Revert "Allow swapping out of GrBackendTexture used by SkSurface"
This reverts commit 9456f7aba5
.
Reason for revert: Breaking layout tests
Original change's description:
> Allow swapping out of GrBackendTexture used by SkSurface
>
> Change-Id: I67f26efaee87536f3faf51ca164bf003013c7c8a
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215428
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
Change-Id: I0ff5e63d47cd3e536f9fe656503d74965ce6dbfd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215822
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
871b727065
commit
f73b8db50b
@ -505,22 +505,6 @@ public:
|
||||
*/
|
||||
GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess);
|
||||
|
||||
/** If the surface was made via MakeFromBackendTexture then it's backing texture may be
|
||||
substituted with a different texture. The contents of the previous backing texture are
|
||||
copied into the new texture. SkCanvas state is preserved. The original sample count is
|
||||
used. The GrBackendFormat and dimensions of replacement texture must match that of
|
||||
the original.
|
||||
|
||||
@param backendTexture the new backing texture for the surface.
|
||||
@param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
||||
@param textureReleaseProc function called when texture can be released
|
||||
@param releaseContext state passed to textureReleaseProc
|
||||
*/
|
||||
bool replaceBackendTexture(const GrBackendTexture& backendTexture,
|
||||
GrSurfaceOrigin origin,
|
||||
TextureReleaseProc textureReleaseProc = nullptr,
|
||||
ReleaseContext releaseContext = nullptr);
|
||||
|
||||
/** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas.
|
||||
SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface
|
||||
is deleted.
|
||||
|
@ -196,9 +196,6 @@ public:
|
||||
// Returns true if the backend texture has been initialized.
|
||||
bool isValid() const { return fIsValid; }
|
||||
|
||||
// Returns true if both textures are valid and refer to the same API texture.
|
||||
bool isSameTexture(const GrBackendTexture&);
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
// We can remove the pixelConfig getter and setter once we remove the GrPixelConfig from the
|
||||
// GrBackendTexture and plumb the GrPixelconfig manually throughout our code (or remove all use
|
||||
@ -217,7 +214,6 @@ private:
|
||||
friend class SkImage_GpuYUVA;
|
||||
friend class SkPromiseImageHelper;
|
||||
friend class SkSurface;
|
||||
friend class SkSurface_Gpu;
|
||||
friend class GrAHardwareBufferImageGenerator;
|
||||
friend class GrBackendTextureImageGenerator;
|
||||
friend class GrProxyProvider;
|
||||
|
@ -360,40 +360,13 @@ bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GrBackendTexture::isSameTexture(const GrBackendTexture& that) {
|
||||
if (!this->isValid() || !that.isValid()) {
|
||||
return false;
|
||||
}
|
||||
if (fBackend != that.fBackend) {
|
||||
return false;
|
||||
}
|
||||
switch (fBackend) {
|
||||
case GrBackendApi::kOpenGL:
|
||||
return fGLInfo.fID == that.fGLInfo.fID;
|
||||
#ifdef SK_VULKAN
|
||||
case GrBackendApi::kVulkan:
|
||||
return fVkInfo.snapImageInfo().fImage == that.fVkInfo.snapImageInfo().fImage;
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
case GrBackendApi::kMetal:
|
||||
return this->fMtlInfo.fTexture == that.fMtlInfo.fTexture;
|
||||
#endif
|
||||
case GrBackendApi::kMock:
|
||||
return fMockInfo.fID == that.fMockInfo.fID;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GrBackendFormat GrBackendTexture::getBackendFormat() const {
|
||||
if (!this->isValid()) {
|
||||
return GrBackendFormat();
|
||||
}
|
||||
switch (fBackend) {
|
||||
#ifdef SK_GL
|
||||
case GrBackendApi::kOpenGL:
|
||||
return GrBackendFormat::MakeGL(fGLInfo.fFormat, fGLInfo.fTarget);
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
case GrBackendApi::kVulkan: {
|
||||
auto info = fVkInfo.snapImageInfo();
|
||||
|
@ -243,23 +243,6 @@ void SkGpuDevice::clearAll() {
|
||||
GrRenderTargetContext::CanClearFullscreen::kYes);
|
||||
}
|
||||
|
||||
void SkGpuDevice::replaceRenderTargetContext(sk_sp<GrRenderTargetContext> rtc,
|
||||
bool shouldRetainContent) {
|
||||
SkASSERT(rtc->width() == this->width());
|
||||
SkASSERT(rtc->height() == this->height());
|
||||
SkASSERT(rtc->numColorSamples() == fRenderTargetContext->numColorSamples());
|
||||
SkASSERT(rtc->numStencilSamples() == fRenderTargetContext->numStencilSamples());
|
||||
SkASSERT(rtc->asSurfaceProxy()->priv().isExact());
|
||||
if (shouldRetainContent) {
|
||||
if (this->context()->abandoned()) {
|
||||
return;
|
||||
}
|
||||
rtc->copy(fRenderTargetContext->asSurfaceProxy());
|
||||
}
|
||||
|
||||
fRenderTargetContext = std::move(rtc);
|
||||
}
|
||||
|
||||
void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
@ -278,7 +261,16 @@ void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) {
|
||||
if (!newRTC) {
|
||||
return;
|
||||
}
|
||||
this->replaceRenderTargetContext(std::move(newRTC), shouldRetainContent);
|
||||
SkASSERT(newRTC->asSurfaceProxy()->priv().isExact());
|
||||
|
||||
if (shouldRetainContent) {
|
||||
if (this->context()->abandoned()) {
|
||||
return;
|
||||
}
|
||||
newRTC->copy(fRenderTargetContext->asSurfaceProxy());
|
||||
}
|
||||
|
||||
fRenderTargetContext = newRTC;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -65,7 +65,6 @@ public:
|
||||
void clearAll();
|
||||
|
||||
void replaceRenderTargetContext(bool shouldRetainContent);
|
||||
void replaceRenderTargetContext(sk_sp<GrRenderTargetContext>, bool shouldRetainContent);
|
||||
|
||||
GrRenderTargetContext* accessRenderTargetContext() override;
|
||||
|
||||
|
@ -81,13 +81,6 @@ GrBackendRenderTarget SkSurface_Base::onGetBackendRenderTarget(BackendHandleAcce
|
||||
return GrBackendRenderTarget(); // invalid
|
||||
}
|
||||
|
||||
bool SkSurface_Base::onReplaceBackendTexture(const GrBackendTexture&,
|
||||
GrSurfaceOrigin,
|
||||
TextureReleaseProc,
|
||||
ReleaseContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
|
||||
auto image = this->makeImageSnapshot();
|
||||
if (image) {
|
||||
@ -369,14 +362,6 @@ GrBackendRenderTarget SkSurface::getBackendRenderTarget(BackendHandleAccess acce
|
||||
return asSB(this)->onGetBackendRenderTarget(access);
|
||||
}
|
||||
|
||||
bool SkSurface::replaceBackendTexture(const GrBackendTexture& backendTexture,
|
||||
GrSurfaceOrigin origin,
|
||||
TextureReleaseProc textureReleaseProc,
|
||||
ReleaseContext releaseContext) {
|
||||
return asSB(this)->onReplaceBackendTexture(backendTexture, origin, textureReleaseProc,
|
||||
releaseContext);
|
||||
}
|
||||
|
||||
void SkSurface::flush() {
|
||||
this->flush(BackendSurfaceAccess::kNoAccess, GrFlushInfo());
|
||||
}
|
||||
|
@ -21,10 +21,7 @@ public:
|
||||
|
||||
virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);
|
||||
virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess);
|
||||
virtual bool onReplaceBackendTexture(const GrBackendTexture&,
|
||||
GrSurfaceOrigin,
|
||||
TextureReleaseProc,
|
||||
ReleaseContext);
|
||||
|
||||
/**
|
||||
* Allocate a canvas that will draw into this surface. We will cache this
|
||||
* canvas, to return the same object to the caller multiple times. We
|
||||
|
@ -518,60 +518,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrB
|
||||
return sk_make_sp<SkSurface_Gpu>(std::move(device));
|
||||
}
|
||||
|
||||
bool SkSurface_Gpu::onReplaceBackendTexture(const GrBackendTexture& backendTexture,
|
||||
GrSurfaceOrigin origin, TextureReleaseProc releaseProc,
|
||||
ReleaseContext releaseContext) {
|
||||
auto context = this->fDevice->context();
|
||||
if (context->abandoned()) {
|
||||
return false;
|
||||
}
|
||||
if (!backendTexture.isValid()) {
|
||||
return false;
|
||||
}
|
||||
if (backendTexture.width() != this->width() || backendTexture.height() != this->height()) {
|
||||
return false;
|
||||
}
|
||||
auto* oldRTC = fDevice->accessRenderTargetContext();
|
||||
auto oldProxy = sk_ref_sp(oldRTC->asTextureProxy());
|
||||
if (!oldProxy) {
|
||||
return false;
|
||||
}
|
||||
auto* oldTexture = oldProxy->peekTexture();
|
||||
if (!oldTexture) {
|
||||
return false;
|
||||
}
|
||||
if (!oldTexture->resourcePriv().refsWrappedObjects()) {
|
||||
return false;
|
||||
}
|
||||
if (oldTexture->backendFormat() != backendTexture.getBackendFormat()) {
|
||||
return false;
|
||||
}
|
||||
if (oldTexture->getBackendTexture().isSameTexture(backendTexture)) {
|
||||
return false;
|
||||
}
|
||||
SkASSERT(oldTexture->asRenderTarget());
|
||||
int sampleCnt = oldTexture->asRenderTarget()->numStencilSamples();
|
||||
GrBackendTexture texCopy = backendTexture;
|
||||
auto colorSpace = sk_ref_sp(oldRTC->colorSpaceInfo().colorSpace());
|
||||
if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, sampleCnt,
|
||||
this->getCanvas()->imageInfo().colorType(), colorSpace, true)) {
|
||||
return false;
|
||||
}
|
||||
sk_sp<GrRenderTargetContext> rtc(
|
||||
context->priv().makeBackendTextureRenderTargetContext(texCopy,
|
||||
origin,
|
||||
sampleCnt,
|
||||
std::move(colorSpace),
|
||||
&this->props(),
|
||||
releaseProc,
|
||||
releaseContext));
|
||||
if (!rtc) {
|
||||
return false;
|
||||
}
|
||||
fDevice->replaceRenderTargetContext(std::move(rtc), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate_backend_render_target(GrContext* ctx, const GrBackendRenderTarget& rt,
|
||||
GrPixelConfig* config, SkColorType ct, sk_sp<SkColorSpace> cs) {
|
||||
// TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to
|
||||
|
@ -25,8 +25,6 @@ public:
|
||||
|
||||
GrBackendTexture onGetBackendTexture(BackendHandleAccess) override;
|
||||
GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess) override;
|
||||
bool onReplaceBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, TextureReleaseProc,
|
||||
ReleaseContext) override;
|
||||
|
||||
SkCanvas* onNewCanvas() override;
|
||||
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "src/core/SkAutoPixmapStorage.h"
|
||||
#include "src/core/SkDevice.h"
|
||||
#include "src/core/SkUtils.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
@ -966,111 +965,6 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxInfo) {
|
||||
GrContext* context = ctxInfo.grContext();
|
||||
|
||||
for (int sampleCnt : {1, 2}) {
|
||||
GrBackendTexture backendTexture1;
|
||||
auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
|
||||
if (!create_backend_texture(context, &backendTexture1, ii, GrMipMapped::kNo,
|
||||
SK_ColorTRANSPARENT, GrRenderable::kYes)) {
|
||||
continue;
|
||||
}
|
||||
SkScopeExit delete1(
|
||||
[context, &backendTexture1] { delete_backend_texture(context, backendTexture1); });
|
||||
GrBackendTexture backendTexture2;
|
||||
if (!create_backend_texture(context, &backendTexture2, ii, GrMipMapped::kNo,
|
||||
SK_ColorTRANSPARENT, GrRenderable::kYes)) {
|
||||
ERRORF(reporter, "Expected to be able to make second texture");
|
||||
continue;
|
||||
}
|
||||
SkScopeExit delete2(
|
||||
[context, &backendTexture2] { delete_backend_texture(context, backendTexture2); });
|
||||
auto ii2 = ii.makeWH(8, 8);
|
||||
GrBackendTexture backendTexture3;
|
||||
if (!create_backend_texture(context, &backendTexture3, ii2, GrMipMapped::kNo,
|
||||
SK_ColorTRANSPARENT, GrRenderable::kYes)) {
|
||||
ERRORF(reporter, "Couldn't create different sized texture.");
|
||||
continue;
|
||||
}
|
||||
SkScopeExit delete3(
|
||||
[context, &backendTexture3] { delete_backend_texture(context, backendTexture3); });
|
||||
|
||||
auto surf = SkSurface::MakeFromBackendTexture(
|
||||
context, backendTexture1, kTopLeft_GrSurfaceOrigin, sampleCnt,
|
||||
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
|
||||
if (!surf) {
|
||||
continue;
|
||||
}
|
||||
surf->getCanvas()->clear(SK_ColorBLUE);
|
||||
// Change matrix, layer, and clip state before swapping out the backing texture.
|
||||
surf->getCanvas()->translate(5, 5);
|
||||
surf->getCanvas()->saveLayer(nullptr, nullptr);
|
||||
surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1));
|
||||
// switch origin while we're at it.
|
||||
bool replaced = surf->replaceBackendTexture(backendTexture2, kBottomLeft_GrSurfaceOrigin);
|
||||
REPORTER_ASSERT(reporter, replaced);
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorRED);
|
||||
surf->getCanvas()->drawRect(SkRect::MakeWH(5, 5), paint);
|
||||
surf->getCanvas()->restore();
|
||||
|
||||
// Check that the replacement texture got the right color values.
|
||||
SkAutoPixmapStorage pm;
|
||||
pm.alloc(ii);
|
||||
bool bad = !surf->readPixels(pm, 0, 0);
|
||||
REPORTER_ASSERT(reporter, !bad, "Could not read surface.");
|
||||
for (int y = 0; y < ii.height() && !bad; ++y) {
|
||||
for (int x = 0; x < ii.width() && !bad; ++x) {
|
||||
auto expected = (x == 5 && y == 5) ? 0xFF0000FF : 0xFFFF0000;
|
||||
auto found = *pm.addr32(x, y);
|
||||
if (found != expected) {
|
||||
bad = true;
|
||||
ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
|
||||
expected, found, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The original texture should still be all blue.
|
||||
surf = SkSurface::MakeFromBackendTexture(
|
||||
context, backendTexture1, kBottomLeft_GrSurfaceOrigin, sampleCnt,
|
||||
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
|
||||
if (!surf) {
|
||||
ERRORF(reporter, "Could not create second surface.");
|
||||
continue;
|
||||
}
|
||||
bad = !surf->readPixels(pm, 0, 0);
|
||||
REPORTER_ASSERT(reporter, !bad, "Could not read second surface.");
|
||||
for (int y = 0; y < ii.height() && !bad; ++y) {
|
||||
for (int x = 0; x < ii.width() && !bad; ++x) {
|
||||
auto expected = 0xFFFF0000;
|
||||
auto found = *pm.addr32(x, y);
|
||||
if (found != expected) {
|
||||
bad = true;
|
||||
ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
|
||||
expected, found, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Can't replace with the same texture
|
||||
REPORTER_ASSERT(reporter,
|
||||
!surf->replaceBackendTexture(backendTexture1, kTopLeft_GrSurfaceOrigin));
|
||||
// Can't replace with invalid texture
|
||||
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin));
|
||||
// Can't replace with different size texture.
|
||||
REPORTER_ASSERT(reporter,
|
||||
!surf->replaceBackendTexture(backendTexture3, kTopLeft_GrSurfaceOrigin));
|
||||
// Can't replace texture of non-wrapped SkSurface.
|
||||
surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, sampleCnt, nullptr);
|
||||
REPORTER_ASSERT(reporter, surf);
|
||||
if (surf) {
|
||||
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(backendTexture1,
|
||||
kTopLeft_GrSurfaceOrigin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) {
|
||||
SkOverdrawCanvas canvas(surface->getCanvas());
|
||||
canvas.drawPaint(SkPaint());
|
||||
|
Loading…
Reference in New Issue
Block a user