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

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: Rebasing. Created 4 years, 9 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/GrImageIDTextureAdjuster.h » ('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 * Copyright 2010 Google Inc. 2 * Copyright 2010 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 10
11 #include "GrCaps.h" 11 #include "GrCaps.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrGpuResourcePriv.h" 13 #include "GrGpuResourcePriv.h"
14 #include "GrIndexBuffer.h" 14 #include "GrIndexBuffer.h"
15 #include "GrPathRendering.h" 15 #include "GrPathRendering.h"
16 #include "GrPipeline.h" 16 #include "GrPipeline.h"
17 #include "GrResourceCache.h" 17 #include "GrResourceCache.h"
18 #include "GrResourceProvider.h" 18 #include "GrResourceProvider.h"
19 #include "GrRenderTargetPriv.h" 19 #include "GrRenderTargetPriv.h"
20 #include "GrStencilAttachment.h" 20 #include "GrStencilAttachment.h"
21 #include "GrSurfacePriv.h" 21 #include "GrSurfacePriv.h"
22 #include "GrTransferBuffer.h" 22 #include "GrTransferBuffer.h"
23 #include "GrVertexBuffer.h" 23 #include "GrVertexBuffer.h"
24 #include "GrVertices.h" 24 #include "GrVertices.h"
25 #include "SkTypes.h"
25 26
26 GrVertices& GrVertices::operator =(const GrVertices& di) { 27 GrVertices& GrVertices::operator =(const GrVertices& di) {
27 fPrimitiveType = di.fPrimitiveType; 28 fPrimitiveType = di.fPrimitiveType;
28 fStartVertex = di.fStartVertex; 29 fStartVertex = di.fStartVertex;
29 fStartIndex = di.fStartIndex; 30 fStartIndex = di.fStartIndex;
30 fVertexCount = di.fVertexCount; 31 fVertexCount = di.fVertexCount;
31 fIndexCount = di.fIndexCount; 32 fIndexCount = di.fIndexCount;
32 33
33 fInstanceCount = di.fInstanceCount; 34 fInstanceCount = di.fInstanceCount;
34 fVerticesPerInstance = di.fVerticesPerInstance; 35 fVerticesPerInstance = di.fVerticesPerInstance;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // By default, GrRenderTargets are GL's normal orientation so that they 82 // By default, GrRenderTargets are GL's normal orientation so that they
82 // can be drawn to by the outside world without the client having 83 // can be drawn to by the outside world without the client having
83 // to render upside down. 84 // to render upside down.
84 if (kDefault_GrSurfaceOrigin == origin) { 85 if (kDefault_GrSurfaceOrigin == origin) {
85 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; 86 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
86 } else { 87 } else {
87 return origin; 88 return origin;
88 } 89 }
89 } 90 }
90 91
92 /**
93 * Prior to creating a texture, make sure the type of texture being created is
94 * supported by calling check_texture_creation_params.
95 *
96 * @param caps The capabilities of the GL device.
97 * @param desc The descriptor of the texture to create.
98 * @param isRT Indicates if the texture can be a render target.
99 */
100 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc,
101 bool* isRT) {
102 if (!caps.isConfigTexturable(desc.fConfig)) {
103 return false;
104 }
105
106 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
107 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
108 return false;
109 }
110
111 // We currently do not support multisampled textures
112 if (!*isRT && desc.fSampleCnt > 0) {
113 return false;
114 }
115
116 if (*isRT) {
117 int maxRTSize = caps.maxRenderTargetSize();
118 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
119 return false;
120 }
121 } else {
122 int maxSize = caps.maxTextureSize();
123 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
124 return false;
125 }
126 }
127 return true;
128 }
129
91 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed, 130 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed,
92 const void* srcData, size_t rowBytes) { 131 const SkTArray<GrMipLevel>& texels) {
93 GrSurfaceDesc desc = origDesc; 132 GrSurfaceDesc desc = origDesc;
94 133
95 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 134 const GrCaps* caps = this->caps();
135 bool isRT = false;
136 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
137 if (!textureCreationParamsValid) {
96 return nullptr; 138 return nullptr;
97 } 139 }
98 140
99 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 141 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
100 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 142 // Attempt to catch un- or wrongly intialized sample counts;
101 return nullptr; 143 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
102 }
103 144
104 // We currently do not support multisampled textures 145 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
105 if (!isRT && desc.fSampleCnt > 0) {
106 return nullptr;
107 }
108 146
109 GrTexture *tex = nullptr; 147 GrTexture* tex = nullptr;
110
111 if (isRT) {
112 int maxRTSize = this->caps()->maxRenderTargetSize();
113 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
114 return nullptr;
115 }
116 } else {
117 int maxSize = this->caps()->maxTextureSize();
118 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
119 return nullptr;
120 }
121 }
122
123 GrGpuResource::LifeCycle lifeCycle = SkBudgeted::kYes == budgeted ? 148 GrGpuResource::LifeCycle lifeCycle = SkBudgeted::kYes == budgeted ?
124 GrGpuResource::kCached_LifeCycle : 149 GrGpuResource::kCached_LifeCycle :
125 GrGpuResource::kUncached_LifeCycle; 150 GrGpuResource::kUncached_LifeCycle;
126 151
127 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
128 // Attempt to catch un- or wrongly initialized sample counts;
129 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
130
131 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
132
133 if (GrPixelConfigIsCompressed(desc.fConfig)) { 152 if (GrPixelConfigIsCompressed(desc.fConfig)) {
134 // We shouldn't be rendering into this 153 // We shouldn't be rendering into this
135 SkASSERT(!isRT); 154 SkASSERT(!isRT);
136 SkASSERT(0 == desc.fSampleCnt); 155 SkASSERT(0 == desc.fSampleCnt);
137 156
138 if (!this->caps()->npotTextureTileSupport() && 157 if (!caps->npotTextureTileSupport() &&
139 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { 158 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
140 return nullptr; 159 return nullptr;
141 } 160 }
142 161
143 this->handleDirtyContext(); 162 this->handleDirtyContext();
144 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); 163 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
145 } else { 164 } else {
146 this->handleDirtyContext(); 165 this->handleDirtyContext();
147 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); 166 tex = this->onCreateTexture(desc, lifeCycle, texels);
148 }
149 if (!this->caps()->reuseScratchTextures() && !isRT) {
150 tex->resourcePriv().removeScratchKey();
151 } 167 }
152 if (tex) { 168 if (tex) {
169 if (!caps->reuseScratchTextures() && !isRT) {
170 tex->resourcePriv().removeScratchKey();
171 }
153 fStats.incTextureCreates(); 172 fStats.incTextureCreates();
154 if (srcData) { 173 if (!texels.empty()) {
155 fStats.incTextureUploads(); 174 if (texels[0].fPixels) {
175 fStats.incTextureUploads();
176 }
156 } 177 }
157 } 178 }
158 return tex; 179 return tex;
159 } 180 }
160 181
182 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
183 const void* srcData, size_t rowBytes) {
184 GrMipLevel level;
185 level.fPixels = srcData;
186 level.fRowBytes = rowBytes;
187 SkSTArray<1, GrMipLevel> levels;
188 levels.push_back(level);
189
190 return this->createTexture(desc, budgeted, levels);
191 }
192
161 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { 193 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) {
162 this->handleDirtyContext(); 194 this->handleDirtyContext();
163 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 195 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
164 return nullptr; 196 return nullptr;
165 } 197 }
166 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && 198 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
167 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 199 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
168 return nullptr; 200 return nullptr;
169 } 201 }
170 int maxSize = this->caps()->maxTextureSize(); 202 int maxSize = this->caps()->maxTextureSize();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 380 }
349 381
350 return this->onReadPixels(surface, 382 return this->onReadPixels(surface,
351 left, top, width, height, 383 left, top, width, height,
352 config, buffer, 384 config, buffer,
353 rowBytes); 385 rowBytes);
354 } 386 }
355 387
356 bool GrGpu::writePixels(GrSurface* surface, 388 bool GrGpu::writePixels(GrSurface* surface,
357 int left, int top, int width, int height, 389 int left, int top, int width, int height,
358 GrPixelConfig config, const void* buffer, 390 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) {
359 size_t rowBytes) { 391 if (!surface) {
360 if (!buffer || !surface) { 392 return false;
393 }
394 bool validMipDataFound = false;
395 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) {
396 if (texels[currentMipLevel].fPixels != nullptr) {
397 validMipDataFound = true;
398 break;
399 }
400 }
401 if (!validMipDataFound) {
361 return false; 402 return false;
362 } 403 }
363 404
364 this->handleDirtyContext(); 405 this->handleDirtyContext();
365 if (this->onWritePixels(surface, left, top, width, height, config, buffer, r owBytes)) { 406 if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
366 fStats.incTextureUploads(); 407 fStats.incTextureUploads();
367 return true; 408 return true;
368 } 409 }
369 return false; 410 return false;
370 } 411 }
371 412
413 bool GrGpu::writePixels(GrSurface* surface,
414 int left, int top, int width, int height,
415 GrPixelConfig config, const void* buffer,
416 size_t rowBytes) {
417 GrMipLevel mipLevel;
418 mipLevel.fPixels = buffer;
419 mipLevel.fRowBytes = rowBytes;
420 SkSTArray<1, GrMipLevel> texels;
421 texels.push_back(mipLevel);
422
423 return this->writePixels(surface, left, top, width, height, config, texels);
424 }
425
372 bool GrGpu::transferPixels(GrSurface* surface, 426 bool GrGpu::transferPixels(GrSurface* surface,
373 int left, int top, int width, int height, 427 int left, int top, int width, int height,
374 GrPixelConfig config, GrTransferBuffer* buffer, 428 GrPixelConfig config, GrTransferBuffer* buffer,
375 size_t offset, size_t rowBytes) { 429 size_t offset, size_t rowBytes) {
376 SkASSERT(buffer); 430 SkASSERT(buffer);
377 431
378 this->handleDirtyContext(); 432 this->handleDirtyContext();
379 if (this->onTransferPixels(surface, left, top, width, height, config, 433 if (this->onTransferPixels(surface, left, top, width, height, config,
380 buffer, offset, rowBytes)) { 434 buffer, offset, rowBytes)) {
381 fStats.incTransfersToTexture(); 435 fStats.incTransfersToTexture();
(...skipping 17 matching lines...) Expand all
399 } 453 }
400 454
401 GrVertices::Iterator iter; 455 GrVertices::Iterator iter;
402 const GrNonInstancedVertices* verts = iter.init(vertices); 456 const GrNonInstancedVertices* verts = iter.init(vertices);
403 do { 457 do {
404 this->onDraw(args, *verts); 458 this->onDraw(args, *verts);
405 fStats.incNumDraws(); 459 fStats.incNumDraws();
406 } while ((verts = iter.next())); 460 } while ((verts = iter.next()));
407 } 461 }
408 462
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrImageIDTextureAdjuster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698