aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2015-04-22 13:27:39 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-22 13:27:40 -0700
commitb0e1be207f6b5a5346641b7b675bb9bd1993f9df (patch)
tree492285942dd7317160ddfb39f69df18a4c30e876
parentb30938ba7f374843f56848be32d03152b2a4b5da (diff)
Refactor createTexture and onCreateTexture
-rw-r--r--src/gpu/GrGpu.cpp48
-rw-r--r--src/gpu/GrGpu.h8
-rw-r--r--src/gpu/GrTest.cpp6
-rw-r--r--src/gpu/gl/GrGLGpu.cpp65
-rw-r--r--src/gpu/gl/GrGLGpu.h11
5 files changed, 73 insertions, 65 deletions
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 88e2bb961e..716c023530 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -37,8 +37,25 @@ void GrGpu::contextAbandoned() {}
////////////////////////////////////////////////////////////////////////////////
-GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
+namespace {
+
+GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
+ // By default, GrRenderTargets are GL's normal orientation so that they
+ // can be drawn to by the outside world without the client having
+ // to render upside down.
+ if (kDefault_GrSurfaceOrigin == origin) {
+ return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
+ } else {
+ return origin;
+ }
+}
+
+}
+
+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;
}
@@ -49,9 +66,32 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
}
GrTexture *tex = NULL;
+
+ if (isRT) {
+ int maxRTSize = this->caps()->maxRenderTargetSize();
+ if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
+ return NULL;
+ }
+ } else {
+ int maxSize = this->caps()->maxTextureSize();
+ if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
+ return NULL;
+ }
+ }
+
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
+ GrGpuResource::kUncached_LifeCycle;
+
+ 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);
+
if (GrPixelConfigIsCompressed(desc.fConfig)) {
// We shouldn't be rendering into this
- SkASSERT((desc.fFlags & kRenderTarget_GrSurfaceFlag) == 0);
+ SkASSERT(!isRT);
+ SkASSERT(0 == desc.fSampleCnt);
if (!this->caps()->npotTextureTileSupport() &&
(!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
@@ -59,10 +99,10 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
}
this->handleDirtyContext();
- tex = this->onCreateCompressedTexture(desc, budgeted, srcData);
+ tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
} else {
this->handleDirtyContext();
- tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes);
+ tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
}
if (!this->caps()->reuseScratchTextures() && !isRT) {
tex->resourcePriv().removeScratchKey();
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 3df651f1e6..5784781996 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -437,9 +437,13 @@ private:
virtual void onResetContext(uint32_t resetBits) = 0;
// overridden by backend-specific derived class to create objects.
- virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted,
+ // Texture size and sample size will have already been validated in base class before
+ // onCreateTexture/CompressedTexture are called.
+ virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
const void* srcData, size_t rowBytes) = 0;
- virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
+ virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
const void* srcData) = 0;
virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0;
virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0;
diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp
index 09a221df78..44be4bfe97 100644
--- a/src/gpu/GrTest.cpp
+++ b/src/gpu/GrTest.cpp
@@ -175,12 +175,12 @@ public:
private:
void onResetContext(uint32_t resetBits) override {}
- GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
- size_t rowBytes) override {
+ GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
+ const void* srcData, size_t rowBytes) override {
return NULL;
}
- GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
+ GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
const void* srcData) override {
return NULL;
}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 954ecc4f61..dedd449edd 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -416,7 +416,8 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
GrGLTexture* texture = NULL;
if (renderTarget) {
GrGLRenderTarget::IDDesc rtIDDesc;
- if (!this->createRenderTargetObjects(surfDesc, false, idDesc.fTextureID, &rtIDDesc)) {
+ if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle,
+ idDesc.fTextureID, &rtIDDesc)) {
return NULL;
}
texture = SkNEW_ARGS(GrGLTextureRenderTarget, (this, surfDesc, idDesc, rtIDDesc));
@@ -811,13 +812,14 @@ static bool renderbuffer_storage_msaa(GrGLContext& ctx,
return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
}
-bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted, GrGLuint texID,
+bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
+ GrGLuint texID,
GrGLRenderTarget::IDDesc* idDesc) {
idDesc->fMSColorRenderbufferID = 0;
idDesc->fRTFBOID = 0;
idDesc->fTexFBOID = 0;
- idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+ idDesc->fLifeCycle = lifeCycle;
GrGLenum status;
@@ -930,13 +932,9 @@ static size_t as_size_t(int x) {
}
#endif
-GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
const void* srcData, size_t rowBytes) {
-
- GrSurfaceDesc desc = origDesc;
-
- // Attempt to catch un- or wrongly initialized sample counts;
- SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
// We fail if the MSAA was requested and is not available.
if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
//SkDebugf("MSAA RT requested but not supported on this platform.");
@@ -945,31 +943,9 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& origDesc, bool budgeted
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
- // If the sample count exceeds the max then we clamp it.
- desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
- desc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
-
- if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
- //SkDebugf("MSAA RT requested but not supported on this platform.");
- return return_null_texture();
- }
-
- if (renderTarget) {
- int maxRTSize = this->caps()->maxRenderTargetSize();
- if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
- return return_null_texture();
- }
- } else {
- int maxSize = this->caps()->maxTextureSize();
- if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
- return return_null_texture();
- }
- }
-
GrGLTexture::IDDesc idDesc;
GL_CALL(GenTextures(1, &idDesc.fTextureID));
- idDesc.fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+ idDesc.fLifeCycle = lifeCycle;
if (!idDesc.fTextureID) {
return return_null_texture();
@@ -1020,7 +996,7 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& origDesc, bool budgeted
GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0));
GrGLRenderTarget::IDDesc rtIDDesc;
- if (!this->createRenderTargetObjects(desc, budgeted, idDesc.fTextureID, &rtIDDesc)) {
+ if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID, &rtIDDesc)) {
GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
return return_null_texture();
}
@@ -1036,30 +1012,17 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& origDesc, bool budgeted
return tex;
}
-GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
const void* srcData) {
-
- if(SkToBool(origDesc.fFlags & kRenderTarget_GrSurfaceFlag) || origDesc.fSampleCnt > 0) {
- return return_null_texture();
- }
-
// Make sure that we're not flipping Y.
- GrSurfaceOrigin texOrigin = resolve_origin(origDesc.fOrigin, false);
- if (kBottomLeft_GrSurfaceOrigin == texOrigin) {
- return return_null_texture();
- }
- GrSurfaceDesc desc = origDesc;
- desc.fOrigin = texOrigin;
-
- int maxSize = this->caps()->maxTextureSize();
- if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
+ if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
return return_null_texture();
}
GrGLTexture::IDDesc idDesc;
GL_CALL(GenTextures(1, &idDesc.fTextureID));
- idDesc.fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+ idDesc.fLifeCycle = lifeCycle;
if (!idDesc.fTextureID) {
return return_null_texture();
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 29d63fbd4f..a8d8c2e71d 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -114,9 +114,10 @@ private:
// GrGpu overrides
void onResetContext(uint32_t resetBits) override;
- GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
- size_t rowBytes) override;
- GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
+ GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
+ const void* srcData, size_t rowBytes) override;
+ GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
+ GrGpuResource::LifeCycle lifeCycle,
const void* srcData) override;
GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override;
GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override;
@@ -277,8 +278,8 @@ private:
int left = 0, int top = 0,
int width = -1, int height = -1);
- bool createRenderTargetObjects(const GrSurfaceDesc&, bool budgeted, GrGLuint texID,
- GrGLRenderTarget::IDDesc*);
+ bool createRenderTargetObjects(const GrSurfaceDesc&, GrGpuResource::LifeCycle lifeCycle,
+ GrGLuint texID, GrGLRenderTarget::IDDesc*);
enum TempFBOTarget {
kSrc_TempFBOTarget,