Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv (take 3)
This is in service of: https://skia-review.googlesource.com/c/11125/ (Add parallel proxyID to StencilOps & RenderTargetOpList) where I want a better choke point for texture creation to improve discard handling.
This is a re-reland of: https://skia-review.googlesource.com/c/11200/ (Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv)
Change-Id: Icfb9dd223418dd460405efd2bfd9d1c356beed1a
Reviewed-on: https://skia-review.googlesource.com/11412
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index a7a2b45..fcf3fe8 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -184,7 +184,7 @@
smallMSAART0 && smallMSAART0->asRenderTarget() &&
smallMSAART0->asRenderTarget()->numColorSamples() < 8) {
smallMSAADesc.fSampleCnt = 8;
- smallMSAART1.reset(resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo));
+ smallMSAART1 = resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo);
sk_sp<GrTexture> smallMSAART1(
resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo));
if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
@@ -1514,13 +1514,13 @@
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = sampleCnt;
- return sk_sp<GrTexture>(provider->createTexture(desc, SkBudgeted::kYes));
+ return provider->createTexture(desc, SkBudgeted::kYes);
}
-static sk_sp<GrTexture> make_mipmap_texture(GrResourceProvider* provider,
- GrSurfaceFlags flags,
- int width, int height,
- int sampleCnt) {
+static sk_sp<GrTextureProxy> make_mipmap_proxy(GrResourceProvider* provider,
+ GrSurfaceFlags flags,
+ int width, int height,
+ int sampleCnt) {
SkBitmap bm;
bm.allocN32Pixels(width, height, true);
@@ -1552,8 +1552,7 @@
desc.fSampleCnt = sampleCnt;
desc.fIsMipMapped = true;
- return sk_sp<GrTexture>(provider->createMipMappedTexture(desc, SkBudgeted::kYes,
- texels.get(), mipLevelCount));
+ return provider->createMipMappedTexture(desc, SkBudgeted::kYes, texels.get(), mipLevelCount);
}
// Exercise GrSurface::gpuMemorySize for different combos of MSAA, RT-only,
@@ -1564,42 +1563,49 @@
static const int kSize = 64;
- sk_sp<GrTexture> tex;
-
// Normal versions
- tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
- size_t size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
+ {
+ sk_sp<GrTexture> tex;
- if (context->caps()->maxSampleCount() >= 4) {
- tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+ tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
+ size_t size = tex->gpuMemorySize();
+ REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
+
+ if (context->caps()->maxSampleCount() >= 4) {
+ tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+ size = tex->gpuMemorySize();
+ REPORTER_ASSERT(reporter, kSize*kSize*4 == size || // msaa4 failed
+ kSize*kSize*4*4 == size || // auto-resolving
+ kSize*kSize*4*5 == size); // explicit resolve buffer
+ }
+
+ tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter, kSize*kSize*4 == size || // msaa4 failed
- kSize*kSize*4*4 == size || // auto-resolving
- kSize*kSize*4*5 == size); // explicit resolve buffer
+ REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
}
- tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
- size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
// Mipmapped versions
- tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
- size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+ {
+ sk_sp<GrTextureProxy> proxy;
- if (context->caps()->maxSampleCount() >= 4) {
- tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
- size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter,
+ proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
+ size_t size = proxy->gpuMemorySize();
+ REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+
+ if (context->caps()->maxSampleCount() >= 4) {
+ proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+ size = proxy->gpuMemorySize();
+ REPORTER_ASSERT(reporter,
kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed
kSize*kSize*4*4+(kSize*kSize*4)/3 == size || // auto-resolving
kSize*kSize*4*5+(kSize*kSize*4)/3 == size); // explicit resolve buffer
- }
+ }
- tex = make_mipmap_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
- size = tex->gpuMemorySize();
- REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+ proxy = make_mipmap_proxy(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
+ size = proxy->gpuMemorySize();
+ REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+ }
}
#endif