Skip to content

Commit f606bd7

Browse files
committed
Never reject an MSAA FBO0
GLES2 doesn't support MSAA FBOs, so GrCaps thought it was supposed to reject an MSAA wrapper on FBO0. This actually isn't correct. In GLES2, FBO0 can still be multisampled.
1 parent 67f70c5 commit f606bd7

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

src/gpu/GrCaps.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,17 @@ class GrCaps : public SkRefCnt {
240240
virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
241241
int sampleCount = 1) const = 0;
242242

243+
virtual bool isRenderTargetAsColorTypeRenderable(GrColorType ct,
244+
const GrBackendRenderTarget& rt) const {
245+
return this->isFormatAsColorTypeRenderable(ct, rt.getBackendFormat(), rt.sampleCnt());
246+
}
247+
243248
virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0;
244249

250+
virtual bool isRenderTargetRenderable(const GrBackendRenderTarget& rt) const {
251+
return this->isFormatRenderable(rt.getBackendFormat(), rt.sampleCnt());
252+
}
253+
245254
// Find a sample count greater than or equal to the requested count which is supported for a
246255
// render target of the given format or 0 if no such sample count is supported. If the requested
247256
// sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0.

src/gpu/GrGpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget
359359

360360
const GrCaps* caps = this->caps();
361361

362-
if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) {
362+
if (!caps->isRenderTargetRenderable(backendRT)) {
363363
return nullptr;
364364
}
365365

src/gpu/gl/GrGLCaps.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4481,6 +4481,20 @@ bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendForm
44814481
return this->isFormatRenderable(f, sampleCount);
44824482
}
44834483

4484+
bool GrGLCaps::isRenderTargetAsColorTypeRenderable(GrColorType ct,
4485+
const GrBackendRenderTarget& rt) const {
4486+
int sampleCntToCheck;
4487+
GrGLFramebufferInfo fbi;
4488+
if (rt.getGLFramebufferInfo(&fbi) && fbi.fFBOID == 0) {
4489+
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
4490+
// FBO0 and told us it's multisampled, just trust that the msaa is valid.
4491+
sampleCntToCheck = 1;
4492+
} else {
4493+
sampleCntToCheck = rt.sampleCnt();
4494+
}
4495+
return this->isFormatAsColorTypeRenderable(ct, rt.getBackendFormat(), sampleCntToCheck);
4496+
}
4497+
44844498
bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
44854499
if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
44864500
return false;
@@ -4491,6 +4505,19 @@ bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount
44914505
return this->isFormatRenderable(format.asGLFormat(), sampleCount);
44924506
}
44934507

4508+
bool GrGLCaps::isRenderTargetRenderable(const GrBackendRenderTarget& rt) const {
4509+
int sampleCntToCheck;
4510+
GrGLFramebufferInfo fbi;
4511+
if (rt.getGLFramebufferInfo(&fbi) && fbi.fFBOID == 0) {
4512+
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
4513+
// FBO0 and told us it's multisampled, just trust that the msaa is valid.
4514+
sampleCntToCheck = 1;
4515+
} else {
4516+
sampleCntToCheck = rt.sampleCnt();
4517+
}
4518+
return this->isFormatRenderable(rt.getBackendFormat(), sampleCntToCheck);
4519+
}
4520+
44944521
int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
44954522
const FormatInfo& info = this->getFormatInfo(format);
44964523

src/gpu/gl/GrGLCaps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ class GrGLCaps : public GrCaps {
125125

126126
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
127127
int sampleCount = 1) const override;
128+
bool isRenderTargetAsColorTypeRenderable(GrColorType,
129+
const GrBackendRenderTarget&) const override;
128130
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
131+
bool isRenderTargetRenderable(const GrBackendRenderTarget&) const override;
129132
bool isFormatRenderable(GrGLFormat format, int sampleCount) const {
130133
return sampleCount <= this->maxRenderTargetSampleCount(format);
131134
}

src/gpu/gl/GrGLGpu.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,12 +784,19 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
784784
return nullptr;
785785
}
786786

787-
const auto format = backendRT.getBackendFormat().asGLFormat();
788-
if (!this->glCaps().isFormatRenderable(format, backendRT.sampleCnt())) {
787+
if (!this->glCaps().isRenderTargetRenderable(backendRT)) {
789788
return nullptr;
790789
}
791790

792-
int sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
791+
const auto format = backendRT.getBackendFormat().asGLFormat();
792+
int sampleCount;
793+
if (info.fFBOID == 0) {
794+
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
795+
// FBO0 and told us it's multisampled, just trust the provided sample count.
796+
sampleCount = backendRT.sampleCnt();
797+
} else {
798+
sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
799+
}
793800

794801
GrGLRenderTarget::IDs rtIDs;
795802
if (sampleCount <= 1) {

src/image/SkSurface_Gpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ bool validate_backend_render_target(const GrCaps* caps, const GrBackendRenderTar
579579
return false;
580580
}
581581

582-
if (!caps->isFormatAsColorTypeRenderable(grCT, rt.getBackendFormat(), rt.sampleCnt())) {
582+
if (!caps->isRenderTargetAsColorTypeRenderable(grCT, rt)) {
583583
return false;
584584
}
585585

0 commit comments

Comments
 (0)