Move the LATC and ETC1 enum values to GrPixelConfig. I also tried to put in checks in a few places to make sure that we weren't using these pixel configurations in places that we shouldn't be.

LATC is a DXT-esque alpha compression format that goes by a few other names (RGTC, 3DC). It might be useful to investigate using it to compress the alpha masks that we get from software rasterization. This patch set adds enums for that and recognition whether or not the device can support it.

R=bsalomon@google.com, robertphillips@google.com

Author: krajcevski@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14991 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-30 13:55:58 +00:00
parent 687a26defa
commit 6e7ddaae0a
11 changed files with 235 additions and 127 deletions

View File

@ -132,6 +132,8 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
kRGBA_GrColorComponentFlags, // kRGBA_4444_GrPixelConfig
kRGBA_GrColorComponentFlags, // kRGBA_8888_GrPixelConfig
kRGBA_GrColorComponentFlags, // kBGRA_8888_GrPixelConfig
kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig
kA_GrColorComponentFlag, // kLATC_GrPixelConfig
};
return kFlags[config];
@ -142,6 +144,8 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
}

View File

@ -281,8 +281,16 @@ enum GrPixelConfig {
* Premultiplied. Byte order is b,g,r,a.
*/
kBGRA_8888_GrPixelConfig,
/**
* ETC1 Compressed Data
*/
kETC1_GrPixelConfig,
/**
* LATC/RGTC/3Dc/BC4 Compressed Data
*/
kLATC_GrPixelConfig,
kLast_GrPixelConfig = kBGRA_8888_GrPixelConfig
kLast_GrPixelConfig = kLATC_GrPixelConfig
};
static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
@ -298,6 +306,18 @@ static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
#error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
#endif
// Returns true if the pixel config is a GPU-specific compressed format
// representation.
static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
switch (config) {
case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig:
return true;
default:
return false;
}
}
// Returns true if the pixel config is 32 bits per pixel
static inline bool GrPixelConfigIs8888(GrPixelConfig config) {
switch (config) {
@ -340,6 +360,7 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
switch (config) {
case kETC1_GrPixelConfig:
case kRGB_565_GrPixelConfig:
return true;
default:
@ -619,20 +640,6 @@ enum GrGLBackendState {
kALL_GrGLBackendState = 0xffff
};
/**
* The compressed texture formats that may be supported by the renderer.
* Make sure to check for the required capabilities using
* GrDrawTargetCaps::compressedTextureSupport
*/
enum GrCompressedFormat {
kETC1_GrCompressedFormat,
kETC2_GrCompressedFormat,
kDXT1_GrCompressedFormat,
kLast_GrCompressedFormat = kDXT1_GrCompressedFormat
};
static const int kGrCompressedFormatCount = kLast_GrCompressedFormat + 1;
/**
* This value translates to reseting all the context state for any backend.
*/

View File

@ -163,6 +163,9 @@ GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config,
SkASSERT(plotWidth * fNumPlotsX == textureWidth);
SkASSERT(plotHeight * fNumPlotsY == textureHeight);
// We currently do not support compressed atlases...
SkASSERT(!GrPixelConfigIsCompressed(config));
// set up allocated plots
size_t bpp = GrBytesPerPixel(fPixelConfig);
fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY));

View File

@ -360,6 +360,10 @@ GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
// no longer need to clamp at min RT size.
rtDesc.fWidth = GrNextPow2(desc.fWidth);
rtDesc.fHeight = GrNextPow2(desc.fHeight);
// We shouldn't be resizing a compressed texture.
SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
size_t bpp = GrBytesPerPixel(desc.fConfig);
SkAutoSMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight);
stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight,
@ -607,7 +611,7 @@ GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe
bool GrContext::supportsIndex8PixelConfig(const GrTextureParams* params,
int width, int height) const {
const GrDrawTargetCaps* caps = fGpu->caps();
if (!caps->eightBitPaletteSupport()) {
if (!caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
return false;
}

View File

@ -1007,7 +1007,6 @@ void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* d
///////////////////////////////////////////////////////////////////////////////
void GrDrawTargetCaps::reset() {
f8BitPaletteSupport = false;
fMipMapSupport = false;
fNPOTTextureTileSupport = false;
fTwoSidedStencilSupport = false;
@ -1029,11 +1028,10 @@ void GrDrawTargetCaps::reset() {
fMaxSampleCount = 0;
memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
memset(fCompressedFormatSupport, 0, sizeof(fCompressedFormatSupport));
memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
}
GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
f8BitPaletteSupport = other.f8BitPaletteSupport;
fMipMapSupport = other.fMipMapSupport;
fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
@ -1055,8 +1053,7 @@ GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
fMaxSampleCount = other.fMaxSampleCount;
memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
memcpy(fCompressedFormatSupport, other.fCompressedFormatSupport,
sizeof(fCompressedFormatSupport));
memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
return *this;
}
@ -1084,7 +1081,6 @@ static SkString map_flags_to_string(uint32_t flags) {
SkString GrDrawTargetCaps::dump() const {
SkString r;
static const char* gNY[] = {"NO", "YES"};
r.appendf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]);
r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
@ -1112,6 +1108,8 @@ SkString GrDrawTargetCaps::dump() const {
"RGBA444", // kRGBA_4444_GrPixelConfig,
"RGBA8888", // kRGBA_8888_GrPixelConfig,
"BGRA8888", // kBGRA_8888_GrPixelConfig,
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
};
GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
@ -1120,33 +1118,26 @@ SkString GrDrawTargetCaps::dump() const {
GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
if (i != kUnknown_GrPixelConfig) {
r.appendf("%s is renderable: %s, with MSAA: %s\n",
kConfigNames[i],
gNY[fConfigRenderSupport[i][0]],
gNY[fConfigRenderSupport[i][1]]);
}
for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
r.appendf("%s is renderable: %s, with MSAA: %s\n",
kConfigNames[i],
gNY[fConfigRenderSupport[i][0]],
gNY[fConfigRenderSupport[i][1]]);
}
static const char* kCompressedFormatNames[] = {
"ETC1", // kETC1_GrCompressedFormat
"ETC2", // kETC2_GrCompressedFormat,
"DXT1", // kDXT1_GrCompressedFormat,
};
GR_STATIC_ASSERT(0 == kETC1_GrCompressedFormat);
GR_STATIC_ASSERT(1 == kETC2_GrCompressedFormat);
GR_STATIC_ASSERT(2 == kDXT1_GrCompressedFormat);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCompressedFormatNames) == kGrCompressedFormatCount);
SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
for (size_t i = 0; i < SK_ARRAY_COUNT(kCompressedFormatNames); ++i) {
r.appendf("%s Compressed Texture Support: %s\n",
kCompressedFormatNames[i],
gNY[fCompressedFormatSupport[i]]);
for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
r.appendf("%s is uploadable to a texture: %s\n",
kConfigNames[i],
gNY[fConfigTextureSupport[i]]);
}
return r;

View File

@ -26,7 +26,6 @@ public:
virtual void reset();
virtual SkString dump() const;
bool eightBitPaletteSupport() const { return f8BitPaletteSupport; }
bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
/** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
only for POT textures) */
@ -72,13 +71,12 @@ public:
return fConfigRenderSupport[config][withMSAA];
}
bool compressedTextureSupport(GrCompressedFormat format) const {
SkASSERT(kGrCompressedFormatCount > format);
return fCompressedFormatSupport[format];
bool isConfigTexturable(GrPixelConfig config) const {
SkASSERT(kGrPixelConfigCnt > config);
return fConfigTextureSupport[config];
}
protected:
bool f8BitPaletteSupport : 1;
bool fNPOTTextureTileSupport : 1;
bool fMipMapSupport : 1;
bool fTwoSidedStencilSupport : 1;
@ -101,8 +99,7 @@ protected:
// The first entry for each config is without msaa and the second is with.
bool fConfigRenderSupport[kGrPixelConfigCnt][2];
bool fCompressedFormatSupport[kGrCompressedFormatCount];
bool fConfigTextureSupport[kGrPixelConfigCnt];
typedef SkRefCnt INHERITED;
};

View File

@ -62,6 +62,25 @@ size_t GrTexture::gpuMemorySize() const {
size_t textureSize = (size_t) fDesc.fWidth *
fDesc.fHeight *
GrBytesPerPixel(fDesc.fConfig);
if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
// Figure out the width and height corresponding to the data...
// Both of the available formats (ETC1 and LATC) have 4x4
// blocks that compress down to 8 bytes.
switch(fDesc.fConfig) {
case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig:
SkASSERT((fDesc.fWidth & 3) == 0);
SkASSERT((fDesc.fHeight & 3) == 0);
textureSize = (fDesc.fWidth >> 2) * (fDesc.fHeight >> 2) * 8;
break;
default:
SkFAIL("Unknown compressed config");
}
}
if (this->impl()->hasMipMaps()) {
// We don't have to worry about the mipmaps being a different size than
// we'd expect because we never change fDesc.fWidth/fHeight.

View File

@ -30,7 +30,6 @@ void GrGLCaps::reset() {
fMaxFragmentTextureUnits = 0;
fMaxFixedFunctionTextureCoords = 0;
fRGBA8RenderbufferSupport = false;
fBGRAFormatSupport = false;
fBGRAIsInternalFormat = false;
fTextureSwizzleSupport = false;
fUnpackRowLengthSupport = false;
@ -68,7 +67,6 @@ GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
fInvalidateFBType = caps.fInvalidateFBType;
fMapBufferType = caps.fMapBufferType;
fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
fBGRAFormatSupport = caps.fBGRAFormatSupport;
fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
@ -134,20 +132,6 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
ctxInfo.hasExtension("GL_ARM_rgba8");
}
if (kGL_GrGLStandard == standard) {
fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
ctxInfo.hasExtension("GL_EXT_bgra");
} else {
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
fBGRAFormatSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
fBGRAFormatSupport = true;
fBGRAIsInternalFormat = true;
}
SkASSERT(fBGRAFormatSupport ||
kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
}
if (kGL_GrGLStandard == standard) {
fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
ctxInfo.hasExtension("GL_ARB_texture_swizzle");
@ -262,19 +246,6 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
/**************************************************************************
* GrDrawTargetCaps fields
**************************************************************************/
GrGLint numFormats;
GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
if (numFormats) {
SkAutoSTMalloc<10, GrGLint> formats(numFormats);
GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < numFormats; ++i) {
if (formats[i] == GR_GL_PALETTE8_RGBA8) {
f8BitPaletteSupport = true;
break;
}
}
}
if (kGL_GrGLStandard == standard) {
// we could also look for GL_ATI_separate_stencil extension or
// GL_EXT_stencil_two_side but they use different function signatures
@ -367,10 +338,9 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
}
this->initConfigTexturableTable(ctxInfo, gli);
this->initConfigRenderableTable(ctxInfo);
this->initCompressedTextureSupport(ctxInfo);
return true;
}
@ -404,12 +374,14 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
// Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
// below already account for this).
GrGLStandard standard = ctxInfo.standard();
enum {
kNo_MSAA = 0,
kYes_MSAA = 1,
};
if (kGL_GrGLStandard == ctxInfo.standard()) {
if (kGL_GrGLStandard == standard) {
// 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) ||
@ -423,7 +395,7 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
}
if (kGL_GrGLStandard != ctxInfo.standard()) {
if (kGL_GrGLStandard != standard) {
// only available in ES
fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
@ -438,7 +410,7 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
}
if (this->fBGRAFormatSupport) {
if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
// The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
// configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
@ -460,36 +432,103 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
}
}
void GrGLCaps::initCompressedTextureSupport(const GrGLContextInfo &ctxInfo) {
void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
GrGLVersion version = ctxInfo.version();
// Base texture support
fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
// Check for 8-bit palette..
GrGLint numFormats;
GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
if (numFormats) {
SkAutoSTMalloc<10, GrGLint> formats(numFormats);
GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < numFormats; ++i) {
if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
break;
}
}
}
// Check for BGRA
if (kGL_GrGLStandard == standard) {
fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
} else {
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
} else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
fBGRAIsInternalFormat = true;
}
SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
}
// Compressed texture support
// glCompressedTexImage2D is available on all OpenGL ES devices...
// however, it is only available on standard OpenGL after version 1.3
if (kGL_GrGLStandard == standard && version < GR_GL_VER(1, 3)) {
return;
}
bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
// Check for ETC1
bool hasETC1 = false;
// First check version for support
if (kGL_GrGLStandard == standard) {
hasETC1 =
version >= GR_GL_VER(4, 3) ||
ctxInfo.hasExtension("GL_ARB_ES3_compatibility");
hasETC1 = hasCompressTex2D &&
(version >= GR_GL_VER(4, 3) ||
ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
} else {
hasETC1 =
version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
// ETC2 is a superset of ETC1, so we can just check for that, too.
(ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"));
hasETC1 = hasCompressTex2D &&
(version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
// ETC2 is a superset of ETC1, so we can just check for that, too.
(ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
}
fCompressedFormatSupport[kETC1_GrCompressedFormat] = hasETC1;
fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
fCompressedFormatSupport[kETC2_GrCompressedFormat] = false;
fCompressedFormatSupport[kDXT1_GrCompressedFormat] = false;
// Check for LATC under its various forms
LATCAlias alias = kLATC_LATCAlias;
bool hasLATC = hasCompressTex2D &&
(ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
// Check for RGTC
if (!hasLATC) {
// If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
if (kGL_GrGLStandard == standard) {
hasLATC = version >= GR_GL_VER(3, 0);
}
if (!hasLATC) {
hasLATC =
ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
}
if (hasLATC) {
alias = kRGTC_LATCAlias;
}
}
// Check for 3DC
if (!hasLATC) {
hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
if (hasLATC) {
alias = k3DC_LATCAlias;
}
}
fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
fLATCAlias = alias;
}
bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
@ -728,7 +767,6 @@ SkString GrGLCaps::dump() const {
}
r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));

View File

@ -205,9 +205,6 @@ public:
/// ES requires an extension to support RGBA8 in RenderBufferStorage
bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
/// Is GL_BGRA supported
bool bgraFormatSupport() const { return fBGRAFormatSupport; }
/**
* Depending on the ES extensions present the BGRA external format may
* correspond either a BGRA or RGBA internalFormat. On desktop GL it is
@ -270,6 +267,19 @@ public:
*/
virtual SkString dump() const SK_OVERRIDE;
/**
* LATC can appear under one of three possible names. In order to know
* which GL internal format to use, we need to keep track of which name
* we found LATC under. The default is LATC.
*/
enum LATCAlias {
kLATC_LATCAlias,
kRGTC_LATCAlias,
k3DC_LATCAlias
};
LATCAlias latcAlias() const { return fLATCAlias; }
private:
/**
* Maintains a bit per GrPixelConfig. It is used to avoid redundantly
@ -312,8 +322,7 @@ private:
void initStencilFormats(const GrGLContextInfo&);
// This must be called after initFSAASupport().
void initConfigRenderableTable(const GrGLContextInfo&);
void initCompressedTextureSupport(const GrGLContextInfo &);
void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
// tracks configs that have been verified to pass the FBO completeness when
// used as a color attachment
@ -334,9 +343,9 @@ private:
FBFetchType fFBFetchType;
InvalidateFBType fInvalidateFBType;
MapBufferType fMapBufferType;
LATCAlias fLATCAlias;
bool fRGBA8RenderbufferSupport : 1;
bool fBGRAFormatSupport : 1;
bool fBGRAIsInternalFormat : 1;
bool fTextureSwizzleSupport : 1;
bool fUnpackRowLengthSupport : 1;

View File

@ -238,6 +238,19 @@
#define GR_GL_COMPRESSED_RGBA8_ETC2 0x9278
#define GR_GL_COMPRESSED_SRGB8_ALPHA8_ETC2 0x9279
#define GR_GL_COMPRESSED_LUMINANCE_LATC1 0x8C70
#define GR_GL_COMPRESSED_SIGNED_LUMINANCE_LATC1 0x8C71
#define GR_GL_COMPRESSED_LUMINANCE_ALPHA_LATC2 0x8C72
#define GR_GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2 0x8C73
#define GR_GL_COMPRESSED_RED_RGTC1 0x8DBB
#define GR_GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC
#define GR_GL_COMPRESSED_RED_GREEN_RGTC2 0x8DBD
#define GR_GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2 0x8DBE
#define GR_GL_COMPRESSED_3DC_X 0x87F9
#define GR_GL_COMPRESSED_3DC_XY 0x87FA
#define GR_GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
#define GR_GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D
#define GR_GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E

View File

@ -200,7 +200,8 @@ GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig,
}
bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const {
if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config()) {
if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config() ||
GrPixelConfigIsCompressed(srcConfig) || GrPixelConfigIsCompressed(texture->config())) {
return false;
}
if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard()) {
@ -209,7 +210,7 @@ bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC
// texture. It depends upon which extension added BGRA. The Apple extension allows it
// (BGRA's internal format is RGBA) while the EXT extension does not (BGRA is its own
// internal format).
if (this->glCaps().bgraFormatSupport() &&
if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) &&
!this->glCaps().bgraIsInternalFormat() &&
kBGRA_8888_GrPixelConfig == srcConfig &&
kRGBA_8888_GrPixelConfig == texture->config()) {
@ -531,6 +532,9 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
size_t rowBytes) {
SkASSERT(NULL != data || isNewTexture);
// If we're uploading compressed data then we should be using uploadCompressedTexData
SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
size_t bpp = GrBytesPerPixel(dataConfig);
if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top,
&width, &height, &data, &rowBytes)) {
@ -548,7 +552,7 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
// texture storage.
bool useTexStorage = false &&
isNewTexture &&
desc.fConfig != kIndex_8_GrPixelConfig &&
kIndex_8_GrPixelConfig != desc.fConfig &&
this->glCaps().texStorageSupport();
if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
@ -1432,8 +1436,13 @@ bool GrGpuGL::onReadPixels(GrRenderTarget* target,
GrPixelConfig config,
void* buffer,
size_t rowBytes) {
GrGLenum format;
GrGLenum type;
// We cannot read pixels into a compressed buffer
if (GrPixelConfigIsCompressed(config)) {
return false;
}
GrGLenum format = 0;
GrGLenum type = 0;
bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin();
if (!this->configToGLFormats(config, false, NULL, &format, &type)) {
return false;
@ -2160,8 +2169,8 @@ void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
newTexParams.fMinFilter = glMinFilterModes[filterMode];
newTexParams.fMagFilter = glMagFilterModes[filterMode];
if (GrTextureParams::kMipMap_FilterMode == filterMode && texture->mipMapsAreDirty()) {
// GL_CALL(Hint(GR_GL_GENERATE_MIPMAP_HINT,GR_GL_NICEST));
if (GrTextureParams::kMipMap_FilterMode == filterMode &&
texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config())) {
GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D));
texture->dirtyMipMaps(false);
}
@ -2395,6 +2404,10 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
externalType = &dontCare;
}
if(!this->glCaps().isConfigTexturable(config)) {
return false;
}
switch (config) {
case kRGBA_8888_GrPixelConfig:
*internalFormat = GR_GL_RGBA;
@ -2407,9 +2420,6 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
*externalType = GR_GL_UNSIGNED_BYTE;
break;
case kBGRA_8888_GrPixelConfig:
if (!this->glCaps().bgraFormatSupport()) {
return false;
}
if (this->glCaps().bgraIsInternalFormat()) {
if (getSizedInternalFormat) {
*internalFormat = GR_GL_BGRA8;
@ -2451,16 +2461,12 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
*externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
break;
case kIndex_8_GrPixelConfig:
if (this->caps()->eightBitPaletteSupport()) {
// glCompressedTexImage doesn't take external params
*externalFormat = GR_GL_PALETTE8_RGBA8;
// no sized/unsized internal format distinction here
*internalFormat = GR_GL_PALETTE8_RGBA8;
// unused with CompressedTexImage
*externalType = GR_GL_UNSIGNED_BYTE;
} else {
return false;
}
// glCompressedTexImage doesn't take external params
*externalFormat = GR_GL_PALETTE8_RGBA8;
// no sized/unsized internal format distinction here
*internalFormat = GR_GL_PALETTE8_RGBA8;
// unused with CompressedTexImage
*externalType = GR_GL_UNSIGNED_BYTE;
break;
case kAlpha_8_GrPixelConfig:
if (this->glCaps().textureRedSupport()) {
@ -2483,6 +2489,22 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
*externalType = GR_GL_UNSIGNED_BYTE;
}
break;
case kETC1_GrPixelConfig:
*internalFormat = GR_GL_COMPRESSED_RGB8_ETC1;
break;
case kLATC_GrPixelConfig:
switch(this->glCaps().latcAlias()) {
case GrGLCaps::kLATC_LATCAlias:
*internalFormat = GR_GL_COMPRESSED_LUMINANCE_LATC1;
break;
case GrGLCaps::kRGTC_LATCAlias:
*internalFormat = GR_GL_COMPRESSED_RED_RGTC1;
break;
case GrGLCaps::k3DC_LATCAlias:
*internalFormat = GR_GL_COMPRESSED_3DC_X;
break;
}
break;
default:
return false;
}
@ -2559,7 +2581,8 @@ inline bool can_copy_texsubimage(const GrSurface* dst,
if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
NULL != dst->asTexture() &&
dst->origin() == src->origin() &&
kIndex_8_GrPixelConfig != src->config()) {
kIndex_8_GrPixelConfig != src->config() &&
!GrPixelConfigIsCompressed(src->config())) {
if (NULL != wouldNeedTempFBO) {
*wouldNeedTempFBO = NULL == src->asRenderTarget();
}