diff --git a/gyp/utils.gyp b/gyp/utils.gyp index d5b2ef7cdd..3171d36a2b 100644 --- a/gyp/utils.gyp +++ b/gyp/utils.gyp @@ -27,6 +27,7 @@ '../include/utils/unix', '../include/utils/win', '../src/core', + '../src/image', '../src/opts', '../src/utils', ], diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 33ae448072..61529cc71d 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -97,13 +97,6 @@ public: uint32_t uniqueID() const { return fUniqueID; } virtual bool isOpaque() const { return false; } - /** - * Return the GrTexture that stores the image pixels. Calling getTexture - * does not affect the reference count of the GrTexture object. - * Will return NULL if the image does not use a texture. - */ - GrTexture* getTexture() const; - virtual SkShader* newShader(SkShader::TileMode, SkShader::TileMode, const SkMatrix* localMatrix = NULL) const; @@ -119,6 +112,21 @@ public: */ const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; + // DEPRECATED + GrTexture* getTexture() const; + + /** + * Returns true if the image is texture backed. + */ + bool isTextureBacked() const; + + /** + * Retrieves the backend API handle of the texture. If flushPendingGrContextReads then the + * GrContext will issue to the backend API any deferred read operations on the texture before + * returning. + */ + GrBackendObject getTextureHandle(bool flushPendingGrContextReads) const; + /** * Copy the pixels from the image into the specified buffer (pixels + rowBytes), * converting them into the requested format (dstInfo). The image pixels are read diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index edb887c943..6db5c1db0d 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1474,7 +1474,7 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, } static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { - GrTexture* tex = image->getTexture(); + GrTexture* tex = as_IB(image)->getTexture(); if (tex) { GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), bm); return true; diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 4efbc33c15..4e563a048e 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -13,6 +13,10 @@ #include "SkReadPixelsRec.h" #include "SkString.h" #include "SkSurface.h" +#if SK_SUPPORT_GPU +#include "GrTexture.h" +#include "GrContext.h" +#endif uint32_t SkImage::NextUniqueID() { static int32_t gUniqueID; @@ -46,10 +50,6 @@ bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY); } -GrTexture* SkImage::getTexture() const { - return as_IB(this)->onGetTexture(); -} - SkShader* SkImage::newShader(SkShader::TileMode tileX, SkShader::TileMode tileY, const SkMatrix* localMatrix) const { @@ -109,6 +109,38 @@ SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset, return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); } +#if SK_SUPPORT_GPU + +GrTexture* SkImage::getTexture() const { + return as_IB(this)->getTexture(); +} + +bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture()); } + +GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const { + GrTexture* texture = as_IB(this)->getTexture(); + if (texture) { + GrContext* context = texture->getContext(); + if (context) { + if (flushPendingGrContextReads) { + context->prepareSurfaceForExternalRead(texture); + } + } + return texture->getTextureHandle(); + } + return 0; +} + +#else + +GrTexture* SkImage::getTexture() const { return NULL; } + +bool SkImage::isTextureBacked() const { return false; } + +GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const { return 0; } + +#endif + /////////////////////////////////////////////////////////////////////////////// static bool raster_canvas_supports(const SkImageInfo& info) { diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 5daf4195e2..3bbff58a18 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -46,7 +46,7 @@ public: virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) const; - virtual GrTexture* onGetTexture() const { return NULL; } + virtual GrTexture* getTexture() const { return NULL; } // return a read-only copy of the pixels. We promise to not modify them, // but only inspect them (or encode them). diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 4c3e1300c5..eaaed8ae82 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -36,7 +36,7 @@ SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro } extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { - if (image->getTexture()) { + if (as_IB(image)->getTexture()) { ((SkImage_Gpu*)image)->applyBudgetDecision(); } } diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 972cd3c2c2..30638873e6 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -37,7 +37,7 @@ public: } bool getROPixels(SkBitmap*) const override; - GrTexture* onGetTexture() const override { return fTexture; } + GrTexture* getTexture() const override { return fTexture; } SkShader* onNewShader(SkShader::TileMode, SkShader::TileMode, const SkMatrix* localMatrix) const override; diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index cf0f0788d2..f44bbfede0 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -69,7 +69,7 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { // image because onCopyOnWrite is only called when there is a cached image. SkImage* image = this->getCachedImage(kNo_Budgeted); SkASSERT(image); - if (rt->asTexture() == image->getTexture()) { + if (rt->asTexture() == as_IB(image)->getTexture()) { this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode); SkTextureImageApplyBudgetedDecision(image); } else if (kDiscard_ContentChangeMode == mode) { diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index b07a94a52f..4c9b270adb 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -13,6 +13,7 @@ #include "SkColorFilter.h" #include "SkDrawFilter.h" #include "SkGPipe.h" +#include "SkImage_Base.h" #include "SkPaint.h" #include "SkPaintPriv.h" #include "SkRRect.h" @@ -43,7 +44,7 @@ static uint64_t image_area(const SkImage* image) { // mutable for now (at least for the purposes of deferred canvas) // static bool should_draw_gpu_image_immediately(const SkImage* image) { - return image->getTexture() != NULL; + return as_IB(image)->getTexture() != NULL; } static bool should_draw_immediately(const SkBitmap* bitmap, const SkImage* image, diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 4803b68221..65c0c3b53d 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -9,6 +9,7 @@ #include "SkData.h" #include "SkDevice.h" #include "SkImageEncoder.h" +#include "SkImage_Base.h" #include "SkRRect.h" #include "SkSurface.h" #include "SkUtils.h" @@ -528,13 +529,13 @@ static void Test_crbug263329(skiatest::Reporter* reporter, // be recycling a texture that is held by an existing image. canvas2->clear(5); SkAutoTUnref image4(surface2->newImageSnapshot()); - REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getTexture()); // The following assertion checks crbug.com/263329 - REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture()); - REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture()); - REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture()); - REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture()); - REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getTexture()); + REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getTexture()); } static void TestGetTexture(skiatest::Reporter* reporter, @@ -542,7 +543,7 @@ static void TestGetTexture(skiatest::Reporter* reporter, GrContext* context) { SkAutoTUnref surface(createSurface(surfaceType, context)); SkAutoTUnref image(surface->newImageSnapshot()); - GrTexture* texture = image->getTexture(); + GrTexture* texture = as_IB(image)->getTexture(); if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceType) { REPORTER_ASSERT(reporter, texture); REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); @@ -550,7 +551,7 @@ static void TestGetTexture(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, NULL == texture); } surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); - REPORTER_ASSERT(reporter, image->getTexture() == texture); + REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture); } #include "GrGpuResourcePriv.h"