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

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: Fixing incorrect rebase. Created 5 years, 2 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
2 /* 1 /*
3 * Copyright 2010 Google Inc. 2 * Copyright 2010 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 8
10 #include "GrGpu.h" 9 #include "GrGpu.h"
11 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // By default, GrRenderTargets are GL's normal orientation so that they 58 // By default, GrRenderTargets are GL's normal orientation so that they
60 // can be drawn to by the outside world without the client having 59 // can be drawn to by the outside world without the client having
61 // to render upside down. 60 // to render upside down.
62 if (kDefault_GrSurfaceOrigin == origin) { 61 if (kDefault_GrSurfaceOrigin == origin) {
63 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; 62 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
64 } else { 63 } else {
65 return origin; 64 return origin;
66 } 65 }
67 } 66 }
68 67
69 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, 68 /**
70 const void* srcData, size_t rowBytes) { 69 * Prior to creating a texture, make sure the type of texture being created is
71 GrSurfaceDesc desc = origDesc; 70 * supported by calling check_texture_creation_params.
72 71 *
73 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 72 * @param caps The capabilities of the GL device.
74 return nullptr; 73 * @param desc The descriptor of the texture to create.
74 * @param isRT Indicates if the texture can be a render target.
75 */
76 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc,
77 bool* isRT) {
78 if (!caps.isConfigTexturable(desc.fConfig)) {
79 return false;
75 } 80 }
76 81
77 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 82 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
78 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 83 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
79 return nullptr; 84 return false;
80 } 85 }
81 86
82 // We currently do not support multisampled textures 87 // We currently do not support multisampled textures
83 if (!isRT && desc.fSampleCnt > 0) { 88 if (!*isRT && desc.fSampleCnt > 0) {
84 return nullptr; 89 return false;
85 } 90 }
86 91
87 GrTexture *tex = nullptr; 92 if (*isRT) {
88 93 int maxRTSize = caps.maxRenderTargetSize();
89 if (isRT) {
90 int maxRTSize = this->caps()->maxRenderTargetSize();
91 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { 94 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
92 return nullptr; 95 return false;
93 } 96 }
94 } else { 97 } else {
95 int maxSize = this->caps()->maxTextureSize(); 98 int maxSize = caps.maxTextureSize();
96 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { 99 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
97 return nullptr; 100 return false;
98 } 101 }
99 } 102 }
103 return true;
104 }
100 105
101 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle : 106 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
102 GrGpuResource::kUncached_Lif eCycle; 107 const SkTArray<SkMipMapLevel>& texels) {
108 GrSurfaceDesc desc = origDesc;
103 109
104 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); 110 const GrCaps* caps = this->caps();
105 // Attempt to catch un- or wrongly initialized sample counts; 111 if (!caps) {
106 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); 112 return nullptr;
107 113 } else {
108 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); 114 bool isRT = false;
109 115 bool textureCreationParamsValid = check_texture_creation_params(*caps, d esc, &isRT);
110 if (GrPixelConfigIsCompressed(desc.fConfig)) { 116 if (!textureCreationParamsValid) {
111 // We shouldn't be rendering into this
112 SkASSERT(!isRT);
113 SkASSERT(0 == desc.fSampleCnt);
114
115 if (!this->caps()->npotTextureTileSupport() &&
116 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
117 return nullptr; 117 return nullptr;
118 } 118 }
119 119
120 this->handleDirtyContext(); 120 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
121 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); 121 // Attempt to catch un- or wrongly intialized sample counts;
122 } else { 122 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
123 this->handleDirtyContext(); 123
124 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); 124 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
125
126 GrTexture* tex = nullptr;
127 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_L ifeCycle :
128 GrGpuResource::kUncached _LifeCycle;
129
130 if (GrPixelConfigIsCompressed(desc.fConfig)) {
131 // We shouldn't be rendering into this
132 SkASSERT(!isRT);
133 SkASSERT(0 == desc.fSampleCnt);
134
135 if (!caps->npotTextureTileSupport() &&
136 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
137 return nullptr;
138 }
139
140 this->handleDirtyContext();
141 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
142 } else {
143 this->handleDirtyContext();
144 tex = this->onCreateTexture(desc, lifeCycle, texels);
145 }
146 if (tex) {
147 if (!caps->reuseScratchTextures() && !isRT) {
148 tex->resourcePriv().removeScratchKey();
149 }
150 fStats.incTextureCreates();
151 if (!texels.empty()) {
152 if (texels[0].fTexels) {
153 fStats.incTextureUploads();
154 }
155 }
156 }
157 return tex;
125 } 158 }
126 if (!this->caps()->reuseScratchTextures() && !isRT) { 159 }
127 tex->resourcePriv().removeScratchKey(); 160
161 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
162 const void* srcData, size_t rowBytes) {
163 const int width = desc.fWidth;
164 const int height = desc.fHeight;
165 if (width < 0 || height < 0) {
bsalomon 2015/09/30 18:01:29 <= 0?
cblume 2015/10/08 09:27:57 Done.
166 return nullptr;
128 } 167 }
129 if (tex) { 168 const uint32_t baseLevelWidth = width;
130 fStats.incTextureCreates(); 169 const uint32_t baseLevelHeight = height;
131 if (srcData) { 170
132 fStats.incTextureUploads(); 171 SkMipMapLevel level(srcData, rowBytes, baseLevelWidth, baseLevelHeight);
133 } 172 const int mipLevelCount = 1;
134 } 173 SkTArray<SkMipMapLevel> levels(mipLevelCount);
135 return tex; 174 levels.push_back(level);
175
176 return this->createTexture(desc, budgeted, levels);
136 } 177 }
137 178
138 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { 179 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) {
139 this->handleDirtyContext(); 180 this->handleDirtyContext();
140 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); 181 GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
141 if (nullptr == tex) { 182 if (nullptr == tex) {
142 return nullptr; 183 return nullptr;
143 } 184 }
144 // TODO: defer this and attach dynamically 185 // TODO: defer this and attach dynamically
145 GrRenderTarget* tgt = tex->asRenderTarget(); 186 GrRenderTarget* tgt = tex->asRenderTarget();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig , false)) { 264 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig , false)) {
224 // If we don't have a fallback to a straight read then fail. 265 // If we don't have a fallback to a straight read then fail.
225 if (kRequireDraw_DrawPreference == *drawPreference) { 266 if (kRequireDraw_DrawPreference == *drawPreference) {
226 return false; 267 return false;
227 } 268 }
228 *drawPreference = kNoDraw_DrawPreference; 269 *drawPreference = kNoDraw_DrawPreference;
229 } 270 }
230 271
231 return true; 272 return true;
232 } 273 }
233 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, siz e_t rowBytes, 274 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
234 GrPixelConfig srcConfig, DrawPreference* drawPref erence, 275 GrPixelConfig srcConfig, DrawPreference* drawPref erence,
235 WritePixelTempDrawInfo* tempDrawInfo) { 276 WritePixelTempDrawInfo* tempDrawInfo) {
236 SkASSERT(drawPreference); 277 SkASSERT(drawPreference);
237 SkASSERT(tempDrawInfo); 278 SkASSERT(tempDrawInfo);
238 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); 279 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
239 280
240 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && 281 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) &&
241 dstSurface->desc().fConfig != srcConfig) { 282 dstSurface->desc().fConfig != srcConfig) {
242 return false; 283 return false;
243 } 284 }
244 285
245 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && 286 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() &&
246 SkToBool(dstSurface->asRenderTarget()) && 287 SkToBool(dstSurface->asRenderTarget()) &&
247 (width < dstSurface->width() || height < dstSurface->height())) { 288 (width < dstSurface->width() || height < dstSurface->height())) {
248 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 289 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
249 } 290 }
250 291
251 if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConf ig, drawPreference, 292 if (!this->onGetWritePixelsInfo(dstSurface, width, height, srcConfig, drawPr eference,
252 tempDrawInfo)) { 293 tempDrawInfo)) {
253 return false; 294 return false;
254 } 295 }
255 296
256 // Check to see if we're going to request that the caller draw when drawing is not possible. 297 // Check to see if we're going to request that the caller draw when drawing is not possible.
257 if (!dstSurface->asRenderTarget() || 298 if (!dstSurface->asRenderTarget() ||
258 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig )) { 299 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig )) {
259 // If we don't have a fallback to a straight upload then fail. 300 // If we don't have a fallback to a straight upload then fail.
260 if (kRequireDraw_DrawPreference == *drawPreference || 301 if (kRequireDraw_DrawPreference == *drawPreference ||
261 !this->caps()->isConfigTexturable(srcConfig)) { 302 !this->caps()->isConfigTexturable(srcConfig)) {
(...skipping 24 matching lines...) Expand all
286 } 327 }
287 328
288 return this->onReadPixels(surface, 329 return this->onReadPixels(surface,
289 left, top, width, height, 330 left, top, width, height,
290 config, buffer, 331 config, buffer,
291 rowBytes); 332 rowBytes);
292 } 333 }
293 334
294 bool GrGpu::writePixels(GrSurface* surface, 335 bool GrGpu::writePixels(GrSurface* surface,
295 int left, int top, int width, int height, 336 int left, int top, int width, int height,
296 GrPixelConfig config, const void* buffer, 337 GrPixelConfig config, const SkTArray<SkMipMapLevel>& tex els) {
297 size_t rowBytes) {
298 if (!buffer) {
299 return false;
300 }
301
302 this->handleDirtyContext(); 338 this->handleDirtyContext();
303 if (this->onWritePixels(surface, left, top, width, height, config, buffer, r owBytes)) { 339 if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
304 fStats.incTextureUploads(); 340 fStats.incTextureUploads();
305 return true; 341 return true;
306 } 342 }
307 return false; 343 return false;
308 } 344 }
309 345
346 bool GrGpu::writePixels(GrSurface* surface,
347 int left, int top, int width, int height,
348 GrPixelConfig config, const void* buffer,
349 size_t rowBytes) {
350 if (width < 0 || height < 0) {
bsalomon 2015/09/30 18:01:29 <= 0?
cblume 2015/10/08 09:27:57 Done.
351 return false;
352 }
353 const uint32_t baseLevelWidth = width;
354 const uint32_t baseLevelHeight = height;
355
356 SkMipMapLevel mipLevel(buffer, rowBytes, baseLevelWidth, baseLevelHeight);
357 const int mipLevelCount = 1;
358 SkTArray<SkMipMapLevel> texels(mipLevelCount);
359 texels.push_back(mipLevel);
360
361 return this->writePixels(surface, left, top, width, height, config, texels);
362 }
363
310 void GrGpu::resolveRenderTarget(GrRenderTarget* target) { 364 void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
311 SkASSERT(target); 365 SkASSERT(target);
312 this->handleDirtyContext(); 366 this->handleDirtyContext();
313 this->onResolveRenderTarget(target); 367 this->onResolveRenderTarget(target);
314 } 368 }
315 369
316 //////////////////////////////////////////////////////////////////////////////// 370 ////////////////////////////////////////////////////////////////////////////////
317 371
318 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { 372 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) {
319 this->handleDirtyContext(); 373 this->handleDirtyContext();
320 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c aps())) { 374 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c aps())) {
321 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); 375 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType);
322 } 376 }
323 377
324 GrVertices::Iterator iter; 378 GrVertices::Iterator iter;
325 const GrNonInstancedVertices* verts = iter.init(vertices); 379 const GrNonInstancedVertices* verts = iter.init(vertices);
326 do { 380 do {
327 this->onDraw(args, *verts); 381 this->onDraw(args, *verts);
328 fStats.incNumDraws(); 382 fStats.incNumDraws();
329 } while ((verts = iter.next())); 383 } while ((verts = iter.next()));
330 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698