Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 34aa059

Browse files
Ethan NicholasSkia Commit-Bot
authored andcommitted
Revert "Remove setting/use of GrPixelConfig in GrBackendTex/RT ctors."
This reverts commit ff2181e. Reason for revert: suspect it's behind Chrome roll failure Original change's description: > Remove setting/use of GrPixelConfig in GrBackendTex/RT ctors. > > Bug: skia: > Change-Id: I1466668e3502cd1e6e1f6aed4105e0f626d293dd > Reviewed-on: https://skia-review.googlesource.com/138987 > Commit-Queue: Greg Daniel <[email protected]> > Reviewed-by: Robert Phillips <[email protected]> [email protected],[email protected],[email protected] Change-Id: I4cba44858aafffbadc45e18349b93c741d7cfc66 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/139220 Reviewed-by: Ethan Nicholas <[email protected]> Commit-Queue: Ethan Nicholas <[email protected]>
1 parent b630734 commit 34aa059

16 files changed

+176
-63
lines changed

include/gpu/GrBackendSurface.h

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ class SK_API GrBackendTexture {
128128
// Creates an invalid backend texture.
129129
GrBackendTexture() : fIsValid(false) {}
130130

131+
#if GR_TEST_UTILS
132+
// GrGLTextureInfo::fFormat is ignored
133+
// Deprecated: Should use version that does not take a GrPixelConfig instead
134+
GrBackendTexture(int width,
135+
int height,
136+
GrPixelConfig config,
137+
const GrGLTextureInfo& glInfo);
138+
139+
// GrGLTextureInfo::fFormat is ignored
140+
// Deprecated: Should use version that does not take a GrPixelConfig instead
141+
GrBackendTexture(int width,
142+
int height,
143+
GrPixelConfig config,
144+
GrMipMapped,
145+
const GrGLTextureInfo& glInfo);
146+
#endif
147+
131148
// The GrGLTextureInfo must have a valid fFormat.
132149
GrBackendTexture(int width,
133150
int height,
@@ -192,12 +209,7 @@ class SK_API GrBackendTexture {
192209
bool isValid() const { return fIsValid; }
193210

194211
#if GR_TEST_UTILS
195-
// We can remove the pixelConfig getter and setter once we remove the GrPixelConfig from the
196-
// GrBackendTexture and plumb the GrPixelconfig manually throughout our code (or remove all use
197-
// of GrPixelConfig in general).
198-
GrPixelConfig pixelConfig() const { return fConfig; }
199-
void setPixelConfig(GrPixelConfig config) { fConfig = config; }
200-
212+
GrPixelConfig testingOnly_getPixelConfig() const;
201213
static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&);
202214
#endif
203215

@@ -206,7 +218,6 @@ class SK_API GrBackendTexture {
206218
friend class SkImage;
207219
friend class SkImage_Gpu;
208220
friend class SkSurface;
209-
friend class GrAHardwareBufferImageGenerator;
210221
friend class GrBackendTextureImageGenerator;
211222
friend class GrProxyProvider;
212223
friend class GrGpu;
@@ -255,6 +266,17 @@ class SK_API GrBackendRenderTarget {
255266
// Creates an invalid backend texture.
256267
GrBackendRenderTarget() : fIsValid(false) {}
257268

269+
#if GR_TEST_UTILS
270+
// GrGLTextureInfo::fFormat is ignored
271+
// Deprecated: Should use version that does not take a GrPixelConfig instead
272+
GrBackendRenderTarget(int width,
273+
int height,
274+
int sampleCnt,
275+
int stencilBits,
276+
GrPixelConfig config,
277+
const GrGLFramebufferInfo& glInfo);
278+
#endif
279+
258280
// The GrGLTextureInfo must have a valid fFormat.
259281
GrBackendRenderTarget(int width,
260282
int height,
@@ -326,12 +348,7 @@ class SK_API GrBackendRenderTarget {
326348

327349

328350
#if GR_TEST_UTILS
329-
// We can remove the pixelConfig getter and setter once we remove the pixel config from the
330-
// GrBackendRenderTarget and plumb the pixel config manually throughout our code (or remove all
331-
// use of GrPixelConfig in general).
332-
GrPixelConfig pixelConfig() const { return fConfig; }
333-
void setPixelConfig(GrPixelConfig config) { fConfig = config; }
334-
351+
GrPixelConfig testingOnly_getPixelConfig() const;
335352
static bool TestingOnly_Equals(const GrBackendRenderTarget&, const GrBackendRenderTarget&);
336353
#endif
337354

src/gpu/GrAHardwareBufferImageGenerator.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,12 @@ sk_sp<GrTextureProxy> GrAHardwareBufferImageGenerator::makeProxy(GrContext* cont
213213
return nullptr;
214214
}
215215

216-
GrBackendTexture backendTex(getInfo().width(), getInfo().height(), GrMipMapped::kNo,
217-
textureInfo);
216+
GrBackendTexture backendTex(getInfo().width(), getInfo().height(), pixelConfig, textureInfo);
218217
if (backendTex.width() <= 0 || backendTex.height() <= 0) {
219218
glDeleteTextures(1, &texID);
220219
eglDestroyImageKHR(display, image);
221220
return nullptr;
222221
}
223-
backendTex.fConfig = pixelConfig;
224222
sk_sp<GrTexture> tex = context->contextPriv().resourceProvider()->wrapBackendTexture(
225223
backendTex, kAdopt_GrWrapOwnership);
226224
if (!tex) {

src/gpu/GrBackendSurface.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ GrBackendTexture::GrBackendTexture(int width,
9696
: fIsValid(true)
9797
, fWidth(width)
9898
, fHeight(height)
99-
, fConfig(kUnknown_GrPixelConfig)
99+
, fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
100100
, fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
101101
, fBackend(kVulkan_GrBackend)
102102
, fVkInfo(vkInfo, layout.release()) {
@@ -117,14 +117,36 @@ GrBackendTexture::GrBackendTexture(int width,
117117
, fMtlInfo(mtlInfo) {}
118118
#endif
119119

120+
#if GR_TEST_UTILS
121+
122+
GrBackendTexture::GrBackendTexture(int width,
123+
int height,
124+
GrPixelConfig config,
125+
const GrGLTextureInfo& glInfo)
126+
: GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
127+
128+
GrBackendTexture::GrBackendTexture(int width,
129+
int height,
130+
GrPixelConfig config,
131+
GrMipMapped mipMapped,
132+
const GrGLTextureInfo& glInfo)
133+
: fIsValid(true)
134+
, fWidth(width)
135+
, fHeight(height)
136+
, fConfig(config)
137+
, fMipMapped(mipMapped)
138+
, fBackend(kOpenGL_GrBackend)
139+
, fGLInfo(glInfo) {}
140+
#endif
141+
120142
GrBackendTexture::GrBackendTexture(int width,
121143
int height,
122144
GrMipMapped mipMapped,
123145
const GrGLTextureInfo& glInfo)
124146
: fIsValid(true)
125147
, fWidth(width)
126148
, fHeight(height)
127-
, fConfig(kUnknown_GrPixelConfig)
149+
, fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
128150
, fMipMapped(mipMapped)
129151
, fBackend(kOpenGL_GrBackend)
130152
, fGLInfo(glInfo) {}
@@ -312,7 +334,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
312334
, fHeight(height)
313335
, fSampleCnt(SkTMax(1, sampleCnt))
314336
, fStencilBits(0) // We always create stencil buffers internally for vulkan
315-
, fConfig(kUnknown_GrPixelConfig)
337+
, fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
316338
, fBackend(kVulkan_GrBackend)
317339
, fVkInfo(vkInfo, layout.release()) {}
318340
#endif
@@ -332,6 +354,24 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
332354
, fMtlInfo(mtlInfo) {}
333355
#endif
334356

357+
#if GR_TEST_UTILS
358+
359+
GrBackendRenderTarget::GrBackendRenderTarget(int width,
360+
int height,
361+
int sampleCnt,
362+
int stencilBits,
363+
GrPixelConfig config,
364+
const GrGLFramebufferInfo& glInfo)
365+
: fIsValid(true)
366+
, fWidth(width)
367+
, fHeight(height)
368+
, fSampleCnt(SkTMax(1, sampleCnt))
369+
, fStencilBits(stencilBits)
370+
, fConfig(config)
371+
, fBackend(kOpenGL_GrBackend)
372+
, fGLInfo(glInfo) {}
373+
#endif
374+
335375
GrBackendRenderTarget::GrBackendRenderTarget(int width,
336376
int height,
337377
int sampleCnt,
@@ -342,7 +382,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
342382
, fHeight(height)
343383
, fSampleCnt(SkTMax(1, sampleCnt))
344384
, fStencilBits(stencilBits)
345-
, fConfig(kUnknown_GrPixelConfig)
385+
, fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
346386
, fBackend(kOpenGL_GrBackend)
347387
, fGLInfo(glInfo) {}
348388

src/gpu/gl/GrGLGpu.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,11 +3975,7 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in
39753975
// unbind the texture from the texture unit to avoid asserts
39763976
GL_CALL(BindTexture(info.fTarget, 0));
39773977

3978-
GrBackendTexture beTex = GrBackendTexture(w, h, mipMapped, info);
3979-
// Lots of tests don't go through Skia's public interface which will set the config so for
3980-
// testing we make sure we set a config here.
3981-
beTex.setPixelConfig(config);
3982-
return beTex;
3978+
return GrBackendTexture(w, h, mipMapped, info);
39833979
}
39843980

39853981
bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
@@ -4073,11 +4069,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h
40734069
return {};
40744070
}
40754071
auto stencilBits = SkToInt(this->glCaps().stencilFormats()[sFormatIdx].fStencilBits);
4076-
GrBackendRenderTarget beRT = GrBackendRenderTarget(w, h, 1, stencilBits, info);
4077-
// Lots of tests don't go through Skia's public interface which will set the config so for
4078-
// testing we make sure we set a config here.
4079-
beRT.setPixelConfig(config);
4080-
return beRT;
4072+
return {w, h, 1, stencilBits, config, info};
40814073
}
40824074

40834075
void GrGLGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& backendRT) {

src/gpu/gl/GrGLUtil.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,40 @@ GrGLenum GrToGLStencilFunc(GrStencilTest test) {
532532
return gTable[(int)test];
533533
}
534534

535+
GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat) {
536+
switch (sizedFormat) {
537+
case GR_GL_R8:
538+
return kAlpha_8_as_Red_GrPixelConfig;
539+
case GR_GL_ALPHA8:
540+
return kAlpha_8_as_Alpha_GrPixelConfig;
541+
case GR_GL_RGBA8:
542+
return kRGBA_8888_GrPixelConfig;
543+
case GR_GL_RGB8:
544+
return kRGB_888_GrPixelConfig;
545+
case GR_GL_BGRA8:
546+
return kBGRA_8888_GrPixelConfig;
547+
case GR_GL_SRGB8_ALPHA8:
548+
return kSRGBA_8888_GrPixelConfig;
549+
case GR_GL_RGB565:
550+
return kRGB_565_GrPixelConfig;
551+
case GR_GL_RGB5:
552+
return kRGB_565_GrPixelConfig;
553+
case GR_GL_RGBA4:
554+
return kRGBA_4444_GrPixelConfig;
555+
case GR_GL_RGB10_A2:
556+
return kRGBA_1010102_GrPixelConfig;
557+
case GR_GL_LUMINANCE8:
558+
return kGray_8_GrPixelConfig;
559+
case GR_GL_RGBA32F:
560+
return kRGBA_float_GrPixelConfig;
561+
case GR_GL_RG32F:
562+
return kRG_float_GrPixelConfig;
563+
case GR_GL_R16F:
564+
return kAlpha_half_as_Red_GrPixelConfig;
565+
case GR_GL_RGBA16F:
566+
return kRGBA_half_GrPixelConfig;
567+
default:
568+
return kUnknown_GrPixelConfig;
569+
}
570+
}
571+

src/gpu/gl/GrGLUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,6 @@ void GrGLClearErr(const GrGLInterface* gl);
256256

257257
GrGLenum GrToGLStencilFunc(GrStencilTest test);
258258

259+
GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat);
260+
259261
#endif

src/gpu/vk/GrVkGpu.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,11 +1359,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(const void* srcData, i
13591359
&info)) {
13601360
return {};
13611361
}
1362-
GrBackendTexture beTex = GrBackendTexture(w, h, info);
1363-
// Lots of tests don't go through Skia's public interface which will set the config so for
1364-
// testing we make sure we set a config here.
1365-
beTex.setPixelConfig(config);
1366-
return beTex;
1362+
return GrBackendTexture(w, h, info);
13671363
}
13681364

13691365
bool GrVkGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
@@ -1413,11 +1409,7 @@ GrBackendRenderTarget GrVkGpu::createTestingOnlyBackendRenderTarget(int w, int h
14131409
&info)) {
14141410
return {};
14151411
}
1416-
GrBackendRenderTarget beRT = GrBackendRenderTarget(w, h, 1, 0, info);
1417-
// Lots of tests don't go through Skia's public interface which will set the config so for
1418-
// testing we make sure we set a config here.
1419-
beRT.setPixelConfig(config);
1420-
return beRT;
1412+
return {w, h, 1, 0, info};
14211413
}
14221414

14231415
void GrVkGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& rt) {

src/gpu/vk/GrVkUtil.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,40 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
7575
return false;
7676
}
7777

78+
GrPixelConfig GrVkFormatToPixelConfig(VkFormat format) {
79+
switch (format) {
80+
case VK_FORMAT_R8G8B8A8_UNORM:
81+
return kRGBA_8888_GrPixelConfig;
82+
case VK_FORMAT_B8G8R8A8_UNORM:
83+
return kBGRA_8888_GrPixelConfig;
84+
case VK_FORMAT_R8G8B8A8_SRGB:
85+
return kSRGBA_8888_GrPixelConfig;
86+
case VK_FORMAT_B8G8R8A8_SRGB:
87+
return kSBGRA_8888_GrPixelConfig;
88+
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
89+
return kRGBA_1010102_GrPixelConfig;
90+
case VK_FORMAT_R5G6B5_UNORM_PACK16:
91+
return kRGB_565_GrPixelConfig;
92+
break;
93+
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
94+
// R4G4B4A4 is not required to be supported so we actually
95+
// store RGBA_4444 data as B4G4R4A4.
96+
return kRGBA_4444_GrPixelConfig;
97+
case VK_FORMAT_R8_UNORM:
98+
return kAlpha_8_GrPixelConfig;
99+
case VK_FORMAT_R32G32B32A32_SFLOAT:
100+
return kRGBA_float_GrPixelConfig;
101+
case VK_FORMAT_R32G32_SFLOAT:
102+
return kRG_float_GrPixelConfig;
103+
case VK_FORMAT_R16G16B16A16_SFLOAT:
104+
return kRGBA_half_GrPixelConfig;
105+
case VK_FORMAT_R16_SFLOAT:
106+
return kAlpha_half_GrPixelConfig;
107+
default:
108+
return kUnknown_GrPixelConfig;
109+
}
110+
}
111+
78112
bool GrVkFormatPixelConfigPairIsValid(VkFormat format, GrPixelConfig config) {
79113
switch (format) {
80114
case VK_FORMAT_R8G8B8A8_UNORM:

src/gpu/vk/GrVkUtil.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class GrVkGpu;
3333
*/
3434
bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format);
3535

36+
/**
37+
* Returns the GrPixelConfig for the given vulkan texture format
38+
*/
39+
GrPixelConfig GrVkFormatToPixelConfig(VkFormat format);
40+
3641
bool GrVkFormatIsSupported(VkFormat);
3742

3843
/**

tests/EGLImageTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
153153
}
154154

155155
// Wrap this texture ID in a GrTexture
156-
GrBackendTexture backendTex(kSize, kSize, GrMipMapped::kNo, externalTexture);
157-
backendTex.setPixelConfig(kRGBA_8888_GrPixelConfig);
156+
GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, externalTexture);
158157

159158
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
160159
// fails on the Nexus5. Why?

0 commit comments

Comments
 (0)