diff options
-rw-r--r-- | example/HelloWorld.cpp | 24 | ||||
-rw-r--r-- | gm/blend.cpp | 3 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 15 | ||||
-rw-r--r-- | include/core/SkImage.h | 22 | ||||
-rw-r--r-- | include/core/SkSurface.h | 11 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 24 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 8 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 2 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 41 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 4 | ||||
-rw-r--r-- | src/image/SkImage_Generator.cpp | 5 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 12 | ||||
-rw-r--r-- | src/image/SkSurface.cpp | 18 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 11 | ||||
-rw-r--r-- | tests/ImageTest.cpp | 28 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 48 | ||||
-rw-r--r-- | tools/android/SkAndroidSDKCanvas.cpp | 10 |
17 files changed, 140 insertions, 146 deletions
diff --git a/example/HelloWorld.cpp b/example/HelloWorld.cpp index 1cc18fdc8d..e13cb3b438 100644 --- a/example/HelloWorld.cpp +++ b/example/HelloWorld.cpp @@ -156,18 +156,18 @@ void HelloWorldWindow::draw(SkCanvas* canvas) { if (kRaster_DeviceType == fType) { // need to send the raster bits to the (gpu) window - SkImage* snap = fSurface->newImageSnapshot(); - size_t rowBytes = 0; - SkImageInfo info; - const void* pixels = snap->peekPixels(&info, &rowBytes); - fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), - SkImageInfo2GrPixelConfig(info.colorType(), - info.alphaType(), - info.profileType()), - pixels, - rowBytes, - GrContext::kFlushWrites_PixelOp); - SkSafeUnref(snap); + sk_sp<SkImage> snap = sk_sp<SkImage>(fSurface->newImageSnapshot()); + SkPixmap pmap; + if (snap->peekPixels(&pmap)) { + const SkImageInfo& info = pmap.info(); + fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), + SkImageInfo2GrPixelConfig(info.colorType(), + info.alphaType(), + info.profileType()), + pmap.addr(), + pmap.rowBytes(), + GrContext::kFlushWrites_PixelOp); + } } INHERITED::present(); } diff --git a/gm/blend.cpp b/gm/blend.cpp index 94dc4c7f75..6ecea4c8e9 100644 --- a/gm/blend.cpp +++ b/gm/blend.cpp @@ -36,7 +36,8 @@ DEF_SIMPLE_GM(blend, canvas, 300, 100) { // Print out the colors in each block (if we're looking at 8888 raster). if (canvas->imageInfo().colorType() == kN32_SkColorType) { - if (const SkPMColor* px = (const SkPMColor*)canvas->peekPixels(nullptr, nullptr)) { + SkPixmap pmap; + if (const SkPMColor* px = canvas->peekPixels(&pmap) ? pmap.addr32() : nullptr) { p.setColor(SK_ColorWHITE); for (int i = 0; i < 3; i++) { SkPMColor c = px[i * 100]; diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 1b4571a09c..034e405f3d 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -212,16 +212,19 @@ public: /** * If the canvas has readable pixels in its base layer (and is not recording to a picture * or other non-raster target) and has direct access to its pixels (i.e. they are in - * local RAM) return the const-address of those pixels, and if not null, - * return the ImageInfo and rowBytes. The returned address is only valid + * local RAM) return true, and if not null, return in the pixmap parameter information about + * the pixels. The pixmap's pixel address is only valid * while the canvas object is in scope and unchanged. Any API calls made on - * canvas (or its parent surface if any) will invalidate the - * returned address (and associated information). + * canvas (or its parent surface if any) will invalidate the pixel address + * (and associated information). * - * On failure, returns NULL and the info and rowBytes parameters are - * ignored. + * On failure, returns false and the pixmap parameter will be ignored. */ + bool peekPixels(SkPixmap*); + +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS const void* peekPixels(SkImageInfo* info, size_t* rowBytes); +#endif /** * Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 0474195ae2..c920c54016 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -168,6 +168,16 @@ public: const SkMatrix* localMatrix = NULL) const; /** + * If the image has direct access to its pixels (i.e. they are in local RAM) + * return true, and if not null, return in the pixmap parameter the info about the + * images pixels. + * + * On failure, return false and ignore the pixmap parameter. + */ + bool peekPixels(SkPixmap* pixmap) const; + +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS + /** * If the image has direct access to its pixels (i.e. they are in local * RAM) return the (const) address of those pixels, and if not null, return * the ImageInfo and rowBytes. The returned address is only valid while @@ -175,17 +185,11 @@ public: * * On failure, returns NULL and the info and rowBytes parameters are * ignored. - */ - const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; - - /** - * If the image has direct access to its pixels (i.e. they are in local - * RAM) return the (const) address of those pixels, and if not null, return - * true, and if pixmap is not NULL, set it to point into the image. * - * On failure, return false and ignore the pixmap parameter. + * DEPRECATED -- use the SkPixmap variant instead */ - bool peekPixels(SkPixmap* pixmap) const; + const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; +#endif /** * Some images have to perform preliminary work in preparation for drawing. This can be diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 7a0352994a..b873c24d55 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -257,15 +257,18 @@ public: /** * If the surface has direct access to its pixels (i.e. they are in local - * RAM) return the const-address of those pixels, and if not null, return - * the ImageInfo and rowBytes. The returned address is only valid while + * RAM) return true, and if not null, set the pixmap parameter to point to the information + * about the surface's pixels. The pixel address in the pixmap is only valid while * the surface object is in scope, and no API call is made on the surface * or its canvas. * - * On failure, returns NULL and the info and rowBytes parameters are - * ignored. + * On failure, returns false and the pixmap parameter is ignored. */ + bool peekPixels(SkPixmap*); + +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS const void* peekPixels(SkImageInfo* info, size_t* rowBytes); +#endif /** * Copy the pixels from the surface into the specified buffer (pixels + rowBytes), diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 35710fb317..d60e0e9211 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1335,18 +1335,24 @@ SkImageInfo SkCanvas::imageInfo() const { } } +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) { SkPixmap pmap; - if (!this->onPeekPixels(&pmap)) { - return nullptr; - } - if (info) { - *info = pmap.info(); - } - if (rowBytes) { - *rowBytes = pmap.rowBytes(); + if (this->peekPixels(&pmap)) { + if (info) { + *info = pmap.info(); + } + if (rowBytes) { + *rowBytes = pmap.rowBytes(); + } + return pmap.addr(); } - return pmap.addr(); + return nullptr; +} +#endif + +bool SkCanvas::peekPixels(SkPixmap* pmap) { + return this->onPeekPixels(pmap); } bool SkCanvas::onPeekPixels(SkPixmap* pmap) { diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index f5f88329c4..a55fe65029 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -114,11 +114,9 @@ public: } else #endif { - SkImageInfo info; - size_t rowBytes; - - if (fImage->peekPixels(&info, &rowBytes)) { - return info.height() * rowBytes; + SkPixmap pm; + if (fImage->peekPixels(&pm)) { + return pm.height() * pm.rowBytes(); } } return 0; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index d7af8258c7..81a3502455 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -263,6 +263,8 @@ GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap) { return nullptr; } pmap = &tmpPixmap; + // must rebuild desc, since we've forced the info to be N32 + desc = GrImageInfoToSurfaceDesc(pmap->info()); } } diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 07279501a3..5e7cb07226 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -36,17 +36,29 @@ SkImage::SkImage(int width, int height, uint32_t uniqueID) SkASSERT(height > 0); } -const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const { - SkImageInfo infoStorage; - size_t rowBytesStorage; - if (nullptr == info) { - info = &infoStorage; +bool SkImage::peekPixels(SkPixmap* pm) const { + SkPixmap tmp; + if (!pm) { + pm = &tmp; } - if (nullptr == rowBytes) { - rowBytes = &rowBytesStorage; + return as_IB(this)->onPeekPixels(pm); +} + +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS +const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const { + SkPixmap pm; + if (this->peekPixels(&pm)) { + if (info) { + *info = pm.info(); + } + if (rowBytes) { + *rowBytes = pm.rowBytes(); + } + return pm.addr(); } - return as_IB(this)->onPeekPixels(info, rowBytes); + return nullptr; } +#endif bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint chint) const { @@ -241,19 +253,6 @@ bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz /////////////////////////////////////////////////////////////////////////////////////////////////// -bool SkImage::peekPixels(SkPixmap* pmap) const { - SkImageInfo info; - size_t rowBytes; - const void* pixels = this->peekPixels(&info, &rowBytes); - if (pixels) { - if (pmap) { - pmap->reset(info, pixels, rowBytes); - } - return true; - } - return false; -} - bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const { return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint); } diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index da87e42888..9e2efe98b5 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -26,7 +26,7 @@ public: SkImage_Base(int width, int height, uint32_t uniqueID); virtual ~SkImage_Base(); - virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { return nullptr; } + virtual bool onPeekPixels(SkPixmap*) const { return false; } // Default impl calls onDraw virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, @@ -74,7 +74,7 @@ private: typedef SkImage INHERITED; }; -static inline SkImage_Base* as_IB(SkImage* image) { +static inline SkImage_Base* as_IB(SkImage* image) { return static_cast<SkImage_Base*>(image); } diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp index 688b4ffe3b..95cc426a43 100644 --- a/src/image/SkImage_Generator.cpp +++ b/src/image/SkImage_Generator.cpp @@ -22,7 +22,6 @@ public: {} bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override; - const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; SkImageCacherator* peekCacherator() const override { return fCache; } SkData* onRefEncoded(GrContext*) const override; bool isOpaque() const override { return fCache->info().isOpaque(); } @@ -62,10 +61,6 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels return false; } -const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesPtr) const { - return NULL; -} - SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const { return fCache->refEncoded(ctx); } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index d4debdf807..5bd0e1d8f1 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -67,7 +67,7 @@ public: virtual ~SkImage_Raster(); bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override; - const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; + bool onPeekPixels(SkPixmap*) const override; SkData* onRefEncoded(GrContext*) const override; bool getROPixels(SkBitmap*, CachingHint) const override; GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override; @@ -140,14 +140,8 @@ bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); } -const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesPtr) const { - const SkImageInfo info = fBitmap.info(); - if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { - return nullptr; - } - *infoPtr = info; - *rowBytesPtr = fBitmap.rowBytes(); - return fBitmap.getPixels(); +bool SkImage_Raster::onPeekPixels(SkPixmap* pm) const { + return fBitmap.peekPixels(pm); } SkData* SkImage_Raster::onRefEncoded(GrContext*) const { diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index b018ef9756..9bec562df9 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -182,9 +182,25 @@ void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, return asSB(this)->onDraw(canvas, x, y, paint); } +bool SkSurface::peekPixels(SkPixmap* pmap) { + return this->getCanvas()->peekPixels(pmap); +} + +#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { - return this->getCanvas()->peekPixels(info, rowBytes); + SkPixmap pm; + if (this->peekPixels(&pm)) { + if (info) { + *info = pm.info(); + } + if (rowBytes) { + *rowBytes = pm.rowBytes(); + } + return pm.addr(); + } + return nullptr; } +#endif bool SkSurface::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) { diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 2390c7455f..f34430f475 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -646,17 +646,16 @@ static void test_newraster(skiatest::Reporter* reporter) { SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); REPORTER_ASSERT(reporter, canvas); - SkImageInfo info2; - size_t rowBytes; - const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowBytes); + SkPixmap pmap; + const SkPMColor* addr = canvas->peekPixels(&pmap) ? pmap.addr32() : nullptr; REPORTER_ASSERT(reporter, addr); - REPORTER_ASSERT(reporter, info == info2); - REPORTER_ASSERT(reporter, minRowBytes == rowBytes); + REPORTER_ASSERT(reporter, info == pmap.info()); + REPORTER_ASSERT(reporter, minRowBytes == pmap.rowBytes()); for (int y = 0; y < info.height(); ++y) { for (int x = 0; x < info.width(); ++x) { REPORTER_ASSERT(reporter, 0 == addr[x]); } - addr = (const SkPMColor*)((const char*)addr + rowBytes); + addr = (const SkPMColor*)((const char*)addr + pmap.rowBytes()); } delete canvas; diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index ff1b4be5a6..1a2e109d79 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -32,12 +32,7 @@ static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect REPORTER_ASSERT(reporter, widthA == b->width()); REPORTER_ASSERT(reporter, heightA == b->height()); -#if 0 - // see https://bug.skia.org/3965 - bool AO = a->isOpaque(); - bool BO = b->isOpaque(); - REPORTER_ASSERT(reporter, AO == BO); -#endif + REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque()); SkImageInfo info = SkImageInfo::MakeN32(widthA, heightA, a->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType); @@ -76,7 +71,6 @@ static SkImage* create_image_565() { return surface->newImageSnapshot(); } #endif -#if 0 static SkImage* create_image_ct() { SkPMColor colors[] = { SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), @@ -94,7 +88,6 @@ static SkImage* create_image_ct() { SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkAlphaType); return SkImage::NewRasterCopy(info, data, 5, colorTable); } -#endif static SkData* create_image_data(SkImageInfo* info) { *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); const size_t rowBytes = info->minRowBytes(); @@ -658,19 +651,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, context) { #endif static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectPeekSuccess) { - SkImageInfo info; - size_t rowBytes; - const void* addr = image->peekPixels(&info, &rowBytes); - bool success = SkToBool(addr); + SkPixmap pm; + bool success = image->peekPixels(&pm); REPORTER_ASSERT(reporter, expectPeekSuccess == success); if (success) { + const SkImageInfo& info = pm.info(); REPORTER_ASSERT(reporter, 20 == info.width()); REPORTER_ASSERT(reporter, 20 == info.height()); REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || kOpaque_SkAlphaType == info.alphaType()); - REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); - REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *(const SkPMColor*)addr); + REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes()); + REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *pm.addr32(0, 0)); } } DEF_TEST(ImagePeek, reporter) { @@ -806,13 +798,11 @@ static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { - for (auto create : {&create_image, + for (auto create : {&create_image #if 0 // read pixels failing for non RT formats (565 not a RT on some desktop GLs). - &create_image_565 -#if 0 // peekPixels on color table images is currently broken. - , &create_image_ct -#endif + , &create_image_565 #endif + , &create_image_ct }) { SkAutoTUnref<SkImage> image((*create)()); if (!image) { diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 971e6b56f7..d6c7acd916 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -157,26 +157,23 @@ static void test_canvas_peek(skiatest::Reporter* reporter, bool expectPeekSuccess) { const SkColor color = SK_ColorRED; const SkPMColor pmcolor = SkPreMultiplyColor(color); - SkImageInfo info; - size_t rowBytes; surface->getCanvas()->clear(color); - const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); - bool success = SkToBool(addr); + SkPixmap pmap; + bool success = surface->getCanvas()->peekPixels(&pmap); REPORTER_ASSERT(reporter, expectPeekSuccess == success); - SkImageInfo info2; - size_t rb2; - const void* addr2 = surface->peekPixels(&info2, &rb2); + SkPixmap pmap2; + const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr; if (success) { - REPORTER_ASSERT(reporter, requestInfo == info); - REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes); - REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); + REPORTER_ASSERT(reporter, requestInfo == pmap.info()); + REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes()); + REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32()); - REPORTER_ASSERT(reporter, addr2 == addr); - REPORTER_ASSERT(reporter, info2 == info); - REPORTER_ASSERT(reporter, rb2 == rowBytes); + REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr()); + REPORTER_ASSERT(reporter, pmap.info() == pmap2.info()); + REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes()); } else { REPORTER_ASSERT(reporter, nullptr == addr2); } @@ -387,9 +384,8 @@ DEF_TEST(UniqueImageSnapshot, reporter) { return reinterpret_cast<intptr_t>(pm.addr()); }; auto getSufaceBackingStore = [reporter](SkSurface* surface) { - SkImageInfo info; - size_t rowBytes; - const void* pixels = surface->getCanvas()->peekPixels(&info, &rowBytes); + SkPixmap pmap; + const void* pixels = surface->getCanvas()->peekPixels(&pmap) ? pmap.addr() : nullptr; REPORTER_ASSERT(reporter, pixels); return reinterpret_cast<intptr_t>(pixels); }; @@ -785,27 +781,23 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { #endif static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) { - SkImageInfo info; - size_t rowBytes; - REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes)); + SkPixmap surfacePM; + REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); - SkImageInfo im_info; - size_t im_rowbytes; - REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes)); + SkPixmap pm; + REPORTER_ASSERT(reporter, image->peekPixels(&pm)); - REPORTER_ASSERT(reporter, rowBytes == im_rowbytes); + REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes()); // trigger a copy-on-write surface->getCanvas()->drawPaint(SkPaint()); SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); - SkImageInfo im_info2; - size_t im_rowbytes2; - REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2)); - - REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes); + SkPixmap pm2; + REPORTER_ASSERT(reporter, image2->peekPixels(&pm2)); + REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes()); } DEF_TEST(surface_rowbytes, reporter) { diff --git a/tools/android/SkAndroidSDKCanvas.cpp b/tools/android/SkAndroidSDKCanvas.cpp index 45fcc758f2..1deb97cbc6 100644 --- a/tools/android/SkAndroidSDKCanvas.cpp +++ b/tools/android/SkAndroidSDKCanvas.cpp @@ -292,15 +292,7 @@ SkSurface* SkAndroidSDKCanvas::onNewSurface(const SkImageInfo& info, } bool SkAndroidSDKCanvas::onPeekPixels(SkPixmap* pmap) { - SkASSERT(pmap); - SkImageInfo info; - size_t rowBytes; - const void* addr = fProxyTarget->peekPixels(&info, &rowBytes); - if (addr) { - pmap->reset(info, addr, rowBytes); - return true; - } - return false; + return fProxyTarget->peekPixels(pmap); } bool SkAndroidSDKCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { |