///////////////////////////////////////////////////////////////////////////////
-// Used in the map of pixel configs to stencil format indices. This value is used to
-// indicate that a stencil format has not yet been set for the given config.
-static const int kUnknownStencilIndex = -1;
-// This value is used as the stencil index when no stencil configs are supported with the
-// given pixel config.
-static const int kUnsupportedStencilIndex = -2;
-
-///////////////////////////////////////////////////////////////////////////////
GrGpu* GrGLGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
GrContext* context) {
SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVertexAttribs);
- for (int i = 0; i < kGrPixelConfigCnt; ++i) {
- fPixelConfigToStencilIndex[i] = kUnknownStencilIndex;
- }
fHWProgramID = 0;
fTempSrcFBOID = 0;
fTempDstFBOID = 0;
int GrGLGpu::getCompatibleStencilIndex(GrPixelConfig config) {
static const int kSize = 16;
- if (kUnknownStencilIndex == fPixelConfigToStencilIndex[config]) {
+ if (ConfigEntry::kUnknown_StencilIndex == fConfigTable[config].fStencilFormatIndex) {
// Default to unsupported
- fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex;
+ fConfigTable[config].fStencilFormatIndex = ConfigEntry::kUnsupported_StencilFormatIndex;
// Create color texture
GrGLuint colorID = 0;
GL_CALL(GenTextures(1, &colorID));
if (!this->configToGLFormats(config, useSizedFormat, &internalFormat,
&externalFormat, &externalType)) {
GL_CALL(DeleteTextures(1, &colorID));
- fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex;
- return kUnsupportedStencilIndex;
+ return ConfigEntry::kUnsupported_StencilFormatIndex;
}
CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
NULL));
if (GR_GL_NO_ERROR != GR_GL_GET_ERROR(this->glInterface())) {
GL_CALL(DeleteTextures(1, &colorID));
- fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex;
- return kUnsupportedStencilIndex;
+ return ConfigEntry::kUnsupported_StencilFormatIndex;
}
// unbind the texture from the texture unit before binding it to the frame buffer
GR_GL_RENDERBUFFER, 0));
}
} else {
- fPixelConfigToStencilIndex[config] = i;
+ fConfigTable[config].fStencilFormatIndex = i;
break;
}
}
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
GL_CALL(DeleteFramebuffers(1, &fb));
}
- SkASSERT(kUnknownStencilIndex != fPixelConfigToStencilIndex[config]);
- return fPixelConfigToStencilIndex[config];
+ SkASSERT(ConfigEntry::kUnknown_StencilIndex != fConfigTable[config].fStencilFormatIndex);
+ return fConfigTable[config].fStencilFormatIndex;
}
GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
GrGLStencilAttachment::IDDesc sbDesc;
int sIdx = this->getCompatibleStencilIndex(rt->config());
- if (sIdx == kUnsupportedStencilIndex) {
+ if (sIdx < 0) {
return nullptr;
}
GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
GrWrapOwnership) override;
// Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
- // compatible stencil format.
+ // compatible stencil format, or negative if there is no compatible stencil format.
int getCompatibleStencilIndex(GrPixelConfig config);
void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override;
struct ConfigEntry {
// Default constructor inits to known bad GL enum values.
- ConfigEntry() { memset(this, 0xAB, sizeof(ConfigEntry)); }
+ ConfigEntry() {
+ memset(this, 0xAB, sizeof(ConfigEntry));
+ fStencilFormatIndex = kUnknown_StencilIndex;
+ }
GrGLenum fBaseInternalFormat;
GrGLenum fSizedInternalFormat;
GrGLenum fExternalFormat;
GrGLenum fExternalType;
- };
- ConfigEntry fConfigTable[kLast_GrPixelConfig + 1];
+ // Index into GrGLCaps's list of stencil formats. Support is determined experimentally and
+ // lazily.
+ int fStencilFormatIndex;
+ enum {
+ // This indicates that a stencil format has not yet been determined for the config.
+ kUnknown_StencilIndex = -1,
+ // This indicates that there is no supported stencil format for the config.
+ kUnsupported_StencilFormatIndex = -2
+ };
+ };
- // Mapping of pixel configs to known supported stencil formats to be used
- // when adding a stencil buffer to a framebuffer.
- int fPixelConfigToStencilIndex[kGrPixelConfigCnt];
+ ConfigEntry fConfigTable[kGrPixelConfigCnt];
typedef GrGpu INHERITED;
friend class GrGLPathRendering; // For accessing setTextureUnit.