Remove more GrContext imports & usage

Sanity is coming soon!

Change-Id: I109ebeef9efd7dbf4d76a13e1c05df36d59affbc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303661
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Adlai Holler 2020-07-20 10:27:41 -04:00 committed by Skia Commit-Bot
parent c59916a5cc
commit dd1395526d
41 changed files with 73 additions and 91 deletions

View File

@ -20,7 +20,6 @@
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/GrSharedEnums.h"
#include "include/private/GrTypesPriv.h"

View File

@ -17,7 +17,6 @@
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrSharedEnums.h"
#include "include/private/GrTypesPriv.h"
#include "src/gpu/GrCaps.h"

View File

@ -11,7 +11,6 @@
#include "include/core/SkColor.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"

View File

@ -16,7 +16,6 @@
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/GrTypesPriv.h"

View File

@ -26,7 +26,6 @@
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrConfig.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrTypesPriv.h"
#include "include/private/SkColorData.h"
#include "src/core/SkMatrixProvider.h"

View File

@ -18,7 +18,6 @@
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrSharedEnums.h"
#include "include/private/GrTypesPriv.h"
#include "src/core/SkTLList.h"

View File

@ -16,7 +16,6 @@
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/utils/SkRandom.h"

View File

@ -28,7 +28,6 @@
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"

View File

@ -17,7 +17,6 @@
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrContextPriv.h"

View File

@ -14,7 +14,6 @@
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/GrTypesPriv.h"
#include "src/gpu/GrBuffer.h"

View File

@ -25,7 +25,7 @@
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/GrTypesPriv.h"
@ -289,11 +289,10 @@ protected:
return;
}
// CONTEXT TODO: remove this use of the 'backdoor' to create an image
GrContext* tmp = canvas->recordingContext()->priv().backdoor();
auto dContext = GrAsDirectContext(canvas->recordingContext());
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
sk_sp<SkImage> texImage(new SkImage_Gpu(sk_ref_sp(tmp),
sk_sp<SkImage> texImage(new SkImage_Gpu(sk_ref_sp(dContext),
image->uniqueID(), std::move(view),
image->colorType(), image->alphaType(),
image->refColorSpace()));

View File

@ -8,7 +8,6 @@
#include "gm/gm.h"
#include "include/core/SkPath.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrContextPriv.h"

View File

@ -15,7 +15,6 @@
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/GrTypesPriv.h"

View File

@ -11,7 +11,6 @@
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrFragmentProcessor.h"

View File

@ -21,7 +21,6 @@
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/core/SkYUVAIndex.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrTypesPriv.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h"

View File

@ -50,7 +50,6 @@
#include <new>
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/SkGr.h"
#endif

View File

@ -22,7 +22,6 @@
#include "src/core/SkValidationUtils.h"
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrColorSpaceXform.h"
#include "src/gpu/GrContextPriv.h"

View File

@ -73,7 +73,7 @@ extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
*
* @return true if the image was successfully uploaded and locked into a texture
*/
bool SkImage_pinAsTexture(const SkImage*, GrContext*);
bool SkImage_pinAsTexture(const SkImage*, GrRecordingContext*);
/**
* The balancing call to a successful invokation of SkImage_pinAsTexture. When a balanced number of
@ -83,7 +83,7 @@ bool SkImage_pinAsTexture(const SkImage*, GrContext*);
*
* The context passed to unpin must match the one passed to pin.
*/
void SkImage_unpinAsTexture(const SkImage*, GrContext*);
void SkImage_unpinAsTexture(const SkImage*, GrRecordingContext*);
/**
* Returns the bounds of the image relative to its encoded buffer. For all non-lazy images,

View File

@ -20,10 +20,6 @@
#include <new>
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#endif
template <typename T> int SafeCount(const T* obj) {
return obj ? obj->count() : 0;
}

View File

@ -15,9 +15,8 @@
#include "src/image/SkImage_Base.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"

View File

@ -18,7 +18,6 @@
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrColorInfo.h"
#include "src/gpu/effects/generated/GrHighContrastFilterEffect.h"
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"

View File

@ -14,7 +14,6 @@
#include "src/core/SkVM.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/effects/generated/GrLumaColorFilterEffect.h"
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"

View File

@ -344,7 +344,6 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect);
#if GR_TEST_UTILS
#include "include/gpu/GrContext.h"
std::unique_ptr<GrFragmentProcessor> ColorTableEffect::TestCreate(GrProcessorTestData* d) {
int flags = 0;

View File

@ -15,7 +15,6 @@
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrColorSpaceXform.h"

View File

@ -24,7 +24,6 @@
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/SkGr.h"
#endif

View File

@ -17,7 +17,6 @@
////////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrColorSpaceXform.h"
#include "src/gpu/effects/GrTextureEffect.h"
#include "src/gpu/effects/generated/GrMagnifierEffect.h"

View File

@ -19,7 +19,6 @@
#include "src/gpu/SkGr.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/effects/GrMatrixConvolutionEffect.h"

View File

@ -16,7 +16,6 @@
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrRecordingContextPriv.h"

View File

@ -19,7 +19,7 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/gl/GrGLTypes.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/gl/GrGLDefines.h"
@ -62,7 +62,13 @@ SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) {
GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBuffer,
uint32_t bufferFormat, bool requireKnownFormat) {
GrBackendApi backend = context->backend();
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(context);
if (!dContext) {
SkDEBUGFAIL("Requires direct context.");
return GrBackendFormat();
}
GrBackendApi backend = dContext->backend();
if (backend == GrBackendApi::kOpenGL) {
switch (bufferFormat) {
@ -104,7 +110,7 @@ GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBu
if (requireKnownFormat) {
return GrBackendFormat();
} else {
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
SkASSERT(gpu);
VkDevice device = gpu->device();
@ -169,7 +175,7 @@ public:
// eglDestroyImageKHR will remove a ref from the AHardwareBuffer
eglDestroyImageKHR(fDisplay, fImage);
}
void rebind(GrContext* grContext);
void rebind(GrDirectContext*);
private:
GrGLuint fTexID;
@ -178,7 +184,7 @@ private:
GrGLuint fTexTarget;
};
void GLTextureHelper::rebind(GrContext* grContext) {
void GLTextureHelper::rebind(GrDirectContext* dContext) {
glBindTexture(fTexTarget, fTexID);
GLenum status = GL_NO_ERROR;
if ((status = glGetError()) != GL_NO_ERROR) {
@ -191,7 +197,7 @@ void GLTextureHelper::rebind(GrContext* grContext) {
SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)", (int) status);
return;
}
grContext->resetContext(kTextureBinding_GrGLBackendState);
dContext->resetContext(kTextureBinding_GrGLBackendState);
}
void delete_gl_texture(void* context) {
@ -200,12 +206,18 @@ void delete_gl_texture(void* context) {
}
void update_gl_texture(void* context, GrContext* grContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(grContext);
if (!dContext) {
SkDEBUGFAIL("Direct context required.");
return;
}
GLTextureHelper* cleanupHelper = static_cast<GLTextureHelper*>(context);
cleanupHelper->rebind(grContext);
cleanupHelper->rebind(dContext);
}
static GrBackendTexture make_gl_backend_texture(
GrContext* context, AHardwareBuffer* hardwareBuffer,
GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
int width, int height,
DeleteImageProc* deleteProc,
UpdateImageProc* updateProc,
@ -253,7 +265,7 @@ static GrBackendTexture make_gl_backend_texture(
eglDestroyImageKHR(display, image);
return GrBackendTexture();
}
context->resetContext(kTextureBinding_GrGLBackendState);
dContext->resetContext(kTextureBinding_GrGLBackendState);
GrGLTextureInfo textureInfo;
textureInfo.fID = texID;
@ -295,11 +307,13 @@ void delete_vk_image(void* context) {
}
void update_vk_image(void* context, GrContext* grContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
SkASSERT(GrAsDirectContext(grContext));
// no op
}
static GrBackendTexture make_vk_backend_texture(
GrContext* context, AHardwareBuffer* hardwareBuffer,
GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
int width, int height,
DeleteImageProc* deleteProc,
UpdateImageProc* updateProc,
@ -307,8 +321,8 @@ static GrBackendTexture make_vk_backend_texture(
bool isProtectedContent,
const GrBackendFormat& backendFormat,
bool isRenderable) {
SkASSERT(context->backend() == GrBackendApi::kVulkan);
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
SkASSERT(dContext->backend() == GrBackendApi::kVulkan);
GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
VkPhysicalDevice physicalDevice = gpu->physicalDevice();
VkDevice device = gpu->device();
@ -510,8 +524,8 @@ static bool can_import_protected_content_eglimpl() {
return equal || atStart || atEnd || inMiddle;
}
static bool can_import_protected_content(GrContext* context) {
if (GrBackendApi::kOpenGL == context->backend()) {
static bool can_import_protected_content(GrDirectContext* dContext) {
if (GrBackendApi::kOpenGL == dContext->backend()) {
// Only compute whether the extension is present once the first time this
// function is called.
static bool hasIt = can_import_protected_content_eglimpl();
@ -528,21 +542,24 @@ GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwar
bool isProtectedContent,
const GrBackendFormat& backendFormat,
bool isRenderable) {
if (context->abandoned()) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(context);
SkASSERT(dContext);
if (!dContext || dContext->abandoned()) {
return GrBackendTexture();
}
bool createProtectedImage = isProtectedContent && can_import_protected_content(context);
bool createProtectedImage = isProtectedContent && can_import_protected_content(dContext);
if (GrBackendApi::kOpenGL == context->backend()) {
return make_gl_backend_texture(context, hardwareBuffer, width, height, deleteProc,
if (GrBackendApi::kOpenGL == dContext->backend()) {
return make_gl_backend_texture(dContext, hardwareBuffer, width, height, deleteProc,
updateProc, imageCtx, createProtectedImage, backendFormat,
isRenderable);
} else {
SkASSERT(GrBackendApi::kVulkan == context->backend());
SkASSERT(GrBackendApi::kVulkan == dContext->backend());
#ifdef SK_VULKAN
// Currently we don't support protected images on vulkan
SkASSERT(!createProtectedImage);
return make_vk_backend_texture(context, hardwareBuffer, width, height, deleteProc,
return make_vk_backend_texture(dContext, hardwareBuffer, width, height, deleteProc,
updateProc, imageCtx, createProtectedImage, backendFormat,
isRenderable);
#else

View File

@ -7,7 +7,6 @@
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "src/core/SkArenaAlloc.h"
#include "src/gpu/GrAuditTrail.h"

View File

@ -617,16 +617,16 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage_pinAsTexture(const SkImage* image, GrContext* ctx) {
bool SkImage_pinAsTexture(const SkImage* image, GrRecordingContext* rContext) {
SkASSERT(image);
SkASSERT(ctx);
return as_IB(image)->onPinAsTexture(ctx);
SkASSERT(rContext);
return as_IB(image)->onPinAsTexture(rContext);
}
void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) {
void SkImage_unpinAsTexture(const SkImage* image, GrRecordingContext* rContext) {
SkASSERT(image);
SkASSERT(ctx);
as_IB(image)->onUnpinAsTexture(ctx);
SkASSERT(rContext);
as_IB(image)->onUnpinAsTexture(rContext);
}
SkIRect SkImage_getSubset(const SkImage* image) {

View File

@ -127,8 +127,8 @@ public:
virtual bool onIsValid(GrRecordingContext*) const = 0;
virtual bool onPinAsTexture(GrContext*) const { return false; }
virtual void onUnpinAsTexture(GrContext*) const {}
virtual bool onPinAsTexture(GrRecordingContext*) const { return false; }
virtual void onUnpinAsTexture(GrRecordingContext*) const {}
virtual sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
GrDirectContext*) const = 0;

View File

@ -9,7 +9,6 @@
#include "include/core/SkPromiseImageTexture.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkBitmapCache.h"

View File

@ -20,7 +20,6 @@
#include "src/shaders/SkBitmapProcShader.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrTextureAdjuster.h"
#include "src/gpu/SkGr.h"
#endif
@ -119,8 +118,8 @@ public:
#if SK_SUPPORT_GPU
GrSurfaceProxyView refPinnedView(GrRecordingContext* context,
uint32_t* uniqueID) const override;
bool onPinAsTexture(GrContext*) const override;
void onUnpinAsTexture(GrContext*) const override;
bool onPinAsTexture(GrRecordingContext*) const override;
void onUnpinAsTexture(GrRecordingContext*) const override;
#endif
SkMipmap* onPeekMips() const override { return fBitmap.fMips.get(); }
@ -214,14 +213,14 @@ GrSurfaceProxyView SkImage_Raster::refPinnedView(GrRecordingContext*, uint32_t*
return {};
}
bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const {
bool SkImage_Raster::onPinAsTexture(GrRecordingContext* rContext) const {
if (fPinnedView) {
SkASSERT(fPinnedCount > 0);
SkASSERT(fPinnedUniqueID != 0);
} else {
SkASSERT(fPinnedCount == 0);
SkASSERT(fPinnedUniqueID == 0);
fPinnedView = GrRefCachedBitmapView(ctx, fBitmap, GrMipMapped::kNo);
fPinnedView = GrRefCachedBitmapView(rContext, fBitmap, GrMipMapped::kNo);
if (!fPinnedView) {
return false;
}
@ -233,7 +232,7 @@ bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const {
return true;
}
void SkImage_Raster::onUnpinAsTexture(GrContext* ctx) const {
void SkImage_Raster::onUnpinAsTexture(GrRecordingContext*) const {
// Note: we always decrement, even if fPinnedTexture is null
SkASSERT(fPinnedCount > 0);
SkASSERT(fPinnedUniqueID != 0);

View File

@ -8,7 +8,6 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/mtl/GrMtlTypes.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h"

View File

@ -89,7 +89,6 @@ skvm::Color SkColorFilterShader::onProgram(skvm::Builder* p,
#if SK_SUPPORT_GPU
/////////////////////////////////////////////////////////////////////
#include "include/gpu/GrContext.h"
std::unique_ptr<GrFragmentProcessor> SkColorFilterShader::asFragmentProcessor(
const GrFPArgs& args) const {

View File

@ -22,6 +22,7 @@
#include <atomic>
#if SK_SUPPORT_GPU
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrColorInfo.h"
@ -342,8 +343,6 @@ void SkPictureShader::PictureShaderContext::shadeSpan(int x, int y, SkPMColor ds
}
#if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h"
#include "src/gpu/GrContextPriv.h"
std::unique_ptr<GrFragmentProcessor> SkPictureShader::asFragmentProcessor(
const GrFPArgs& args) const {

View File

@ -28,6 +28,7 @@
#include "tests/Test.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/text/GrAtlasManager.h"
#include "src/gpu/text/GrTextBlobCache.h"

View File

@ -16,7 +16,6 @@
#include "tools/debugger/DebugLayerManager.h"
#include "tools/debugger/DrawCommand.h"
#include "include/gpu/GrContext.h"
#include "src/gpu/GrAuditTrail.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"

View File

@ -10,27 +10,27 @@
#include "include/core/SkImage.h"
#include "include/core/SkPixmap.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "src/core/SkAutoPixmapStorage.h"
namespace {
class ManagedBackendTexture : public SkNVRefCnt<ManagedBackendTexture> {
public:
~ManagedBackendTexture() {
if (fContext && fTexture.isValid()) {
fContext->submit(true);
fContext->deleteBackendTexture(fTexture);
if (fDContext && fTexture.isValid()) {
fDContext->submit(true);
fDContext->deleteBackendTexture(fTexture);
}
}
static void Release(void* context) { static_cast<ManagedBackendTexture*>(context)->unref(); }
template <typename... Args>
static sk_sp<ManagedBackendTexture> Make(GrContext* context, Args&&... args) {
static sk_sp<ManagedBackendTexture> Make(GrDirectContext* dContext, Args&&... args) {
sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture);
mbet->fContext = context;
mbet->fTexture = context->createBackendTexture(std::forward<Args>(args)..., Release,
mbet->refAndPassAsContext());
mbet->fDContext = dContext;
mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)..., Release,
mbet->refAndPassAsContext());
return mbet;
}
@ -43,13 +43,13 @@ public:
private:
ManagedBackendTexture() = default;
GrContext* fContext = nullptr;
GrDirectContext* fDContext = nullptr;
GrBackendTexture fTexture;
};
} // namespace
namespace sk_gpu_test {
sk_sp<SkImage> MakeBackendTextureImage(GrContext* context,
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
const SkPixmap& pixmap,
GrRenderable renderable,
GrSurfaceOrigin origin) {
@ -64,8 +64,8 @@ sk_sp<SkImage> MakeBackendTextureImage(GrContext* context,
}
src = &temp;
}
auto mbet = ManagedBackendTexture::Make(context, src, 1, renderable, GrProtected::kNo);
return SkImage::MakeFromTexture(context,
auto mbet = ManagedBackendTexture::Make(dContext, src, 1, renderable, GrProtected::kNo);
return SkImage::MakeFromTexture(dContext,
mbet->texture(),
origin,
src->colorType(),

View File

@ -8,7 +8,7 @@
#include "include/core/SkRefCnt.h"
#include "include/gpu/GrTypes.h"
class GrContext;
class GrDirectContext;
class SkImage;
class SkPixmap;
@ -20,5 +20,6 @@ namespace sk_gpu_test {
* For testing purposes the texture can be made renderable to exercise different code paths for
* renderable textures/formats.
*/
sk_sp<SkImage> MakeBackendTextureImage(GrContext*, const SkPixmap&, GrRenderable, GrSurfaceOrigin);
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext*, const SkPixmap&,
GrRenderable, GrSurfaceOrigin);
} // namespace sk_gpu_test