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

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 rebase errors and cleaning up. Created 4 years, 10 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 * 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, bool budgeted, 130 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
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;
102 }
103
104 // We currently do not support multisampled textures
105 if (!isRT && desc.fSampleCnt > 0) {
106 return nullptr;
107 }
108
109 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 = budgeted ? GrGpuResource::kCached_LifeC ycle :
124 GrGpuResource::kUncached_Lif eCycle;
125
126 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
127 // Attempt to catch un- or wrongly initialized sample counts;
128 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); 143 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
129 144
130 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); 145 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
131 146
147 GrTexture* tex = nullptr;
148 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle :
149 GrGpuResource::kUncached_Lif eCycle;
150
132 if (GrPixelConfigIsCompressed(desc.fConfig)) { 151 if (GrPixelConfigIsCompressed(desc.fConfig)) {
133 // We shouldn't be rendering into this 152 // We shouldn't be rendering into this
134 SkASSERT(!isRT); 153 SkASSERT(!isRT);
135 SkASSERT(0 == desc.fSampleCnt); 154 SkASSERT(0 == desc.fSampleCnt);
136 155
137 if (!this->caps()->npotTextureTileSupport() && 156 if (!caps->npotTextureTileSupport() &&
138 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { 157 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
139 return nullptr; 158 return nullptr;
140 } 159 }
141 160
142 this->handleDirtyContext(); 161 this->handleDirtyContext();
143 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); 162 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
144 } else { 163 } else {
145 this->handleDirtyContext(); 164 this->handleDirtyContext();
146 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); 165 tex = this->onCreateTexture(desc, lifeCycle, texels);
147 }
148 if (!this->caps()->reuseScratchTextures() && !isRT) {
149 tex->resourcePriv().removeScratchKey();
150 } 166 }
151 if (tex) { 167 if (tex) {
168 if (!caps->reuseScratchTextures() && !isRT) {
169 tex->resourcePriv().removeScratchKey();
170 }
152 fStats.incTextureCreates(); 171 fStats.incTextureCreates();
153 if (srcData) { 172 if (!texels.empty()) {
154 fStats.incTextureUploads(); 173 if (texels[0].fPixels) {
174 fStats.incTextureUploads();
175 }
155 } 176 }
156 } 177 }
157 return tex; 178 return tex;
158 } 179 }
159 180
181 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
182 const void* srcData, size_t rowBytes) {
183 GrMipLevel level;
184 level.fPixels = srcData;
185 level.fRowBytes = rowBytes;
186 SkSTArray<1, GrMipLevel> levels;
187 levels.push_back(level);
188
189 return this->createTexture(desc, budgeted, levels);
190 }
191
160 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { 192 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) {
161 this->handleDirtyContext(); 193 this->handleDirtyContext();
162 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 194 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
163 return nullptr; 195 return nullptr;
164 } 196 }
165 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && 197 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
166 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 198 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
167 return nullptr; 199 return nullptr;
168 } 200 }
169 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); 201 GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 359 }
328 360
329 return this->onReadPixels(surface, 361 return this->onReadPixels(surface,
330 left, top, width, height, 362 left, top, width, height,
331 config, buffer, 363 config, buffer,
332 rowBytes); 364 rowBytes);
333 } 365 }
334 366
335 bool GrGpu::writePixels(GrSurface* surface, 367 bool GrGpu::writePixels(GrSurface* surface,
336 int left, int top, int width, int height, 368 int left, int top, int width, int height,
337 GrPixelConfig config, const void* buffer, 369 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) {
338 size_t rowBytes) { 370 if (!surface) {
339 if (!buffer || !surface) { 371 return false;
372 }
373 bool validMipDataFound = false;
374 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) {
375 if (texels[currentMipLevel].fPixels != nullptr) {
376 validMipDataFound = true;
377 break;
378 }
379 }
380 if (!validMipDataFound) {
340 return false; 381 return false;
341 } 382 }
342 383
343 this->handleDirtyContext(); 384 this->handleDirtyContext();
344 if (this->onWritePixels(surface, left, top, width, height, config, buffer, r owBytes)) { 385 if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
345 fStats.incTextureUploads(); 386 fStats.incTextureUploads();
346 return true; 387 return true;
347 } 388 }
348 return false; 389 return false;
349 } 390 }
350 391
392 bool GrGpu::writePixels(GrSurface* surface,
393 int left, int top, int width, int height,
394 GrPixelConfig config, const void* buffer,
395 size_t rowBytes) {
396 GrMipLevel mipLevel;
397 mipLevel.fPixels = buffer;
398 mipLevel.fRowBytes = rowBytes;
399 SkSTArray<1, GrMipLevel> texels;
400 texels.push_back(mipLevel);
401
402 return this->writePixels(surface, left, top, width, height, config, texels);
403 }
404
351 bool GrGpu::transferPixels(GrSurface* surface, 405 bool GrGpu::transferPixels(GrSurface* surface,
352 int left, int top, int width, int height, 406 int left, int top, int width, int height,
353 GrPixelConfig config, GrTransferBuffer* buffer, 407 GrPixelConfig config, GrTransferBuffer* buffer,
354 size_t offset, size_t rowBytes) { 408 size_t offset, size_t rowBytes) {
355 SkASSERT(buffer); 409 SkASSERT(buffer);
356 410
357 this->handleDirtyContext(); 411 this->handleDirtyContext();
358 if (this->onTransferPixels(surface, left, top, width, height, config, 412 if (this->onTransferPixels(surface, left, top, width, height, config,
359 buffer, offset, rowBytes)) { 413 buffer, offset, rowBytes)) {
360 fStats.incTransfersToTexture(); 414 fStats.incTransfersToTexture();
(...skipping 17 matching lines...) Expand all
378 } 432 }
379 433
380 GrVertices::Iterator iter; 434 GrVertices::Iterator iter;
381 const GrNonInstancedVertices* verts = iter.init(vertices); 435 const GrNonInstancedVertices* verts = iter.init(vertices);
382 do { 436 do {
383 this->onDraw(args, *verts); 437 this->onDraw(args, *verts);
384 fStats.incNumDraws(); 438 fStats.incNumDraws();
385 } while ((verts = iter.next())); 439 } while ((verts = iter.next()));
386 } 440 }
387 441
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698