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.
static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
switch (config) {
case kIndex_8_GrPixelConfig:
case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig:
case kR11_EAC_GrPixelConfig:
@ -359,9 +360,9 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
}
static inline size_t GrBytesPerPixel(GrPixelConfig config) {
SkASSERT(!GrPixelConfigIsCompressed(config));
switch (config) {
case kAlpha_8_GrPixelConfig:
case kIndex_8_GrPixelConfig:
return 1;
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@ -377,9 +378,9 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
}
static inline size_t GrUnpackAlignment(GrPixelConfig config) {
SkASSERT(!GrPixelConfigIsCompressed(config));
switch (config) {
case kAlpha_8_GrPixelConfig:
case kIndex_8_GrPixelConfig:
return 1;
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@ -448,13 +449,6 @@ enum 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
* 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,
int width, int height) {
SkASSERT(GrPixelConfigIsCompressed(config));
static const int kGrIndex8TableSize = 256 * 4; // 4 == sizeof(GrColor)
switch (config) {
case kIndex_8_GrPixelConfig:
return width * height + kGrIndex8TableSize;
case kR11_EAC_GrPixelConfig:
case kLATC_GrPixelConfig:
case kETC1_GrPixelConfig:

View File

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

View File

@ -65,7 +65,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
ctable->unlockColors();
// 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()) {
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
// and paletted textures can't be sub-updated
if (ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->height())) {
size_t imagesize = bitmap->width() * bitmap->height() + kGrColorTableSize;
SkAutoMalloc storage(imagesize);
size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig,
bitmap->width(), bitmap->height());
SkAutoMalloc storage(imageSize);
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
SkAutoSMalloc<128 * 128> tempStorage;
// paletted textures cannot be partially updated
// We currently lazily create MIPMAPs when the we see a draw with
// 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
// texture storage.
bool useTexStorage = false &&
isNewTexture &&
kIndex_8_GrPixelConfig != desc.fConfig &&
this->glCaps().texStorageSupport();
if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
@ -618,11 +616,6 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
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
* 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,
desc.fWidth, desc.fHeight));
} else {
if (GR_GL_PALETTE8_RGBA8 == internalFormat) {
GrGLsizei imageSize = desc.fWidth * desc.fHeight +
kGrColorTableSize;
GL_ALLOC_CALL(this->glInterface(),
CompressedTexImage2D(GR_GL_TEXTURE_2D,
0, // level
internalFormat,
desc.fWidth, desc.fHeight,
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));
}
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());
if (error != GR_GL_NO_ERROR) {
@ -788,10 +768,8 @@ bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
return false;
}
bool succeeded = true;
CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
if (isNewTexture) {
CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
GL_ALLOC_CALL(this->glInterface(),
CompressedTexImage2D(GR_GL_TEXTURE_2D,
0, // level
@ -800,22 +778,25 @@ bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
0, // border
dataSize,
data));
GrGLenum error = check_alloc_error(desc, this->glInterface());
if (error != GR_GL_NO_ERROR) {
return false;
}
} else {
GL_ALLOC_CALL(this->glInterface(),
CompressedTexSubImage2D(GR_GL_TEXTURE_2D,
0, // level
left, top,
width, height,
internalFormat,
dataSize,
data));
// Paletted textures can't be updated.
if (GR_GL_PALETTE8_RGBA8 == internalFormat) {
return false;
}
GL_CALL(CompressedTexSubImage2D(GR_GL_TEXTURE_2D,
0, // level
left, top,
width, height,
internalFormat,
dataSize,
data));
}
GrGLenum error = check_alloc_error(desc, this->glInterface());
if (error != GR_GL_NO_ERROR) {
succeeded = false;
}
return succeeded;
return true;
}
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;
break;
case kIndex_8_GrPixelConfig:
// 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()) {
@ -2722,7 +2699,6 @@ 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() &&
!GrPixelConfigIsCompressed(src->config())) {
if (NULL != wouldNeedTempFBO) {
*wouldNeedTempFBO = NULL == src->asRenderTarget();