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

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: 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..3e64890998c42d97e2ce54ea698a73e3eb7ff407 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -64,40 +64,45 @@ 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;
+static bool check_texture_creation_params(const GrCaps* caps, const GrSurfaceDesc& desc,
scroggo 2015/07/21 14:44:23 nit: typically we use const& for parameters which
cblume 2015/07/21 23:07:30 Done.
+ bool& isRT) {
scroggo 2015/07/21 14:44:23 nit: typically we use pointers for parameters whic
cblume 2015/07/21 23:07:29 Done.
+ 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;
+ return false;
}
- GrTexture *tex = NULL;
-
if (isRT) {
- int maxRTSize = this->caps()->maxRenderTargetSize();
+ 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;
+
+ bool isRT = false;
+ bool textureCreationParamsValid = check_texture_creation_params(this->caps(), desc, isRT);
+ if (textureCreationParamsValid == false) {
scroggo 2015/07/21 14:44:23 nit: typically we just say if (!textureCreationPa
cblume 2015/07/21 23:07:29 Done.
+ return NULL;
+ }
desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
// Attempt to catch un- or wrongly initialized sample counts;
@@ -105,6 +110,10 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
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);
@@ -133,6 +142,52 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
return tex;
}
+GrTexture* GrGpu::createMipmappedTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+ const SkMipMap& srcData) {
+ GrSurfaceDesc desc = origDesc;
+
+ bool isRT = false;
+ bool textureCreationParamsValid = check_texture_creation_params(this->caps(), desc, isRT);
+ if (textureCreationParamsValid == false) {
+ return NULL;
+ }
+
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->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 (!this->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 (!this->caps()->reuseScratchTextures() && !isRT) {
+ tex->resourcePriv().removeScratchKey();
+ }
+ if (tex) {
+ fStats.incTextureCreates();
+ fStats.incTextureUploads();
+ }
+ return tex;
+}
+
bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) {
SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment());
GrUniqueKey sbKey;

Powered by Google App Engine
This is Rietveld 408576698