Index: src/gpu/GrGpu.cpp |
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp |
index 96728f3ba80d16950b34225840061b0bc04de32d..cb2593b0c0463bed2c74535c98396733f4740312 100644 |
--- a/src/gpu/GrGpu.cpp |
+++ b/src/gpu/GrGpu.cpp |
@@ -1,4 +1,3 @@ |
- |
/* |
* Copyright 2010 Google Inc. |
* |
@@ -66,73 +65,115 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) |
} |
} |
-GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
- const void* srcData, size_t rowBytes) { |
- GrSurfaceDesc desc = origDesc; |
- |
- if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
- return nullptr; |
+/** |
+ * Prior to creating a texture, make sure the type of texture being created is |
+ * supported by calling check_texture_creation_params. |
+ * |
+ * @param caps The capabilities of the GL device. |
+ * @param desc The descriptor of the texture to create. |
+ * @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) { |
+ if (!caps.isConfigTexturable(desc.fConfig)) { |
+ return false; |
} |
- bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
- if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
- return nullptr; |
+ *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
+ if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
+ return false; |
} |
// We currently do not support multisampled textures |
- if (!isRT && desc.fSampleCnt > 0) { |
- return nullptr; |
+ if (!*isRT && desc.fSampleCnt > 0) { |
+ return false; |
} |
- GrTexture *tex = nullptr; |
- |
- if (isRT) { |
- int maxRTSize = this->caps()->maxRenderTargetSize(); |
+ if (*isRT) { |
+ int maxRTSize = caps.maxRenderTargetSize(); |
if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
- return nullptr; |
+ return false; |
} |
} else { |
- int maxSize = this->caps()->maxTextureSize(); |
+ int maxSize = caps.maxTextureSize(); |
if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
- return nullptr; |
+ return false; |
} |
} |
+ return true; |
+} |
- GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : |
- GrGpuResource::kUncached_LifeCycle; |
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
+ const SkTArray<SkMipMapLevel>& texels) { |
+ GrSurfaceDesc desc = origDesc; |
- desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
- // Attempt to catch un- or wrongly initialized sample counts; |
- SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
+ const GrCaps* caps = this->caps(); |
+ if (!caps) { |
+ return nullptr; |
+ } else { |
+ bool isRT = false; |
+ bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT); |
+ if (!textureCreationParamsValid) { |
+ return nullptr; |
+ } |
- desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
+ // Attempt to catch un- or wrongly intialized sample counts; |
+ SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
- if (GrPixelConfigIsCompressed(desc.fConfig)) { |
- // We shouldn't be rendering into this |
- SkASSERT(!isRT); |
- SkASSERT(0 == desc.fSampleCnt); |
+ desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
- if (!this->caps()->npotTextureTileSupport() && |
- (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
- return nullptr; |
- } |
+ GrTexture* tex = nullptr; |
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : |
+ GrGpuResource::kUncached_LifeCycle; |
- this->handleDirtyContext(); |
- tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); |
- } else { |
- this->handleDirtyContext(); |
- tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); |
- } |
- if (!this->caps()->reuseScratchTextures() && !isRT) { |
- tex->resourcePriv().removeScratchKey(); |
- } |
- if (tex) { |
- fStats.incTextureCreates(); |
- if (srcData) { |
- fStats.incTextureUploads(); |
+ if (GrPixelConfigIsCompressed(desc.fConfig)) { |
+ // We shouldn't be rendering into this |
+ SkASSERT(!isRT); |
+ SkASSERT(0 == desc.fSampleCnt); |
+ |
+ if (!caps->npotTextureTileSupport() && |
+ (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
+ return nullptr; |
+ } |
+ |
+ this->handleDirtyContext(); |
+ tex = this->onCreateCompressedTexture(desc, lifeCycle, texels); |
+ } else { |
+ this->handleDirtyContext(); |
+ tex = this->onCreateTexture(desc, lifeCycle, texels); |
} |
+ if (tex) { |
+ if (!caps->reuseScratchTextures() && !isRT) { |
+ tex->resourcePriv().removeScratchKey(); |
+ } |
+ fStats.incTextureCreates(); |
+ if (!texels.empty()) { |
+ if (texels[0].fTexels) { |
+ fStats.incTextureUploads(); |
+ } |
+ } |
+ } |
+ return tex; |
+ } |
+} |
+ |
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, |
+ const void* srcData, size_t rowBytes) { |
+ const int width = desc.fWidth; |
+ const int height = desc.fHeight; |
+ if (width < 0 || height < 0) { |
bsalomon
2015/09/30 18:01:29
<= 0?
cblume
2015/10/08 09:27:57
Done.
|
+ return nullptr; |
} |
- return tex; |
+ const uint32_t baseLevelWidth = width; |
+ const uint32_t baseLevelHeight = height; |
+ |
+ SkMipMapLevel level(srcData, rowBytes, baseLevelWidth, baseLevelHeight); |
+ const int mipLevelCount = 1; |
+ SkTArray<SkMipMapLevel> levels(mipLevelCount); |
+ levels.push_back(level); |
+ |
+ return this->createTexture(desc, budgeted, levels); |
} |
GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { |
@@ -230,7 +271,7 @@ bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size |
return true; |
} |
-bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
+bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
GrPixelConfig srcConfig, DrawPreference* drawPreference, |
WritePixelTempDrawInfo* tempDrawInfo) { |
SkASSERT(drawPreference); |
@@ -248,7 +289,7 @@ bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, siz |
ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
} |
- if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConfig, drawPreference, |
+ if (!this->onGetWritePixelsInfo(dstSurface, width, height, srcConfig, drawPreference, |
tempDrawInfo)) { |
return false; |
} |
@@ -293,20 +334,33 @@ bool GrGpu::readPixels(GrSurface* surface, |
bool GrGpu::writePixels(GrSurface* surface, |
int left, int top, int width, int height, |
- GrPixelConfig config, const void* buffer, |
- size_t rowBytes) { |
- if (!buffer) { |
- return false; |
- } |
- |
+ GrPixelConfig config, const SkTArray<SkMipMapLevel>& texels) { |
this->handleDirtyContext(); |
- if (this->onWritePixels(surface, left, top, width, height, config, buffer, rowBytes)) { |
+ if (this->onWritePixels(surface, left, top, width, height, config, texels)) { |
fStats.incTextureUploads(); |
return true; |
} |
return false; |
} |
+bool GrGpu::writePixels(GrSurface* surface, |
+ int left, int top, int width, int height, |
+ GrPixelConfig config, const void* buffer, |
+ size_t rowBytes) { |
+ if (width < 0 || height < 0) { |
bsalomon
2015/09/30 18:01:29
<= 0?
cblume
2015/10/08 09:27:57
Done.
|
+ return false; |
+ } |
+ const uint32_t baseLevelWidth = width; |
+ const uint32_t baseLevelHeight = height; |
+ |
+ SkMipMapLevel mipLevel(buffer, rowBytes, baseLevelWidth, baseLevelHeight); |
+ const int mipLevelCount = 1; |
+ SkTArray<SkMipMapLevel> texels(mipLevelCount); |
+ texels.push_back(mipLevel); |
+ |
+ return this->writePixels(surface, left, top, width, height, config, texels); |
+} |
+ |
void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
SkASSERT(target); |
this->handleDirtyContext(); |