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

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

Issue 1765633002: Don't allow nullptr in texels array params (unless using a transfer buffer). (Closed) Base URL: https://skia.googlesource.com/skia@usesdk
Patch Set: Upload again in case prev didn't work 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/GrTextureProvider.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 * 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
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 /** 93 /**
94 * Prior to creating a texture, make sure the type of texture being created is 94 * Prior to creating a texture, make sure the type of texture being created is
95 * supported by calling check_texture_creation_params. 95 * supported by calling check_texture_creation_params.
96 * 96 *
97 * @param caps The capabilities of the GL device. 97 * @param caps The capabilities of the GL device.
98 * @param desc The descriptor of the texture to create. 98 * @param desc The descriptor of the texture to create.
99 * @param isRT Indicates if the texture can be a render target. 99 * @param isRT Indicates if the texture can be a render target.
100 */ 100 */
101 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc, 101 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc,
102 bool* isRT) { 102 bool* isRT, const SkTArray<GrMipLevel> & texels) {
103 if (!caps.isConfigTexturable(desc.fConfig)) { 103 if (!caps.isConfigTexturable(desc.fConfig)) {
104 return false; 104 return false;
105 } 105 }
106 106
107 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 107 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
108 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 108 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
109 return false; 109 return false;
110 } 110 }
111 111
112 // We currently do not support multisampled textures 112 // We currently do not support multisampled textures
113 if (!*isRT && desc.fSampleCnt > 0) { 113 if (!*isRT && desc.fSampleCnt > 0) {
114 return false; 114 return false;
115 } 115 }
116 116
117 if (*isRT) { 117 if (*isRT) {
118 int maxRTSize = caps.maxRenderTargetSize(); 118 int maxRTSize = caps.maxRenderTargetSize();
119 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { 119 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
120 return false; 120 return false;
121 } 121 }
122 } else { 122 } else {
123 int maxSize = caps.maxTextureSize(); 123 int maxSize = caps.maxTextureSize();
124 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { 124 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
125 return false; 125 return false;
126 } 126 }
127 } 127 }
128
129 for (int i = 0; i < texels.count(); ++i) {
130 if (!texels[i].fPixels) {
131 return false;
132 }
133 }
128 return true; 134 return true;
129 } 135 }
130 136
131 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed, 137 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed,
132 const SkTArray<GrMipLevel>& texels) { 138 const SkTArray<GrMipLevel>& texels) {
133 GrSurfaceDesc desc = origDesc; 139 GrSurfaceDesc desc = origDesc;
134 140
135 const GrCaps* caps = this->caps(); 141 const GrCaps* caps = this->caps();
136 bool isRT = false; 142 bool isRT = false;
137 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT); 143 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT, texels);
138 if (!textureCreationParamsValid) { 144 if (!textureCreationParamsValid) {
139 return nullptr; 145 return nullptr;
140 } 146 }
141 147
142 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); 148 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
143 // Attempt to catch un- or wrongly intialized sample counts; 149 // Attempt to catch un- or wrongly intialized sample counts;
144 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); 150 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
145 151
146 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); 152 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
147 153
(...skipping 25 matching lines...) Expand all
173 fStats.incTextureCreates(); 179 fStats.incTextureCreates();
174 if (!texels.empty()) { 180 if (!texels.empty()) {
175 if (texels[0].fPixels) { 181 if (texels[0].fPixels) {
176 fStats.incTextureUploads(); 182 fStats.incTextureUploads();
177 } 183 }
178 } 184 }
179 } 185 }
180 return tex; 186 return tex;
181 } 187 }
182 188
183 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
184 const void* srcData, size_t rowBytes) {
185 GrMipLevel level;
186 level.fPixels = srcData;
187 level.fRowBytes = rowBytes;
188 SkSTArray<1, GrMipLevel> levels;
189 levels.push_back(level);
190
191 return this->createTexture(desc, budgeted, levels);
192 }
193
194 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { 189 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) {
195 this->handleDirtyContext(); 190 this->handleDirtyContext();
196 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 191 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
197 return nullptr; 192 return nullptr;
198 } 193 }
199 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && 194 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
200 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 195 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
201 return nullptr; 196 return nullptr;
202 } 197 }
203 int maxSize = this->caps()->maxTextureSize(); 198 int maxSize = this->caps()->maxTextureSize();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 config, buffer, 380 config, buffer,
386 rowBytes); 381 rowBytes);
387 } 382 }
388 383
389 bool GrGpu::writePixels(GrSurface* surface, 384 bool GrGpu::writePixels(GrSurface* surface,
390 int left, int top, int width, int height, 385 int left, int top, int width, int height,
391 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) { 386 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) {
392 if (!surface) { 387 if (!surface) {
393 return false; 388 return false;
394 } 389 }
395 bool validMipDataFound = false;
396 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) { 390 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) {
397 if (texels[currentMipLevel].fPixels != nullptr) { 391 if (!texels[currentMipLevel].fPixels ) {
398 validMipDataFound = true; 392 return false;
399 break;
400 } 393 }
401 } 394 }
402 if (!validMipDataFound) {
403 return false;
404 }
405 395
406 this->handleDirtyContext(); 396 this->handleDirtyContext();
407 if (this->onWritePixels(surface, left, top, width, height, config, texels)) { 397 if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
408 fStats.incTextureUploads(); 398 fStats.incTextureUploads();
409 return true; 399 return true;
410 } 400 }
411 return false; 401 return false;
412 } 402 }
413 403
414 bool GrGpu::writePixels(GrSurface* surface, 404 bool GrGpu::writePixels(GrSurface* surface,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 499 }
510 500
511 GrVertices::Iterator iter; 501 GrVertices::Iterator iter;
512 const GrNonInstancedVertices* verts = iter.init(vertices); 502 const GrNonInstancedVertices* verts = iter.init(vertices);
513 do { 503 do {
514 this->onDraw(args, *verts); 504 this->onDraw(args, *verts);
515 fStats.incNumDraws(); 505 fStats.incNumDraws();
516 } while ((verts = iter.next())); 506 } while ((verts = iter.next()));
517 } 507 }
518 508
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrTextureProvider.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698