Towards removing getTexture() on SkImage
Review URL: https://codereview.chromium.org/1166993002
This commit is contained in:
parent
519580553a
commit
55812362f1
@ -27,6 +27,7 @@
|
||||
'../include/utils/unix',
|
||||
'../include/utils/win',
|
||||
'../src/core',
|
||||
'../src/image',
|
||||
'../src/opts',
|
||||
'../src/utils',
|
||||
],
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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).
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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<SkImage> 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<SkSurface> surface(createSurface(surfaceType, context));
|
||||
SkAutoTUnref<SkImage> 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"
|
||||
|
Loading…
Reference in New Issue
Block a user