* @param isRT Indicates if the texture can be a render target.
*/
static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDesc& desc,
- bool* isRT, const SkTArray<GrMipLevel>& texels) {
+ bool* isRT) {
if (!caps.isConfigTexturable(desc.fConfig)) {
return false;
}
return false;
}
}
-
- for (int i = 0; i < texels.count(); ++i) {
- if (!texels[i].fPixels) {
- return false;
- }
- }
return true;
}
const GrCaps* caps = this->caps();
bool isRT = false;
- bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT, texels);
+ bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
if (!textureCreationParamsValid) {
return nullptr;
}
return tex;
}
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+ const void* srcData, size_t rowBytes) {
+ GrMipLevel level;
+ level.fPixels = srcData;
+ level.fRowBytes = rowBytes;
+ SkSTArray<1, GrMipLevel> levels;
+ levels.push_back(level);
+
+ return this->createTexture(desc, budgeted, levels);
+}
+
GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
this->handleDirtyContext();
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
if (!surface) {
return false;
}
+ bool validMipDataFound = false;
for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
- if (!texels[currentMipLevel].fPixels ) {
- return false;
+ if (texels[currentMipLevel].fPixels != nullptr) {
+ validMipDataFound = true;
+ break;
}
}
+ if (!validMipDataFound) {
+ return false;
+ }
this->handleDirtyContext();
if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
if (this->isAbandoned()) {
return nullptr;
}
- if (mipLevelCount && !texels) {
- return nullptr;
- }
- for (int i = 0; i < mipLevelCount; ++i) {
- if (!texels[i].fPixels) {
- return nullptr;
- }
- }
-
if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
!fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return nullptr;
static const uint32_t kFlags = kExact_ScratchTextureFlag |
kNoCreate_ScratchTextureFlag;
if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
- if (!texels || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- baseMipLevel.fPixels, baseMipLevel.fRowBytes)) {
+ if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ baseMipLevel.fPixels, baseMipLevel.fRowBytes)) {
if (SkBudgeted::kNo == budgeted) {
texture->resourcePriv().makeUnbudgeted();
}
GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
const void* srcData, size_t rowBytes) {
- GrMipLevel tempTexels;
- GrMipLevel* texels = nullptr;
- int levelCount = 0;
- if (srcData) {
- tempTexels.fPixels = srcData;
- tempTexels.fRowBytes = rowBytes;
- texels = &tempTexels;
- levelCount = 1;
- }
- return this->createMipMappedTexture(desc, budgeted, texels, levelCount);
+ const int mipLevelCount = 1;
+ GrMipLevel texels[mipLevelCount];
+ texels[0].fPixels = srcData;
+ texels[0].fRowBytes = rowBytes;
+
+ return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount);
}
GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
}
if (!(kNoCreate_ScratchTextureFlag & flags)) {
- return fGpu->createTexture(*desc, SkBudgeted::kYes);
+ return fGpu->createTexture(*desc, SkBudgeted::kYes, nullptr, 0);
}
return nullptr;
* @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 void allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc,
const GrGLInterface& interface,
const GrGLCaps& caps,
GrGLenum target,
GrGLenum externalFormat,
GrGLenum externalType,
const SkTArray<GrMipLevel>& texels,
- int baseWidth, int baseHeight) {
+ int baseWidth, int baseHeight,
+ bool* succeeded) {
CLEAR_ERROR_BEFORE_ALLOC(&interface);
bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig);
desc.fWidth, desc.fHeight));
GrGLenum error = check_alloc_error(desc, &interface);
if (error != GR_GL_NO_ERROR) {
- return false;
+ *succeeded = false;
} else {
for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
const void* currentMipData = texels[currentMipLevel].fPixels;
externalFormat, externalType,
currentMipData));
}
- return true;
+ *succeeded = true;
}
} else {
- if (texels.empty()) {
+ *succeeded = true;
+ for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
+ int twoToTheMipLevel = 1 << currentMipLevel;
+ int currentWidth = SkTMax(1, baseWidth / twoToTheMipLevel);
+ int currentHeight = SkTMax(1, baseHeight / twoToTheMipLevel);
+ const void* currentMipData = texels[currentMipLevel].fPixels;
+ // Even if curremtMipData is nullptr, continue to call TexImage2D.
+ // This will allocate texture memory which we can later populate.
GL_ALLOC_CALL(&interface,
TexImage2D(target,
- 0,
+ currentMipLevel,
internalFormat,
- baseWidth,
- baseHeight,
+ currentWidth,
+ currentHeight,
0, // border
externalFormat, externalType,
- nullptr));
+ currentMipData));
GrGLenum error = check_alloc_error(desc, &interface);
if (error != GR_GL_NO_ERROR) {
- return false;
- }
- } else {
- for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
- int twoToTheMipLevel = 1 << currentMipLevel;
- int currentWidth = SkTMax(1, baseWidth / twoToTheMipLevel);
- int currentHeight = SkTMax(1, baseHeight / twoToTheMipLevel);
- const void* currentMipData = texels[currentMipLevel].fPixels;
- // Even if curremtMipData is nullptr, continue to call TexImage2D.
- // This will allocate texture memory which we can later populate.
- GL_ALLOC_CALL(&interface,
- TexImage2D(target,
- currentMipLevel,
- internalFormat,
- currentWidth,
- currentHeight,
- 0, // border
- externalFormat, externalType,
- currentMipData));
- GrGLenum error = check_alloc_error(desc, &interface);
- if (error != GR_GL_NO_ERROR) {
- return false;
- }
+ *succeeded = false;
+ break;
}
}
}
- return true;
}
/**
for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >= 0;
currentMipLevel--) {
- SkASSERT(texelsShallowCopy[currentMipLevel].fPixels || kTransfer_UploadType == uploadType);
+ SkASSERT(texelsShallowCopy[currentMipLevel].fPixels ||
+ kNewTexture_UploadType == uploadType || kTransfer_UploadType == uploadType);
}
const GrGLInterface* interface = this->glInterface();
int currentWidth = SkTMax(1, width / twoToTheMipLevel);
int currentHeight = SkTMax(1, height / twoToTheMipLevel);
+ if (texelsShallowCopy[currentMipLevel].fPixels == nullptr) {
+ continue;
+ }
+
if (currentHeight > SK_MaxS32 ||
currentWidth > SK_MaxS32) {
return false;
bool swFlipY = false;
bool glFlipY = false;
- if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty()) {
+ if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
if (caps.unpackFlipYSupport()) {
glFlipY = true;
} else {
char* buffer = (char*)tempStorage.reset(combined_buffer_size);
for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) {
+ if (texelsShallowCopy[currentMipLevel].fPixels == nullptr) {
+ continue;
+ }
+
int twoToTheMipLevel = 1 << currentMipLevel;
int currentWidth = SkTMax(1, width / twoToTheMipLevel);
int currentHeight = SkTMax(1, height / twoToTheMipLevel);
} else {
return false;
}
- }
-
- if (!texelsShallowCopy.empty()) {
if (glFlipY) {
GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
0 == left && 0 == top &&
desc.fWidth == width && desc.fHeight == height &&
!desc.fTextureStorageAllocator.fAllocateTextureStorage) {
- succeeded = allocate_and_populate_uncompressed_texture(desc, *interface, caps, target,
- internalFormat, externalFormat,
- externalType, texelsShallowCopy,
- width, height);
+ allocate_and_populate_uncompressed_texture(desc, *interface, caps, target,
+ internalFormat, externalFormat,
+ externalType, texelsShallowCopy,
+ width, height, &succeeded);
} else {
if (swFlipY || glFlipY) {
top = desc.fHeight - (top + height);
int twoToTheMipLevel = 1 << currentMipLevel;
int currentWidth = SkTMax(1, width / twoToTheMipLevel);
int currentHeight = SkTMax(1, height / twoToTheMipLevel);
+ if (texelsShallowCopy[currentMipLevel].fPixels == nullptr) {
+ continue;
+ }
GL_CALL(TexSubImage2D(target,
currentMipLevel,
UploadType uploadType,
int left, int top, int width, int height) {
SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+ SkASSERT(kTransfer_UploadType != uploadType &&
+ (texels[0].fPixels || kNewTexture_UploadType != uploadType));
// No support for software flip y, yet...
SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin);
return false;
}
for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
- SkASSERT(texels[currentMipLevel].fPixels || kTransfer_UploadType == uploadType);
+ if (texels[currentMipLevel].fPixels == nullptr) {
+ continue;
+ }
int twoToTheMipLevel = 1 << currentMipLevel;
int currentWidth = SkTMax(1, width / twoToTheMipLevel);
// We do not make SkTArray available outside of Skia,
// and so we do not want to allow mipmaps to external
// allocators just yet.
- SkASSERT(texels.count() < 2);
+ SkASSERT(texels.count() == 1);
+ SkSTArray<1, GrMipLevel> texelsShallowCopy(1);
+ texelsShallowCopy.push_back(texels[0]);
- const void* pixels = nullptr;
- if (!texels.empty()) {
- pixels = texels.begin()->fPixels;
- }
switch (desc.fTextureStorageAllocator.fAllocateTextureStorage(
desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendObject>(info),
- desc.fWidth, desc.fHeight, desc.fConfig, pixels, desc.fOrigin)) {
+ desc.fWidth, desc.fHeight, desc.fConfig, texelsShallowCopy[0].fPixels,
+ desc.fOrigin)) {
case GrTextureStorageAllocator::Result::kSucceededAndUploaded:
return true;
case GrTextureStorageAllocator::Result::kFailed:
if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0,
desc.fWidth, desc.fHeight,
- desc.fConfig, texels)) {
+ desc.fConfig, texelsShallowCopy)) {
desc.fTextureStorageAllocator.fDeallocateTextureStorage(
desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendObject>(info));
return false;
desc.fConfig = rtConfig;
desc.fWidth = desc.fHeight = 16;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> temp(this->createTexture(desc,
- SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> temp(this->createTexture(desc, SkBudgeted::kNo, nullptr, 0));
if (!temp) {
return false;
}