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

Side by Side Diff: src/gpu/GrGpu.cpp

Issue 1102663002: Refactor createTexture and onCreateTexture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: change descCopy name 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 GrGpu::~GrGpu() { 32 GrGpu::~GrGpu() {
33 SkSafeSetNull(fQuadIndexBuffer); 33 SkSafeSetNull(fQuadIndexBuffer);
34 } 34 }
35 35
36 void GrGpu::contextAbandoned() {} 36 void GrGpu::contextAbandoned() {}
37 37
38 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
39 39
40 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, 40 namespace {
41
jvanverth1 2015/04/22 20:28:13 I thought we were deprecating the use of anonymous
42 GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
43 // By default, GrRenderTargets are GL's normal orientation so that they
44 // can be drawn to by the outside world without the client having
45 // to render upside down.
46 if (kDefault_GrSurfaceOrigin == origin) {
47 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
48 } else {
49 return origin;
50 }
51 }
52
53 }
54
55 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
41 const void* srcData, size_t rowBytes) { 56 const void* srcData, size_t rowBytes) {
57 GrSurfaceDesc desc = origDesc;
58
42 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 59 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
43 return NULL; 60 return NULL;
44 } 61 }
45 62
46 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 63 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
47 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 64 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
48 return NULL; 65 return NULL;
49 } 66 }
50 67
51 GrTexture *tex = NULL; 68 GrTexture *tex = NULL;
69
70 if (isRT) {
71 int maxRTSize = this->caps()->maxRenderTargetSize();
72 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
73 return NULL;
74 }
75 } else {
76 int maxSize = this->caps()->maxTextureSize();
77 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
78 return NULL;
79 }
80 }
81
82 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle :
83 GrGpuResource::kUncached_Lif eCycle;
84
85 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
86 // Attempt to catch un- or wrongly initialized sample counts;
87 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
88
89 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
90
52 if (GrPixelConfigIsCompressed(desc.fConfig)) { 91 if (GrPixelConfigIsCompressed(desc.fConfig)) {
53 // We shouldn't be rendering into this 92 // We shouldn't be rendering into this
54 SkASSERT((desc.fFlags & kRenderTarget_GrSurfaceFlag) == 0); 93 SkASSERT(!isRT);
94 SkASSERT(0 == desc.fSampleCnt);
55 95
56 if (!this->caps()->npotTextureTileSupport() && 96 if (!this->caps()->npotTextureTileSupport() &&
57 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { 97 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
58 return NULL; 98 return NULL;
59 } 99 }
60 100
61 this->handleDirtyContext(); 101 this->handleDirtyContext();
62 tex = this->onCreateCompressedTexture(desc, budgeted, srcData); 102 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
63 } else { 103 } else {
64 this->handleDirtyContext(); 104 this->handleDirtyContext();
65 tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes); 105 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
66 } 106 }
67 if (!this->caps()->reuseScratchTextures() && !isRT) { 107 if (!this->caps()->reuseScratchTextures() && !isRT) {
68 tex->resourcePriv().removeScratchKey(); 108 tex->resourcePriv().removeScratchKey();
69 } 109 }
70 if (tex) { 110 if (tex) {
71 fStats.incTextureCreates(); 111 fStats.incTextureCreates();
72 if (srcData) { 112 if (srcData) {
73 fStats.incTextureUploads(); 113 fStats.incTextureUploads();
74 } 114 }
75 } 115 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 GrDrawTarget::PathIndexType indexType, 355 GrDrawTarget::PathIndexType indexType,
316 const float transformValues[], 356 const float transformValues[],
317 GrDrawTarget::PathTransformType transformType, 357 GrDrawTarget::PathTransformType transformType,
318 int count, 358 int count,
319 const GrStencilSettings& stencilSettings) { 359 const GrStencilSettings& stencilSettings) {
320 this->handleDirtyContext(); 360 this->handleDirtyContext();
321 pathRange->willDrawPaths(indices, indexType, count); 361 pathRange->willDrawPaths(indices, indexType, count);
322 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, 362 this->onDrawPaths(args, pathRange, indices, indexType, transformValues,
323 transformType, count, stencilSettings); 363 transformType, count, stencilSettings);
324 } 364 }
OLDNEW
« 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