Move renderable config list to GrDrawTargetCaps

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/26342006

git-svn-id: http://skia.googlecode.com/svn/trunk@11756 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-10-14 15:33:45 +00:00
parent 2887119a63
commit 7388051d74
9 changed files with 108 additions and 86 deletions

View File

@ -1689,7 +1689,7 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
////////////////////////////////////////////////////////////////////////////////
bool GrContext::isConfigRenderable(GrPixelConfig config) const {
return fGpu->isConfigRenderable(config);
return fGpu->caps()->isConfigRenderable(config);
}
static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {

View File

@ -981,6 +981,8 @@ void GrDrawTargetCaps::reset() {
fMaxRenderTargetSize = 0;
fMaxTextureSize = 0;
fMaxSampleCount = 0;
memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
}
GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
@ -1001,6 +1003,8 @@ GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
fMaxTextureSize = other.fMaxTextureSize;
fMaxSampleCount = other.fMaxSampleCount;
memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
return *this;
}
@ -1021,4 +1025,29 @@ void GrDrawTargetCaps::print() const {
GrPrintf("Max Texture Size : %d\n", fMaxTextureSize);
GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
GrPrintf("Max Sample Count : %d\n", fMaxSampleCount);
static const char* kConfigNames[] = {
"Unknown", // kUnknown_GrPixelConfig
"Alpha8", // kAlpha_8_GrPixelConfig,
"Index8", // kIndex_8_GrPixelConfig,
"RGB565", // kRGB_565_GrPixelConfig,
"RGBA444", // kRGBA_4444_GrPixelConfig,
"RGBA8888", // kRGBA_8888_GrPixelConfig,
"BGRA8888", // kBGRA_8888_GrPixelConfig,
};
GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig]);
for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
if (i != kUnknown_GrPixelConfig) {
GrPrintf("%s is renderable: %s\n", kConfigNames[i], gNY[fConfigRenderSupport[i]]);
}
}
}

View File

@ -7,6 +7,7 @@
*/
#include "SkRefCnt.h"
#include "GrTypes.h"
#ifndef GrDrawTargetCaps_DEFINED
#define GrDrawTargetCaps_DEFINED
@ -43,6 +44,14 @@ public:
// Will be 0 if MSAA is not supported
int maxSampleCount() const { return fMaxSampleCount; }
/**
* Can the provided configuration act as a render target?
*/
bool isConfigRenderable(GrPixelConfig config) const {
SkASSERT(kGrPixelConfigCnt > config);
return fConfigRenderSupport[config];
}
protected:
bool f8BitPaletteSupport : 1;
bool fNPOTTextureTileSupport : 1;
@ -61,6 +70,8 @@ protected:
int fMaxTextureSize;
int fMaxSampleCount;
bool fConfigRenderSupport[kGrPixelConfigCnt];
typedef SkRefCnt INHERITED;
};

View File

@ -47,10 +47,6 @@ GrGpu::GrGpu(GrContext* context)
poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
#endif
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
fConfigRenderSupport[i] = false;
};
}
GrGpu::~GrGpu() {

View File

@ -290,14 +290,6 @@ public:
return fResetTimestamp;
}
/**
* Can the provided configuration act as a color render target?
*/
bool isConfigRenderable(GrPixelConfig config) const {
SkASSERT(kGrPixelConfigCnt > config);
return fConfigRenderSupport[config];
}
/**
* These methods are called by the clip manager's setupClipping function
* which (called as part of GrGpu's implementation of onDraw and
@ -401,10 +393,6 @@ protected:
// The final stencil settings to use as determined by the clip manager.
GrStencilSettings fStencilSettings;
// Derived classes need access to this so they can fill it out in their
// constructors
bool fConfigRenderSupport[kGrPixelConfigCnt];
// Helpers for setting up geometry state
void finalizeReservedVertices();
void finalizeReservedIndices();

View File

@ -334,6 +334,67 @@ void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
} else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
}
this->initConfigRenderableTable(ctxInfo);
}
void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
// OpenGL < 3.0
// no support for render targets unless the GL_ARB_framebuffer_object
// extension is supported (in which case we get ALPHA, RED, RG, RGB,
// RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
// probably don't get R8 in this case.
// OpenGL 3.0
// base color renderable: ALPHA, RED, RG, RGB, and RGBA
// sized derivatives: ALPHA8, R8, RGBA4, RGBA8
// >= OpenGL 3.1
// base color renderable: RED, RG, RGB, and RGBA
// sized derivatives: R8, RGBA4, RGBA8
// if the GL_ARB_compatibility extension is supported then we get back
// support for GL_ALPHA and ALPHA8
// GL_EXT_bgra adds BGRA render targets to any version
// ES 2.0
// color renderable: RGBA4, RGB5_A1, RGB565
// GL_EXT_texture_rg adds support for R8 as a color render target
// GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
// GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
// ES 3.0
// Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
// below already account for this).
if (kDesktop_GrGLBinding == ctxInfo.binding()) {
// Post 3.0 we will get R8
// Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
if (ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true;
}
} else {
// On ES we can only hope for R8
fConfigRenderSupport[kAlpha_8_GrPixelConfig] = fTextureRedSupport;
}
if (kDesktop_GrGLBinding != ctxInfo.binding()) {
// only available in ES
fConfigRenderSupport[kRGB_565_GrPixelConfig] = true;
}
// we no longer support 444 as a render target
fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false;
if (this->fRGBA8RenderbufferSupport) {
fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true;
}
if (this->fBGRAFormatSupport) {
fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true;
}
}
bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,

View File

@ -286,8 +286,9 @@ private:
}
};
void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
void initStencilFormats(const GrGLContextInfo& ctxInfo);
void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
void initStencilFormats(const GrGLContextInfo&);
void initConfigRenderableTable(const GrGLContextInfo&);
// tracks configs that have been verified to pass the FBO completeness when
// used as a color attachment

View File

@ -127,9 +127,6 @@ GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context)
fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits());
fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords());
fillInConfigRenderableTable();
GrGLClearErr(fGLContext.interface());
if (gPrintStartupSpew) {
@ -177,65 +174,6 @@ GrGpuGL::~GrGpuGL() {
///////////////////////////////////////////////////////////////////////////////
void GrGpuGL::fillInConfigRenderableTable() {
// OpenGL < 3.0
// no support for render targets unless the GL_ARB_framebuffer_object
// extension is supported (in which case we get ALPHA, RED, RG, RGB,
// RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
// probably don't get R8 in this case.
// OpenGL 3.0
// base color renderable: ALPHA, RED, RG, RGB, and RGBA
// sized derivatives: ALPHA8, R8, RGBA4, RGBA8
// >= OpenGL 3.1
// base color renderable: RED, RG, RGB, and RGBA
// sized derivatives: R8, RGBA4, RGBA8
// if the GL_ARB_compatibility extension is supported then we get back
// support for GL_ALPHA and ALPHA8
// GL_EXT_bgra adds BGRA render targets to any version
// ES 2.0
// color renderable: RGBA4, RGB5_A1, RGB565
// GL_EXT_texture_rg adds support for R8 as a color render target
// GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
// GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
// ES 3.0
// Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
// below already account for this).
if (kDesktop_GrGLBinding == this->glBinding()) {
// Post 3.0 we will get R8
// Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
if (this->glVersion() >= GR_GL_VER(3,0) ||
this->hasExtension("GL_ARB_framebuffer_object")) {
fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true;
}
} else {
// On ES we can only hope for R8
fConfigRenderSupport[kAlpha_8_GrPixelConfig] =
this->glCaps().textureRedSupport();
}
if (kDesktop_GrGLBinding != this->glBinding()) {
// only available in ES
fConfigRenderSupport[kRGB_565_GrPixelConfig] = true;
}
// we no longer support 444 as a render target
fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false;
if (this->glCaps().rgba8RenderbufferSupport()) {
fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true;
}
if (this->glCaps().bgraFormatSupport()) {
fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true;
}
}
GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig,
GrPixelConfig surfaceConfig) const {
@ -2460,8 +2398,8 @@ inline bool can_blit_framebuffer(const GrSurface* dst,
const GrSurface* src,
const GrGpuGL* gpu,
bool* wouldNeedTempFBO = NULL) {
if (gpu->isConfigRenderable(dst->config()) &&
gpu->isConfigRenderable(src->config()) &&
if (gpu->glCaps().isConfigRenderable(dst->config()) &&
gpu->glCaps().isConfigRenderable(src->config()) &&
gpu->glCaps().usesMSAARenderBuffers()) {
// ES3 doesn't allow framebuffer blits when the src has MSAA and the configs don't match
// or the rects are not the same (not just the same size but have the same edges).
@ -2501,7 +2439,7 @@ inline bool can_copy_texsubimage(const GrSurface* dst,
if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
return false;
}
if (gpu->isConfigRenderable(src->config()) && NULL != dst->asTexture() &&
if (gpu->glCaps().isConfigRenderable(src->config()) && NULL != dst->asTexture() &&
dst->origin() == src->origin() && kIndex_8_GrPixelConfig != src->config()) {
if (NULL != wouldNeedTempFBO) {
*wouldNeedTempFBO = NULL == src->asRenderTarget();

View File

@ -261,8 +261,6 @@ private:
GrGLuint texID,
GrGLRenderTarget::Desc* desc);
void fillInConfigRenderableTable();
GrGLContext fGLContext;
// GL program-related state