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

Side by Side 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 unified diff | Download patch
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // By default, GrRenderTargets are GL's normal orientation so that they 57 // By default, GrRenderTargets are GL's normal orientation so that they
58 // can be drawn to by the outside world without the client having 58 // can be drawn to by the outside world without the client having
59 // to render upside down. 59 // to render upside down.
60 if (kDefault_GrSurfaceOrigin == origin) { 60 if (kDefault_GrSurfaceOrigin == origin) {
61 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; 61 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
62 } else { 62 } else {
63 return origin; 63 return origin;
64 } 64 }
65 } 65 }
66 66
67 static bool check_texture_creation_params(const GrCaps* caps, const GrSurfaceDes c& desc,
scroggo 2015/07/21 14:44:23 nit: typically we use const& for parameters which
cblume 2015/07/21 23:07:30 Done.
68 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.
69 if (!caps->isConfigTexturable(desc.fConfig)) {
70 return false;
71 }
72
73 isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
74 if (isRT && !caps->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
75 return false;
76 }
77
78 // We currently not support multisampled textures
79 if (!isRT && desc.fSampleCnt > 0) {
80 return false;
81 }
82
83 if (isRT) {
84 int maxRTSize = caps->maxRenderTargetSize();
85 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
86 return false;
87 }
88 } else {
89 int maxSize = caps->maxTextureSize();
90 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
91 return false;
92 }
93 }
94 return true;
95 }
96
67 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, 97 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
68 const void* srcData, size_t rowBytes) { 98 const void* srcData, size_t rowBytes) {
69 GrSurfaceDesc desc = origDesc; 99 GrSurfaceDesc desc = origDesc;
70 100
71 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 101 bool isRT = false;
102 bool textureCreationParamsValid = check_texture_creation_params(this->caps() , desc, isRT);
103 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.
72 return NULL; 104 return NULL;
73 } 105 }
74 106
75 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
76 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
77 return NULL;
78 }
79
80 // We currently not support multisampled textures
81 if (!isRT && desc.fSampleCnt > 0) {
82 return NULL;
83 }
84
85 GrTexture *tex = NULL;
86
87 if (isRT) {
88 int maxRTSize = this->caps()->maxRenderTargetSize();
89 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
90 return NULL;
91 }
92 } else {
93 int maxSize = this->caps()->maxTextureSize();
94 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
95 return NULL;
96 }
97 }
98
99 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle :
100 GrGpuResource::kUncached_Lif eCycle;
101
102 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); 107 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
103 // Attempt to catch un- or wrongly initialized sample counts; 108 // Attempt to catch un- or wrongly initialized sample counts;
104 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); 109 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
105 110
106 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); 111 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
107 112
113 GrTexture *tex = NULL;
114 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle :
115 GrGpuResource::kUncached_Lif eCycle;
116
108 if (GrPixelConfigIsCompressed(desc.fConfig)) { 117 if (GrPixelConfigIsCompressed(desc.fConfig)) {
109 // We shouldn't be rendering into this 118 // We shouldn't be rendering into this
110 SkASSERT(!isRT); 119 SkASSERT(!isRT);
111 SkASSERT(0 == desc.fSampleCnt); 120 SkASSERT(0 == desc.fSampleCnt);
112 121
113 if (!this->caps()->npotTextureTileSupport() && 122 if (!this->caps()->npotTextureTileSupport() &&
114 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { 123 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
115 return NULL; 124 return NULL;
116 } 125 }
117 126
118 this->handleDirtyContext(); 127 this->handleDirtyContext();
119 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); 128 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
120 } else { 129 } else {
121 this->handleDirtyContext(); 130 this->handleDirtyContext();
122 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); 131 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
123 } 132 }
124 if (!this->caps()->reuseScratchTextures() && !isRT) { 133 if (!this->caps()->reuseScratchTextures() && !isRT) {
125 tex->resourcePriv().removeScratchKey(); 134 tex->resourcePriv().removeScratchKey();
126 } 135 }
127 if (tex) { 136 if (tex) {
128 fStats.incTextureCreates(); 137 fStats.incTextureCreates();
129 if (srcData) { 138 if (srcData) {
130 fStats.incTextureUploads(); 139 fStats.incTextureUploads();
131 } 140 }
132 } 141 }
133 return tex; 142 return tex;
134 } 143 }
135 144
145 GrTexture* GrGpu::createMipmappedTexture(const GrSurfaceDesc& origDesc, bool bud geted,
146 const SkMipMap& srcData) {
147 GrSurfaceDesc desc = origDesc;
148
149 bool isRT = false;
150 bool textureCreationParamsValid = check_texture_creation_params(this->caps() , desc, isRT);
151 if (textureCreationParamsValid == false) {
152 return NULL;
153 }
154
155 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
156 // Attempt to catch un- or wrongly initialized sample counts;
157 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
158
159 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
160
161 GrTexture *tex = NULL;
162 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle :
163 GrGpuResource::kUncached_Lif eCycle;
164
165 if (GrPixelConfigIsCompressed(desc.fConfig)) {
166 // We shouldn't be rendering into this
167 SkASSERT(!isRT);
168 SkASSERT(0 == desc.fSampleCnt);
169
170 if (!this->caps()->npotTextureTileSupport() &&
171 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
172 return NULL;
173 }
174
175 this->handleDirtyContext();
176 tex = this->onCreateCompressedMipmappedTexture(desc, lifeCycle, srcData) ;
177 } else {
178 this->handleDirtyContext();
179 tex = this->onCreateMipmappedTexture(desc, lifeCycle, srcData);
180 }
181 if (!this->caps()->reuseScratchTextures() && !isRT) {
182 tex->resourcePriv().removeScratchKey();
183 }
184 if (tex) {
185 fStats.incTextureCreates();
186 fStats.incTextureUploads();
187 }
188 return tex;
189 }
190
136 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { 191 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) {
137 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); 192 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment());
138 GrUniqueKey sbKey; 193 GrUniqueKey sbKey;
139 194
140 int width = rt->width(); 195 int width = rt->width();
141 int height = rt->height(); 196 int height = rt->height();
142 #if 0 197 #if 0
143 if (this->caps()->oversizedStencilSupport()) { 198 if (this->caps()->oversizedStencilSupport()) {
144 width = SkNextPow2(width); 199 width = SkNextPow2(width);
145 height = SkNextPow2(height); 200 height = SkNextPow2(height);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 //////////////////////////////////////////////////////////////////////////////// 359 ////////////////////////////////////////////////////////////////////////////////
305 360
306 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { 361 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) {
307 this->handleDirtyContext(); 362 this->handleDirtyContext();
308 GrVertices::Iterator iter; 363 GrVertices::Iterator iter;
309 const GrNonInstancedVertices* verts = iter.init(vertices); 364 const GrNonInstancedVertices* verts = iter.init(vertices);
310 do { 365 do {
311 this->onDraw(args, *verts); 366 this->onDraw(args, *verts);
312 } while ((verts = iter.next())); 367 } while ((verts = iter.next()));
313 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698