Skip to content

Commit 1e2cb44

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Switch GrCaps::areColorTypeAndFormatCompatible over to using GrColorType
This necessitated some Gr*Caps refactoring Change-Id: I8d72e9645b51bcf72d58b2c2c4fbd9ee7e83ddf1 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225184 Reviewed-by: Brian Salomon <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent 4d03689 commit 1e2cb44

12 files changed

Lines changed: 299 additions & 126 deletions

File tree

‎src/gpu/GrCaps.h‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,35 @@ class GrCaps : public SkRefCnt {
362362
* returned.
363363
*/
364364
virtual GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
365-
SkColorType) const = 0;
365+
GrColorType) const = 0;
366366

367-
virtual bool areColorTypeAndFormatCompatible(SkColorType ct, const GrBackendFormat&) const = 0;
367+
bool areColorTypeAndFormatCompatible(SkColorType skCT,
368+
const GrBackendFormat& format) const {
369+
GrColorType grCT = SkColorTypeToGrColorType(skCT);
370+
if (GrColorType::kUnknown == grCT) {
371+
return false;
372+
}
373+
374+
return this->areColorTypeAndFormatCompatible(grCT, format);
375+
}
376+
377+
virtual bool areColorTypeAndFormatCompatible(GrColorType ct, const GrBackendFormat&) const = 0;
378+
379+
GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat& format,
380+
SkColorType skCT) const {
381+
GrColorType grCT = SkColorTypeToGrColorType(skCT);
382+
if (GrColorType::kUnknown == grCT) {
383+
return kUnknown_GrPixelConfig;
384+
}
385+
386+
return this->getConfigFromBackendFormat(format, grCT);
387+
}
368388

369389
// TODO: replace validateBackendRenderTarget with calls to getConfigFromBackendFormat?
370390
// TODO: it seems like we could pass the full SkImageInfo and validate its colorSpace too
371391
// Returns kUnknown if a valid config could not be determined.
372392
virtual GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat& format,
373-
SkColorType ct) const = 0;
393+
GrColorType ct) const = 0;
374394

375395
/**
376396
* Special method only for YUVA images. Returns a config that matches the backend format or

‎src/gpu/GrProxyProvider.cpp‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,10 @@ static bool validate_backend_format_and_config(const GrCaps* caps,
415415
// We have no way to verify these at the moment.
416416
return true;
417417
}
418-
SkColorType colorType = GrColorTypeToSkColorType(GrPixelConfigToColorType(config));
419-
if (colorType == kUnknown_SkColorType) {
420-
// We should add support for validating GrColorType with a GrBackendFormat. Currently we
421-
// only support SkColorType. For now we just assume things that don't have a corresponding
422-
// SkColorType are correct.
423-
return true;
424-
}
425418

426-
return caps->areColorTypeAndFormatCompatible(colorType, format);
419+
GrColorType grCT = GrPixelConfigToColorType(config);
420+
421+
return caps->areColorTypeAndFormatCompatible(grCT, format);
427422
}
428423
#endif
429424

@@ -618,8 +613,7 @@ sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
618613
GrColorType colorType = GrPixelConfigToColorType(backendRT.config());
619614
#ifdef SK_DEBUG
620615
GrPixelConfig testConfig =
621-
this->caps()->validateBackendRenderTarget(backendRT,
622-
GrColorTypeToSkColorType(colorType));
616+
this->caps()->validateBackendRenderTarget(backendRT, colorType);
623617
SkASSERT(testConfig != kUnknown_GrPixelConfig);
624618
#endif
625619

‎src/gpu/SkGpuDevice.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,7 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
16771677
format = fContext->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
16781678
}
16791679

1680-
auto config = fContext->priv().caps()->getConfigFromBackendFormat(
1681-
format, GrColorTypeToSkColorType(colorType));
1680+
auto config = fContext->priv().caps()->getConfigFromBackendFormat(format, colorType);
16821681
sk_sp<GrRenderTargetContext> rtc(fContext->priv().makeDeferredRenderTargetContext(
16831682
format,
16841683
fit,

‎src/gpu/gl/GrGLCaps.cpp‎

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,9 +3619,14 @@ bool GrGLCaps::isFormatTexturable(SkColorType ct, const GrBackendFormat& format)
36193619
return this->isGLFormatTexturable(grCT, *glFormat);
36203620
}
36213621

3622-
int GrGLCaps::getRenderTargetSampleCount(int requestedCount, SkColorType ct,
3622+
int GrGLCaps::getRenderTargetSampleCount(int requestedCount, SkColorType skCT,
36233623
const GrBackendFormat& format) const {
3624-
GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
3624+
GrColorType grCT = SkColorTypeToGrColorType(skCT);
3625+
if (GrColorType::kUnknown == grCT) {
3626+
return 0;
3627+
}
3628+
3629+
GrPixelConfig config = this->getConfigFromBackendFormat(format, grCT);
36253630
if (kUnknown_GrPixelConfig == config) {
36263631
return 0;
36273632
}
@@ -3652,8 +3657,13 @@ int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig confi
36523657
return 0;
36533658
}
36543659

3655-
int GrGLCaps::maxRenderTargetSampleCount(SkColorType ct, const GrBackendFormat& format) const {
3656-
GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
3660+
int GrGLCaps::maxRenderTargetSampleCount(SkColorType skCT, const GrBackendFormat& format) const {
3661+
GrColorType grCT = SkColorTypeToGrColorType(skCT);
3662+
if (GrColorType::kUnknown == grCT) {
3663+
return 0;
3664+
}
3665+
3666+
GrPixelConfig config = this->getConfigFromBackendFormat(format, grCT);
36573667
if (kUnknown_GrPixelConfig == config) {
36583668
return 0;
36593669
}
@@ -3689,42 +3699,48 @@ bool GrGLCaps::isFormatCopyable(SkColorType ct, const GrBackendFormat& format) c
36893699
return this->canFormatBeFBOColorAttachment(*glFormat);
36903700
}
36913701

3692-
GrPixelConfig validate_sized_format(GrGLenum format, SkColorType ct, GrGLStandard standard) {
3702+
// A near clone of format_color_type_valid_pair
3703+
GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
36933704
switch (ct) {
3694-
case kUnknown_SkColorType:
3705+
case GrColorType::kUnknown:
36953706
return kUnknown_GrPixelConfig;
3696-
case kAlpha_8_SkColorType:
3707+
case GrColorType::kAlpha_8:
36973708
if (GR_GL_ALPHA8 == format) {
36983709
return kAlpha_8_as_Alpha_GrPixelConfig;
36993710
} else if (GR_GL_R8 == format) {
37003711
return kAlpha_8_as_Red_GrPixelConfig;
37013712
}
37023713
break;
3703-
case kRGB_565_SkColorType:
3714+
case GrColorType::kBGR_565:
37043715
if (GR_GL_RGB565 == format) {
37053716
return kRGB_565_GrPixelConfig;
37063717
}
37073718
break;
3708-
case kARGB_4444_SkColorType:
3719+
case GrColorType::kABGR_4444:
37093720
if (GR_GL_RGBA4 == format) {
37103721
return kRGBA_4444_GrPixelConfig;
37113722
}
37123723
break;
3713-
case kRGBA_8888_SkColorType:
3724+
case GrColorType::kRGBA_8888:
37143725
if (GR_GL_RGBA8 == format) {
37153726
return kRGBA_8888_GrPixelConfig;
37163727
} else if (GR_GL_SRGB8_ALPHA8 == format) {
37173728
return kSRGBA_8888_GrPixelConfig;
37183729
}
37193730
break;
3720-
case kRGB_888x_SkColorType:
3731+
case GrColorType::kRGB_888x:
37213732
if (GR_GL_RGB8 == format) {
37223733
return kRGB_888_GrPixelConfig;
37233734
} else if (GR_GL_RGBA8 == format) {
37243735
return kRGB_888X_GrPixelConfig;
37253736
}
37263737
break;
3727-
case kBGRA_8888_SkColorType:
3738+
case GrColorType::kRG_88:
3739+
if (GR_GL_RG8 == format) {
3740+
return kRG_88_GrPixelConfig;
3741+
}
3742+
break;
3743+
case GrColorType::kBGRA_8888:
37283744
if (GR_GL_RGBA8 == format) {
37293745
if (GR_IS_GR_GL(standard)) {
37303746
return kBGRA_8888_GrPixelConfig;
@@ -3735,50 +3751,79 @@ GrPixelConfig validate_sized_format(GrGLenum format, SkColorType ct, GrGLStandar
37353751
}
37363752
}
37373753
break;
3738-
case kRGBA_1010102_SkColorType:
3754+
case GrColorType::kRGBA_1010102:
37393755
if (GR_GL_RGB10_A2 == format) {
37403756
return kRGBA_1010102_GrPixelConfig;
37413757
}
37423758
break;
3743-
case kRGB_101010x_SkColorType:
3744-
break;
3745-
case kGray_8_SkColorType:
3759+
case GrColorType::kGray_8:
37463760
if (GR_GL_LUMINANCE8 == format) {
37473761
return kGray_8_as_Lum_GrPixelConfig;
37483762
} else if (GR_GL_R8 == format) {
37493763
return kGray_8_as_Red_GrPixelConfig;
37503764
}
37513765
break;
3752-
case kRGBA_F16Norm_SkColorType:
3753-
if (GR_GL_RGBA16F == format) {
3754-
return kRGBA_half_Clamped_GrPixelConfig;
3766+
case GrColorType::kAlpha_F16:
3767+
if (GR_GL_R16F == format) {
3768+
return kAlpha_half_GrPixelConfig;
37553769
}
37563770
break;
3757-
case kRGBA_F16_SkColorType:
3771+
case GrColorType::kRGBA_F16:
37583772
if (GR_GL_RGBA16F == format) {
37593773
return kRGBA_half_GrPixelConfig;
37603774
}
37613775
break;
3762-
case kRGBA_F32_SkColorType:
3776+
case GrColorType::kRGBA_F16_Clamped:
3777+
if (GR_GL_RGBA16F == format) {
3778+
return kRGBA_half_Clamped_GrPixelConfig;
3779+
}
3780+
break;
3781+
case GrColorType::kRG_F32:
3782+
if (GR_GL_RG32F == format) {
3783+
return kRG_float_GrPixelConfig;
3784+
}
3785+
break;
3786+
case GrColorType::kRGBA_F32:
37633787
if (GR_GL_RGBA32F == format) {
37643788
return kRGBA_float_GrPixelConfig;
37653789
}
37663790
break;
3791+
case GrColorType::kR_16:
3792+
if (GR_GL_R16 == format) {
3793+
return kR_16_GrPixelConfig;
3794+
}
3795+
break;
3796+
case GrColorType::kRG_1616:
3797+
if (GR_GL_RG16 == format) {
3798+
return kRG_1616_GrPixelConfig;
3799+
}
3800+
break;
3801+
case GrColorType::kRGBA_16161616:
3802+
if (GR_GL_RGBA16 == format) {
3803+
return kRGBA_16161616_GrPixelConfig;
3804+
}
3805+
break;
3806+
case GrColorType::kRG_F16:
3807+
if (GR_GL_RG16F == format) {
3808+
return kRG_half_GrPixelConfig;
3809+
}
3810+
break;
37673811
}
3812+
37683813
SkDebugf("Unknown pixel config 0x%x\n", format);
37693814
return kUnknown_GrPixelConfig;
37703815
}
37713816

37723817
GrPixelConfig GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt,
3773-
SkColorType ct) const {
3818+
GrColorType ct) const {
37743819
GrGLFramebufferInfo fbInfo;
37753820
if (!rt.getGLFramebufferInfo(&fbInfo)) {
37763821
return kUnknown_GrPixelConfig;
37773822
}
37783823
return validate_sized_format(fbInfo.fFormat, ct, fStandard);
37793824
}
37803825

3781-
bool GrGLCaps::areColorTypeAndFormatCompatible(SkColorType ct,
3826+
bool GrGLCaps::areColorTypeAndFormatCompatible(GrColorType ct,
37823827
const GrBackendFormat& format) const {
37833828
const GrGLenum* glFormat = format.getGLFormat();
37843829
if (!glFormat) {
@@ -3789,7 +3834,7 @@ bool GrGLCaps::areColorTypeAndFormatCompatible(SkColorType ct,
37893834
}
37903835

37913836
GrPixelConfig GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format,
3792-
SkColorType ct) const {
3837+
GrColorType ct) const {
37933838
const GrGLenum* glFormat = format.getGLFormat();
37943839
if (!glFormat) {
37953840
return kUnknown_GrPixelConfig;

‎src/gpu/gl/GrGLCaps.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ class GrGLCaps : public GrCaps {
417417
bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; }
418418

419419
GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
420-
SkColorType) const override;
420+
GrColorType) const override;
421421

422-
bool areColorTypeAndFormatCompatible(SkColorType, const GrBackendFormat&) const override;
422+
bool areColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
423423

424-
GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override;
424+
GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
425425
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
426426

427427
GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,

‎src/gpu/gl/GrGLGpu.cpp‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,13 +4131,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h
41314131
// Lots of tests don't go through Skia's public interface which will set the config so for
41324132
// testing we make sure we set a config here.
41334133
beRT.setPixelConfig(config);
4134-
#ifdef SK_DEBUG
4135-
SkColorType skColorType = GrColorTypeToSkColorType(colorType);
4136-
if (skColorType != kUnknown_SkColorType) {
4137-
SkASSERT(this->caps()->validateBackendRenderTarget(
4138-
beRT, GrColorTypeToSkColorType(colorType)) != kUnknown_GrPixelConfig);
4139-
}
4140-
#endif
4134+
SkASSERT(kUnknown_GrPixelConfig != this->caps()->validateBackendRenderTarget(beRT, colorType));
41414135
return beRT;
41424136
}
41434137

0 commit comments

Comments
 (0)