Remove SkImage_GpuBase::getTexture().

Part of effort to consolidate access to GPU SkImage texture proxies.

Bug: skia:11208
Change-Id: Icfcf6fea6be6f05220a5ddd1482f88dafe1cbd9d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359836
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Brian Salomon 2021-01-27 12:28:18 -05:00 committed by Skia Commit-Bot
parent 64400d95d6
commit 9e8e2aa9c3
5 changed files with 20 additions and 60 deletions

View File

@ -574,28 +574,19 @@ bool SkImage::MakeBackendTextureFromSkImage(GrDirectContext* direct,
return false;
}
// Ensure we have a texture backed image.
if (!image->isTextureBacked()) {
image = image->makeTextureImage(direct);
if (!image) {
return false;
}
}
SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image));
GrTexture* texture = gpuImage->getTexture();
if (!texture) {
// In context-loss cases, we may not have a texture.
return false;
}
GrSurfaceProxyView view = as_IB(image)->refView(direct, GrMipmapped::kNo);
// If the image's context doesn't match the provided context, fail.
if (texture->getContext() != direct) {
if (!view) {
return false;
}
// Flush any pending IO on the texture.
direct->priv().flushSurface(as_IB(image)->peekProxy());
direct->priv().flushSurface(view.proxy());
GrTexture* texture = view.asTextureProxy()->peekTexture();
if (!texture) {
return false;
}
// We must make a copy of the image if the image is not unique, if the GrTexture owned by the
// image is not unique, or if the texture wraps an external object.
if (!image->unique() || !texture->unique() ||
@ -605,14 +596,7 @@ bool SkImage::MakeBackendTextureFromSkImage(GrDirectContext* direct,
if (!image) {
return false;
}
texture = gpuImage->getTexture();
if (!texture) {
return false;
}
// Flush to ensure that the copy is completed before we return the texture.
direct->priv().flushSurface(as_IB(image)->peekProxy());
return MakeBackendTextureFromSkImage(direct, std::move(image), backendTexture, releaseProc);
}
SkASSERT(!texture->resourcePriv().refsWrappedObjects());
@ -620,8 +604,10 @@ bool SkImage::MakeBackendTextureFromSkImage(GrDirectContext* direct,
SkASSERT(image->unique());
// Take a reference to the GrTexture and release the image.
sk_sp<GrTexture> textureRef(SkSafeRef(texture));
sk_sp<GrTexture> textureRef = sk_ref_sp(texture);
view.reset();
image = nullptr;
SkASSERT(textureRef->unique());
// Steal the backend texture from the GrTexture, releasing the GrTexture in the process.
return GrTexture::StealBackendTexture(std::move(textureRef), backendTexture, releaseProc);

View File

@ -189,7 +189,6 @@ bool SkImage_GpuBase::onReadPixels(GrDirectContext* dContext,
GrSurfaceProxyView SkImage_GpuBase::refView(GrRecordingContext* context,
GrMipmapped mipMapped) const {
if (!context || !fContext->priv().matches(context)) {
SkASSERT(0);
return {};
}
@ -232,28 +231,6 @@ GrBackendTexture SkImage_GpuBase::onGetBackendTexture(bool flushPendingGrContext
return GrBackendTexture(); // invalid
}
GrTexture* SkImage_GpuBase::getTexture() const {
GrTextureProxy* proxy = this->peekProxy();
if (proxy && proxy->isInstantiated()) {
return proxy->peekTexture();
}
auto direct = fContext->asDirectContext();
if (!direct) {
// This image was created with a DDL context and cannot be instantiated.
return nullptr;
}
const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view && *view && !view->proxy()->isInstantiated());
if (!view->proxy()->instantiate(direct->priv().resourceProvider())) {
return nullptr;
}
return view->proxy()->peekTexture();
}
bool SkImage_GpuBase::onIsValid(GrRecordingContext* context) const {
// The base class has already checked that 'context' isn't abandoned (if it's not nullptr)
if (fContext->priv().abandoned()) {

View File

@ -46,8 +46,6 @@ public:
GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const final;
GrTexture* getTexture() const;
bool onIsValid(GrRecordingContext*) const final;
#if GR_TEST_UTILS

View File

@ -23,15 +23,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextureMipMapInvalidationTest, reporter, ct
auto isMipped = [reporter](SkSurface* surf) {
SkImage_GpuBase* image = static_cast<SkImage_GpuBase*>(as_IB(surf->makeImageSnapshot()));
const GrTexture* texture = image->getTexture();
bool textureIsMipmapped = texture->mipmapped() == GrMipmapped::kYes;
REPORTER_ASSERT(reporter, textureIsMipmapped == image->hasMipmaps());
bool proxyIsMipmapped = image->peekProxy()->mipmapped() == GrMipmapped::kYes;
REPORTER_ASSERT(reporter, proxyIsMipmapped == image->hasMipmaps());
return image->hasMipmaps();
};
auto mipsAreDirty = [](SkSurface* surf) {
SkImage_GpuBase* image = static_cast<SkImage_GpuBase*>(as_IB(surf->makeImageSnapshot()));
return image->getTexture()->mipmapsAreDirty();
return image->peekProxy()->peekTexture()->mipmapsAreDirty();
};
auto info = SkImageInfo::MakeN32Premul(256, 256);

View File

@ -486,13 +486,13 @@ static void test_crbug263329(skiatest::Reporter* reporter,
SkImage_GpuBase* gpuImage3 = static_cast<SkImage_GpuBase*>(as_IB(image3));
SkImage_GpuBase* gpuImage4 = static_cast<SkImage_GpuBase*>(as_IB(image4));
REPORTER_ASSERT(reporter, gpuImage4->getTexture() != gpuImage3->getTexture());
REPORTER_ASSERT(reporter, gpuImage4->peekProxy() != gpuImage3->peekProxy());
// The following assertion checks crbug.com/263329
REPORTER_ASSERT(reporter, gpuImage4->getTexture() != gpuImage2->getTexture());
REPORTER_ASSERT(reporter, gpuImage4->getTexture() != gpuImage1->getTexture());
REPORTER_ASSERT(reporter, gpuImage3->getTexture() != gpuImage2->getTexture());
REPORTER_ASSERT(reporter, gpuImage3->getTexture() != gpuImage1->getTexture());
REPORTER_ASSERT(reporter, gpuImage2->getTexture() != gpuImage1->getTexture());
REPORTER_ASSERT(reporter, gpuImage4->peekProxy() != gpuImage2->peekProxy());
REPORTER_ASSERT(reporter, gpuImage4->peekProxy() != gpuImage1->peekProxy());
REPORTER_ASSERT(reporter, gpuImage3->peekProxy() != gpuImage2->peekProxy());
REPORTER_ASSERT(reporter, gpuImage3->peekProxy() != gpuImage1->peekProxy());
REPORTER_ASSERT(reporter, gpuImage2->peekProxy() != gpuImage1->peekProxy());
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) {
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {