if (GrPixelConfigIsCompressed(glTex->config())) {
// We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixels()
SkASSERT(config == glTex->config());
- success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), texels,
+ success = this->uploadCompressedTexData(glTex->config(), glTex->width(), glTex->height(),
+ glTex->origin(), glTex->target(), texels,
kWrite_UploadType, left, top, width, height);
} else {
- success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_UploadType,
+ success = this->uploadTexData(glTex->config(), glTex->width(), glTex->height(),
+ glTex->origin(), glTex->target(), kWrite_UploadType,
left, top, width, height, config, texels);
}
mipLevel.fRowBytes = rowBytes;
SkSTArray<1, GrMipLevel> texels;
texels.push_back(mipLevel);
- success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_UploadType,
- left, top, width, height, config, texels);
+ success = this->uploadTexData(glTex->config(), glTex->width(), glTex->height(), glTex->origin(),
+ glTex->target(), kTransfer_UploadType, left, top, width, height,
+ config, texels);
return success;
}
/**
* Creates storage space for the texture and fills it with texels.
*
- * @param desc The surface descriptor for the texture being created.
+ * @param config Pixel config of the texture.
* @param interface The GL interface in use.
* @param caps The capabilities of the GL device.
* @param internalFormat The data format used for the internal storage of the texture. May be sized.
* @param texels The texel data of the texture being created.
* @param baseWidth The width of the texture's base mipmap level
* @param baseHeight The height of the texture's base mipmap level
- * @param succeeded Set to true if allocating and populating the texture completed
- * without error.
*/
-static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc,
+static bool allocate_and_populate_uncompressed_texture(GrPixelConfig config,
const GrGLInterface& interface,
const GrGLCaps& caps,
GrGLenum target,
int baseWidth, int baseHeight) {
CLEAR_ERROR_BEFORE_ALLOC(&interface);
- bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig);
+ bool useTexStorage = caps.isConfigTexSupportEnabled(config);
// We can only use TexStorage if we know we will not later change the storage requirements.
// This means if we may later want to add mipmaps, we cannot use TexStorage.
// Right now, we cannot know if we will later add mipmaps or not.
// The only time we can use TexStorage is when we already have the
// mipmaps or are using a format incompatible with MIP maps.
- useTexStorage &= texels.count() > 1 || GrPixelConfigIsSint(desc.fConfig);
+ useTexStorage &= texels.count() > 1 || GrPixelConfigIsSint(config);
if (useTexStorage) {
// We never resize or change formats of textures.
GL_ALLOC_CALL(&interface,
- TexStorage2D(target,
- SkTMax(texels.count(), 1),
- internalFormatForTexStorage,
- desc.fWidth, desc.fHeight));
+ TexStorage2D(target, SkTMax(texels.count(), 1), internalFormatForTexStorage,
+ baseWidth, baseHeight));
GrGLenum error = CHECK_ALLOC_ERROR(&interface);
if (error != GR_GL_NO_ERROR) {
return false;
continue;
}
int twoToTheMipLevel = 1 << currentMipLevel;
- int currentWidth = SkTMax(1, desc.fWidth / twoToTheMipLevel);
- int currentHeight = SkTMax(1, desc.fHeight / twoToTheMipLevel);
+ int currentWidth = SkTMax(1, baseWidth / twoToTheMipLevel);
+ int currentHeight = SkTMax(1, baseHeight / twoToTheMipLevel);
GR_GL_CALL(&interface,
TexSubImage2D(target,
/**
* Creates storage space for the texture and fills it with texels.
*
+ * @param config Compressed pixel config of the texture.
* @param desc The surface descriptor for the texture being created.
* @param interface The GL interface in use.
* @param caps The capabilities of the GL device.
* @param internalFormat The data format used for the internal storage of the texture.
* @param texels The texel data of the texture being created.
*/
-static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc,
+static bool allocate_and_populate_compressed_texture(GrPixelConfig config,
const GrGLInterface& interface,
const GrGLCaps& caps,
GrGLenum target, GrGLenum internalFormat,
int baseWidth, int baseHeight) {
CLEAR_ERROR_BEFORE_ALLOC(&interface);
- bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig);
+ bool useTexStorage = caps.isConfigTexSupportEnabled(config);
// We can only use TexStorage if we know we will not later change the storage requirements.
// This means if we may later want to add mipmaps, we cannot use TexStorage.
// Right now, we cannot know if we will later add mipmaps or not.
// Make sure that the width and height that we pass to OpenGL
// is a multiple of the block size.
- size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, currentWidth,
- currentHeight);
+ size_t dataSize = GrCompressedFormatDataSize(config, currentWidth, currentHeight);
GR_GL_CALL(&interface, CompressedTexSubImage2D(target,
currentMipLevel,
0, // left
// Make sure that the width and height that we pass to OpenGL
// is a multiple of the block size.
- size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, baseWidth, baseHeight);
+ size_t dataSize = GrCompressedFormatDataSize(config, baseWidth, baseHeight);
GL_ALLOC_CALL(&interface,
CompressedTexImage2D(target,
}
}
-bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
- GrGLenum target,
- UploadType uploadType,
- int left, int top, int width, int height,
- GrPixelConfig dataConfig,
+bool GrGLGpu::uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
+ GrSurfaceOrigin texOrigin, GrGLenum target, UploadType uploadType,
+ int left, int top, int width, int height, GrPixelConfig dataConfig,
const SkTArray<GrMipLevel>& texels) {
// If we're uploading compressed data then we should be using uploadCompressedTexData
SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
- SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+ SkASSERT(this->caps()->isConfigTexturable(texConfig));
// texels is const.
// But we may need to flip the texture vertically to prepare it.
currentWidth > SK_MaxS32) {
return false;
}
- if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
- ¤tWidth,
- ¤tHeight,
- &texelsShallowCopy[currentMipLevel].fPixels,
- &texelsShallowCopy[currentMipLevel].fRowBytes)) {
+ if (!GrSurfacePriv::AdjustWritePixelParams(texWidth, texHeight, bpp, &left, &top,
+ ¤tWidth, ¤tHeight,
+ &texelsShallowCopy[currentMipLevel].fPixels,
+ &texelsShallowCopy[currentMipLevel].fRowBytes)) {
return false;
}
if (currentWidth < 0 || currentHeight < 0) {
// External format and type come from the upload data.
GrGLenum externalFormat;
GrGLenum externalType;
- if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFormat,
- &externalFormat, &externalType)) {
+ if (!this->glCaps().getTexImageFormats(texConfig, dataConfig, &internalFormat, &externalFormat,
+ &externalType)) {
return false;
}
// TexStorage requires a sized format, and internalFormat may or may not be
- GrGLenum internalFormatForTexStorage = this->glCaps().configSizedInternalFormat(desc.fConfig);
+ GrGLenum internalFormatForTexStorage = this->glCaps().configSizedInternalFormat(texConfig);
/*
* Check whether to allocate a temporary buffer for flipping y or
bool swFlipY = false;
bool glFlipY = false;
- if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty()) {
+ if (kBottomLeft_GrSurfaceOrigin == texOrigin && !texelsShallowCopy.empty()) {
if (caps.unpackFlipYSupport()) {
glFlipY = true;
} else {
if (glFlipY) {
GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
- GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT,
- config_alignment(desc.fConfig)));
+ GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(texConfig)));
}
bool succeeded = true;
- if (kNewTexture_UploadType == uploadType &&
- 0 == left && 0 == top &&
- desc.fWidth == width && desc.fHeight == height) {
- succeeded = allocate_and_populate_uncompressed_texture(desc, *interface, caps, target,
- internalFormat,
- internalFormatForTexStorage,
- externalFormat, externalType,
- texelsShallowCopy, width, height);
+ if (kNewTexture_UploadType == uploadType) {
+ if (0 == left && 0 == top && texWidth == width && texHeight == height) {
+ allocate_and_populate_uncompressed_texture(texConfig, *interface, caps, target,
+ internalFormat, internalFormatForTexStorage,
+ externalFormat, externalType,
+ texelsShallowCopy, width, height);
+ } else {
+ succeeded = false;
+ }
} else {
if (swFlipY || glFlipY) {
- top = desc.fHeight - (top + height);
+ top = texHeight - (top + height);
}
for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count();
currentMipLevel++) {
// create a CompressedTexData struct that takes a desc/ptr and figures out
// the proper upload semantics. Then users can construct this function how they
// see fit if they want to go against the "standard" way to do it.
-bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc,
- GrGLenum target,
- const SkTArray<GrMipLevel>& texels,
- UploadType uploadType,
+bool GrGLGpu::uploadCompressedTexData(GrPixelConfig config, int texWidth, int texHeight,
+ GrSurfaceOrigin texOrigin, GrGLenum target,
+ const SkTArray<GrMipLevel>& texels, UploadType uploadType,
int left, int top, int width, int height) {
- SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+ SkASSERT(this->caps()->isConfigTexturable(config));
// No support for software flip y, yet...
- SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin);
+ SkASSERT(kBottomLeft_GrSurfaceOrigin != texOrigin);
const GrGLInterface* interface = this->glInterface();
const GrGLCaps& caps = this->glCaps();
if (-1 == width) {
- width = desc.fWidth;
+ width = texWidth;
}
#ifdef SK_DEBUG
else {
- SkASSERT(width <= desc.fWidth);
+ SkASSERT(width <= texWidth);
}
#endif
if (-1 == height) {
- height = desc.fHeight;
+ height = texHeight;
}
#ifdef SK_DEBUG
else {
- SkASSERT(height <= desc.fHeight);
+ SkASSERT(height <= texHeight);
}
#endif
// We only need the internal format for compressed 2D textures.
GrGLenum internalFormat;
- if (!caps.getCompressedTexImageFormats(desc.fConfig, &internalFormat)) {
+ if (!caps.getCompressedTexImageFormats(config, &internalFormat)) {
return false;
}
if (kNewTexture_UploadType == uploadType) {
- return allocate_and_populate_compressed_texture(desc, *interface, caps, target,
+ return allocate_and_populate_compressed_texture(config, *interface, caps, target,
internalFormat, texels, width, height);
} else {
for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
// Make sure that the width and height that we pass to OpenGL
// is a multiple of the block size.
- size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, currentWidth,
- currentHeight);
+ size_t dataSize = GrCompressedFormatDataSize(config, currentWidth, currentHeight);
GL_CALL(CompressedTexSubImage2D(target,
currentMipLevel,
left, top,
GrGLTexture::TexParams initialTexParams;
set_initial_texture_params(this->glInterface(), idDesc.fInfo, &initialTexParams);
- if (!this->uploadCompressedTexData(desc, idDesc.fInfo.fTarget, texels)) {
+ if (!this->uploadCompressedTexData(desc.fConfig, desc.fWidth, desc.fHeight, desc.fOrigin,
+ idDesc.fInfo.fTarget, texels)) {
GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
return return_null_texture();
}
if (info) {
set_initial_texture_params(this->glInterface(), *info, initialTexParams);
}
- if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0,
- desc.fWidth, desc.fHeight,
- desc.fConfig, texels)) {
+ if (!this->uploadTexData(desc.fConfig, desc.fWidth, desc.fHeight, desc.fOrigin, info->fTarget,
+ kNewTexture_UploadType, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ texels)) {
GL_CALL(DeleteTextures(1, &(info->fID)));
return false;
}
}
GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
- int width,
- int height) {
+ int width, int height) {
SkASSERT(width >= rt->width());
SkASSERT(height >= rt->height());
size_t bpp = GrBytesPerPixel(dataConfig);
- const GrSurfaceDesc& desc = tex->desc();
-
- if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
+ if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
&width, &height, &data, &rowBytes)) {
return false;
}
&subres,
&layout));
- int texTop = kBottomLeft_GrSurfaceOrigin == desc.fOrigin ? tex->height() - top - height : top;
+ int texTop = kBottomLeft_GrSurfaceOrigin == tex->origin() ? tex->height() - top - height : top;
const GrVkAlloc& alloc = tex->alloc();
VkDeviceSize offset = alloc.fOffset + texTop*layout.rowPitch + left*bpp;
VkDeviceSize size = height*layout.rowPitch;
return false;
}
- if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
+ if (kBottomLeft_GrSurfaceOrigin == tex->origin()) {
// copy into buffer by rows
const char* srcRow = reinterpret_cast<const char*>(data);
char* dstRow = reinterpret_cast<char*>(mapPtr)+(height - 1)*layout.rowPitch;
return false;
}
- const GrSurfaceDesc& desc = tex->desc();
- SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+ SkASSERT(this->caps()->isConfigTexturable(tex->config()));
size_t bpp = GrBytesPerPixel(dataConfig);
// texels is const.
}
// Determine whether we need to flip when we copy into the buffer
- bool flipY = (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty());
+ bool flipY = (kBottomLeft_GrSurfaceOrigin == tex->origin() && !texelsShallowCopy.empty());
// adjust any params (left, top, currentWidth, currentHeight
// find the combined size of all the mip levels and the relative offset of
// each into the collective buffer
// Do the first level separately because we may need to adjust width and height
// (for the non-mipped case).
- if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
- &width,
- &height,
- &texelsShallowCopy[0].fPixels,
+ if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
+ &width, &height, &texelsShallowCopy[0].fPixels,
&texelsShallowCopy[0].fRowBytes)) {
return false;
}
for (int currentMipLevel = 1; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) {
currentWidth = SkTMax(1, currentWidth/2);
currentHeight = SkTMax(1, currentHeight/2);
- if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
- ¤tWidth,
- ¤tHeight,
+ if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
+ ¤tWidth, ¤tHeight,
&texelsShallowCopy[currentMipLevel].fPixels,
&texelsShallowCopy[currentMipLevel].fRowBytes)) {
return false;