Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: src/gpu/GrGpu.cpp

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Style changes based on CL feedback. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrGpu.cpp
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 728fb880622010fa9495932d467b7f6df7d3ff04..3c996071b3cedd1a946c4feee074eb1645733f54 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -64,73 +64,146 @@ 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 NULL;
+/**
+ * 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 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 NULL;
+ *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+ if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ return false;
}
- // We currently not support multisampled textures
- if (!isRT && desc.fSampleCnt > 0) {
- return NULL;
+ // We currently do not support multisampled textures
+ if (!*isRT && desc.fSampleCnt > 0) {
+ return false;
}
- GrTexture *tex = NULL;
-
- if (isRT) {
- int maxRTSize = this->caps()->maxRenderTargetSize();
+ if (*isRT) {
+ int maxRTSize = caps.maxRenderTargetSize();
if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
- return NULL;
+ return false;
}
} else {
- int maxSize = this->caps()->maxTextureSize();
+ int maxSize = caps.maxTextureSize();
if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
- return NULL;
+ return false;
}
}
+ return true;
+}
- GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+ const void* srcData, size_t rowBytes) {
+ 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 NULL;
+ } else {
+ bool isRT = false;
+ bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
+ if (!textureCreationParamsValid) {
+ return NULL;
+ }
- desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
+ // Attempt to catch un- or wrongly initialized 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 NULL;
+ GrTexture *tex = NULL;
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
+ GrGpuResource::kUncached_LifeCycle;
+
+ 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 NULL;
+ }
+
+ this->handleDirtyContext();
+ tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
+ } else {
+ this->handleDirtyContext();
+ tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
}
+ if (!caps->reuseScratchTextures() && !isRT) {
+ tex->resourcePriv().removeScratchKey();
+ }
+ if (tex) {
+ fStats.incTextureCreates();
+ if (srcData) {
+ fStats.incTextureUploads();
+ }
+ }
+ return tex;
+ }
+}
+
+GrTexture* GrGpu::createMipmappedTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+ const SkMipMap& srcData) {
+ GrSurfaceDesc desc = origDesc;
- this->handleDirtyContext();
- tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
+ const GrCaps* caps = this->caps();
+ if (!caps) {
+ return NULL;
} else {
- this->handleDirtyContext();
- tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
- }
- if (!this->caps()->reuseScratchTextures() && !isRT) {
- tex->resourcePriv().removeScratchKey();
- }
- if (tex) {
- fStats.incTextureCreates();
- if (srcData) {
+ bool isRT = false;
+ bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
+ if (!textureCreationParamsValid) {
+ return NULL;
+ }
+
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
+ // Attempt to catch un- or wrongly initialized sample counts;
+ SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
+
+ desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
+
+ GrTexture *tex = NULL;
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
+ GrGpuResource::kUncached_LifeCycle;
+
+ 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 NULL;
+ }
+
+ this->handleDirtyContext();
+ tex = this->onCreateCompressedMipmappedTexture(desc, lifeCycle, srcData);
+ } else {
+ this->handleDirtyContext();
+ tex = this->onCreateMipmappedTexture(desc, lifeCycle, srcData);
+ }
+ if (!caps->reuseScratchTextures() && !isRT) {
+ tex->resourcePriv().removeScratchKey();
+ }
+ if (tex) {
+ fStats.incTextureCreates();
fStats.incTextureUploads();
}
+ return tex;
}
- return tex;
}
bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) {

Powered by Google App Engine
This is Rietveld 408576698