Consider index8 a compressed config.

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

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/457333004
This commit is contained in:
bsalomon 2014-08-11 14:19:09 -07:00 committed by Commit bot
parent c7103a104f
commit d4cb922ea1
4 changed files with 38 additions and 64 deletions

View File

@ -324,6 +324,7 @@ static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
// representation. // representation.
static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) { static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
switch (config) { switch (config) {
case kIndex_8_GrPixelConfig:
case kETC1_GrPixelConfig: case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig: case kLATC_GrPixelConfig:
case kR11_EAC_GrPixelConfig: case kR11_EAC_GrPixelConfig:
@ -359,9 +360,9 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
} }
static inline size_t GrBytesPerPixel(GrPixelConfig config) { static inline size_t GrBytesPerPixel(GrPixelConfig config) {
SkASSERT(!GrPixelConfigIsCompressed(config));
switch (config) { switch (config) {
case kAlpha_8_GrPixelConfig: case kAlpha_8_GrPixelConfig:
case kIndex_8_GrPixelConfig:
return 1; return 1;
case kRGB_565_GrPixelConfig: case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig: case kRGBA_4444_GrPixelConfig:
@ -377,9 +378,9 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
} }
static inline size_t GrUnpackAlignment(GrPixelConfig config) { static inline size_t GrUnpackAlignment(GrPixelConfig config) {
SkASSERT(!GrPixelConfigIsCompressed(config));
switch (config) { switch (config) {
case kAlpha_8_GrPixelConfig: case kAlpha_8_GrPixelConfig:
case kIndex_8_GrPixelConfig:
return 1; return 1;
case kRGB_565_GrPixelConfig: case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig: case kRGBA_4444_GrPixelConfig:
@ -448,13 +449,6 @@ enum GrTextureFlags {
GR_MAKE_BITFIELD_OPS(GrTextureFlags) GR_MAKE_BITFIELD_OPS(GrTextureFlags)
enum {
/**
* For Index8 pixel config, the colortable must be 256 entries
*/
kGrColorTableSize = 256 * 4 //sizeof(GrColor)
};
/** /**
* Some textures will be stored such that the upper and left edges of the content meet at the * Some textures will be stored such that the upper and left edges of the content meet at the
* the origin (in texture coord space) and for other textures the lower and left edges meet at * the origin (in texture coord space) and for other textures the lower and left edges meet at
@ -684,8 +678,11 @@ enum GrGLBackendState {
static inline size_t GrCompressedFormatDataSize(GrPixelConfig config, static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
int width, int height) { int width, int height) {
SkASSERT(GrPixelConfigIsCompressed(config)); SkASSERT(GrPixelConfigIsCompressed(config));
static const int kGrIndex8TableSize = 256 * 4; // 4 == sizeof(GrColor)
switch (config) { switch (config) {
case kIndex_8_GrPixelConfig:
return width * height + kGrIndex8TableSize;
case kR11_EAC_GrPixelConfig: case kR11_EAC_GrPixelConfig:
case kLATC_GrPixelConfig: case kLATC_GrPixelConfig:
case kETC1_GrPixelConfig: case kETC1_GrPixelConfig:

View File

@ -58,12 +58,12 @@ void GrTextureImpl::dirtyMipMaps(bool mipMapsDirty) {
} }
size_t GrTexture::gpuMemorySize() const { size_t GrTexture::gpuMemorySize() const {
size_t textureSize = (size_t) fDesc.fWidth * size_t textureSize;
fDesc.fHeight *
GrBytesPerPixel(fDesc.fConfig);
if (GrPixelConfigIsCompressed(fDesc.fConfig)) { if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fDesc.fHeight); textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fDesc.fHeight);
} else {
textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fDesc.fConfig);
} }
if (this->impl()->hasMipMaps()) { if (this->impl()->hasMipMaps()) {

View File

@ -65,7 +65,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
ctable->unlockColors(); ctable->unlockColors();
// always skip a full 256 number of entries, even if we memcpy'd fewer // always skip a full 256 number of entries, even if we memcpy'd fewer
dst += kGrColorTableSize; dst += 256 * sizeof(GrColor);
if ((unsigned)bitmap.width() == bitmap.rowBytes()) { if ((unsigned)bitmap.width() == bitmap.rowBytes()) {
memcpy(dst, bitmap.getPixels(), bitmap.getSize()); memcpy(dst, bitmap.getPixels(), bitmap.getSize());
@ -285,8 +285,9 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
// build_compressed_data doesn't do npot->pot expansion // build_compressed_data doesn't do npot->pot expansion
// and paletted textures can't be sub-updated // and paletted textures can't be sub-updated
if (ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->height())) { if (ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->height())) {
size_t imagesize = bitmap->width() * bitmap->height() + kGrColorTableSize; size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig,
SkAutoMalloc storage(imagesize); bitmap->width(), bitmap->height());
SkAutoMalloc storage(imageSize);
build_compressed_data(storage.get(), origBitmap); build_compressed_data(storage.get(), origBitmap);

View File

@ -580,14 +580,12 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
// in case we need a temporary, trimmed copy of the src pixels // in case we need a temporary, trimmed copy of the src pixels
SkAutoSMalloc<128 * 128> tempStorage; SkAutoSMalloc<128 * 128> tempStorage;
// paletted textures cannot be partially updated
// We currently lazily create MIPMAPs when the we see a draw with // We currently lazily create MIPMAPs when the we see a draw with
// GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the
// MIP levels are all created when the texture is created. So for now we don't use // MIP levels are all created when the texture is created. So for now we don't use
// texture storage. // texture storage.
bool useTexStorage = false && bool useTexStorage = false &&
isNewTexture && isNewTexture &&
kIndex_8_GrPixelConfig != desc.fConfig &&
this->glCaps().texStorageSupport(); this->glCaps().texStorageSupport();
if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
@ -618,11 +616,6 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
return false; return false;
} }
if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) {
// paletted textures cannot be updated
return false;
}
/* /*
* check whether to allocate a temporary buffer for flipping y or * check whether to allocate a temporary buffer for flipping y or
* because our srcData has extra bytes past each row. If so, we need * because our srcData has extra bytes past each row. If so, we need
@ -688,27 +681,14 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
internalFormat, internalFormat,
desc.fWidth, desc.fHeight)); desc.fWidth, desc.fHeight));
} else { } else {
if (GR_GL_PALETTE8_RGBA8 == internalFormat) { GL_ALLOC_CALL(this->glInterface(),
GrGLsizei imageSize = desc.fWidth * desc.fHeight + TexImage2D(GR_GL_TEXTURE_2D,
kGrColorTableSize; 0, // level
GL_ALLOC_CALL(this->glInterface(), internalFormat,
CompressedTexImage2D(GR_GL_TEXTURE_2D, desc.fWidth, desc.fHeight,
0, // level 0, // border
internalFormat, externalFormat, externalType,
desc.fWidth, desc.fHeight, data));
0, // border
imageSize,
data));
} else {
GL_ALLOC_CALL(this->glInterface(),
TexImage2D(GR_GL_TEXTURE_2D,
0, // level
internalFormat,
desc.fWidth, desc.fHeight,
0, // border
externalFormat, externalType,
data));
}
} }
GrGLenum error = check_alloc_error(desc, this->glInterface()); GrGLenum error = check_alloc_error(desc, this->glInterface());
if (error != GR_GL_NO_ERROR) { if (error != GR_GL_NO_ERROR) {
@ -788,10 +768,8 @@ bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
return false; return false;
} }
bool succeeded = true;
CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
if (isNewTexture) { if (isNewTexture) {
CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
GL_ALLOC_CALL(this->glInterface(), GL_ALLOC_CALL(this->glInterface(),
CompressedTexImage2D(GR_GL_TEXTURE_2D, CompressedTexImage2D(GR_GL_TEXTURE_2D,
0, // level 0, // level
@ -800,22 +778,25 @@ bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
0, // border 0, // border
dataSize, dataSize,
data)); data));
GrGLenum error = check_alloc_error(desc, this->glInterface());
if (error != GR_GL_NO_ERROR) {
return false;
}
} else { } else {
GL_ALLOC_CALL(this->glInterface(), // Paletted textures can't be updated.
CompressedTexSubImage2D(GR_GL_TEXTURE_2D, if (GR_GL_PALETTE8_RGBA8 == internalFormat) {
0, // level return false;
left, top, }
width, height, GL_CALL(CompressedTexSubImage2D(GR_GL_TEXTURE_2D,
internalFormat, 0, // level
dataSize, left, top,
data)); width, height,
internalFormat,
dataSize,
data));
} }
GrGLenum error = check_alloc_error(desc, this->glInterface()); return true;
if (error != GR_GL_NO_ERROR) {
succeeded = false;
}
return succeeded;
} }
static bool renderbuffer_storage_msaa(GrGLContext& ctx, static bool renderbuffer_storage_msaa(GrGLContext& ctx,
@ -2588,12 +2569,8 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
*externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
break; break;
case kIndex_8_GrPixelConfig: case kIndex_8_GrPixelConfig:
// glCompressedTexImage doesn't take external params
*externalFormat = GR_GL_PALETTE8_RGBA8;
// no sized/unsized internal format distinction here // no sized/unsized internal format distinction here
*internalFormat = GR_GL_PALETTE8_RGBA8; *internalFormat = GR_GL_PALETTE8_RGBA8;
// unused with CompressedTexImage
*externalType = GR_GL_UNSIGNED_BYTE;
break; break;
case kAlpha_8_GrPixelConfig: case kAlpha_8_GrPixelConfig:
if (this->glCaps().textureRedSupport()) { if (this->glCaps().textureRedSupport()) {
@ -2722,7 +2699,6 @@ inline bool can_copy_texsubimage(const GrSurface* dst,
if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) && if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
NULL != dst->asTexture() && NULL != dst->asTexture() &&
dst->origin() == src->origin() && dst->origin() == src->origin() &&
kIndex_8_GrPixelConfig != src->config() &&
!GrPixelConfigIsCompressed(src->config())) { !GrPixelConfigIsCompressed(src->config())) {
if (NULL != wouldNeedTempFBO) { if (NULL != wouldNeedTempFBO) {
*wouldNeedTempFBO = NULL == src->asRenderTarget(); *wouldNeedTempFBO = NULL == src->asRenderTarget();