// representation.
static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
switch (config) {
+ case kIndex_8_GrPixelConfig:
case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig:
case kR11_EAC_GrPixelConfig:
}
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:
}
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:
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
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:
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());
// 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);
// 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()) {
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
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) {
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
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,
*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()) {
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();