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

Unified Diff: src/gpu/GrGpu.cpp

Issue 1102663002: Refactor createTexture and onCreateTexture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrGpu.cpp
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 88e2bb961e6b8dd336713d6ee5928cb50b8a1dab..d57bac1dc5e69169747b09ccae7aa15eb2c5ca9f 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -37,6 +37,21 @@ void GrGpu::contextAbandoned() {}
////////////////////////////////////////////////////////////////////////////////
+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& desc, bool budgeted,
const void* srcData, size_t rowBytes) {
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
@@ -49,9 +64,34 @@ 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;
+
+ GrSurfaceDesc descCopy = desc;
+
+ descCopy.fSampleCnt = SkTMin(descCopy.fSampleCnt, this->caps()->maxSampleCount());
+ // Attempt to catch un- or wrongly initialized sample counts;
+ SkASSERT(descCopy.fSampleCnt >= 0 && descCopy.fSampleCnt <= 64);
+
+ descCopy.fOrigin = resolve_origin(descCopy.fOrigin, isRT);
+
if (GrPixelConfigIsCompressed(desc.fConfig)) {
// We shouldn't be rendering into this
- SkASSERT((desc.fFlags & kRenderTarget_GrSurfaceFlag) == 0);
+ SkASSERT(!isRT);
+ SkASSERT(0 == descCopy.fSampleCnt);
if (!this->caps()->npotTextureTileSupport() &&
(!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
bsalomon 2015/04/22 20:11:11 descCopy x2 ? minor suggestion: I think it is sl
egdaniel 2015/04/22 20:20:27 Done.
@@ -59,10 +99,10 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
}
this->handleDirtyContext();
- tex = this->onCreateCompressedTexture(desc, budgeted, srcData);
+ tex = this->onCreateCompressedTexture(descCopy, lifeCycle, srcData);
} else {
this->handleDirtyContext();
- tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes);
+ tex = this->onCreateTexture(descCopy, lifeCycle, srcData, rowBytes);
}
if (!this->caps()->reuseScratchTextures() && !isRT) {
tex->resourcePriv().removeScratchKey();
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698