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

Side by Side Diff: src/gpu/GrTextureProvider.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.cpp ('k') | src/gpu/gl/GrGLGpu.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 2015 Google Inc. 2 * Copyright 2015 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 #include "GrTextureProvider.h" 8 #include "GrTextureProvider.h"
9 #include "GrTexturePriv.h" 9 #include "GrTexturePriv.h"
10 #include "GrResourceCache.h" 10 #include "GrResourceCache.h"
(...skipping 19 matching lines...) Expand all
30 { 30 {
31 } 31 }
32 32
33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, 33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
34 const GrMipLevel* texels, i nt mipLevelCount) { 34 const GrMipLevel* texels, i nt mipLevelCount) {
35 ASSERT_SINGLE_OWNER 35 ASSERT_SINGLE_OWNER
36 36
37 if (this->isAbandoned()) { 37 if (this->isAbandoned()) {
38 return nullptr; 38 return nullptr;
39 } 39 }
40 if (mipLevelCount && !texels) {
41 return nullptr;
42 }
43 for (int i = 0; i < mipLevelCount; ++i) {
44 if (!texels[i].fPixels) {
45 return nullptr;
46 }
47 }
48
40 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && 49 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
41 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 50 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
42 return nullptr; 51 return nullptr;
43 } 52 }
44 if (!GrPixelConfigIsCompressed(desc.fConfig) && 53 if (!GrPixelConfigIsCompressed(desc.fConfig) &&
45 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { 54 !desc.fTextureStorageAllocator.fAllocateTextureStorage) {
46 if (mipLevelCount < 2) { 55 if (mipLevelCount < 2) {
47 const GrMipLevel& baseMipLevel = texels[0]; 56 const GrMipLevel& baseMipLevel = texels[0];
48 static const uint32_t kFlags = kExact_ScratchTextureFlag | 57 static const uint32_t kFlags = kExact_ScratchTextureFlag |
49 kNoCreate_ScratchTextureFlag; 58 kNoCreate_ScratchTextureFlag;
50 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { 59 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
51 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f Config, 60 if (!texels || texture->writePixels(0, 0, desc.fWidth, desc.fHei ght, desc.fConfig,
52 baseMipLevel.fPixels, baseMipLevel.fRow Bytes)) { 61 baseMipLevel.fPixels, baseMi pLevel.fRowBytes)) {
53 if (SkBudgeted::kNo == budgeted) { 62 if (SkBudgeted::kNo == budgeted) {
54 texture->resourcePriv().makeUnbudgeted(); 63 texture->resourcePriv().makeUnbudgeted();
55 } 64 }
56 return texture; 65 return texture;
57 } 66 }
58 texture->unref(); 67 texture->unref();
59 } 68 }
60 } 69 }
61 } 70 }
62 71
63 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); 72 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount);
64 for (int i = 0; i < mipLevelCount; ++i) { 73 for (int i = 0; i < mipLevelCount; ++i) {
65 texelsShallowCopy.push_back(texels[i]); 74 texelsShallowCopy.push_back(texels[i]);
66 } 75 }
67 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); 76 return fGpu->createTexture(desc, budgeted, texelsShallowCopy);
68 } 77 }
69 78
70 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete d budgeted, 79 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete d budgeted,
71 const void* srcData, size_t rowBytes ) { 80 const void* srcData, size_t rowBytes ) {
72 const int mipLevelCount = 1; 81 GrMipLevel tempTexels;
73 GrMipLevel texels[mipLevelCount]; 82 GrMipLevel* texels = nullptr;
74 texels[0].fPixels = srcData; 83 int levelCount = 0;
75 texels[0].fRowBytes = rowBytes; 84 if (srcData) {
76 85 tempTexels.fPixels = srcData;
77 return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); 86 tempTexels.fRowBytes = rowBytes;
87 texels = &tempTexels;
88 levelCount = 1;
89 }
90 return this->createMipMappedTexture(desc, budgeted, texels, levelCount);
78 } 91 }
79 92
80 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { 93 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
81 ASSERT_SINGLE_OWNER 94 ASSERT_SINGLE_OWNER
82 return this->internalCreateApproxTexture(desc, 0); 95 return this->internalCreateApproxTexture(desc, 0);
83 } 96 }
84 97
85 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc, 98 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc,
86 uint32_t scratchFlags) { 99 uint32_t scratchFlags) {
87 ASSERT_SINGLE_OWNER 100 ASSERT_SINGLE_OWNER
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 GrSurface* surface = static_cast<GrSurface*>(resource); 143 GrSurface* surface = static_cast<GrSurface*>(resource);
131 GrRenderTarget* rt = surface->asRenderTarget(); 144 GrRenderTarget* rt = surface->asRenderTarget();
132 if (rt && fGpu->caps()->discardRenderTargetSupport()) { 145 if (rt && fGpu->caps()->discardRenderTargetSupport()) {
133 rt->discard(); 146 rt->discard();
134 } 147 }
135 return surface->asTexture(); 148 return surface->asTexture();
136 } 149 }
137 } 150 }
138 151
139 if (!(kNoCreate_ScratchTextureFlag & flags)) { 152 if (!(kNoCreate_ScratchTextureFlag & flags)) {
140 return fGpu->createTexture(*desc, SkBudgeted::kYes, nullptr, 0); 153 return fGpu->createTexture(*desc, SkBudgeted::kYes);
141 } 154 }
142 155
143 return nullptr; 156 return nullptr;
144 } 157 }
145 158
146 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c, 159 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c,
147 GrWrapOwnership ownership) { 160 GrWrapOwnership ownership) {
148 ASSERT_SINGLE_OWNER 161 ASSERT_SINGLE_OWNER
149 if (this->isAbandoned()) { 162 if (this->isAbandoned()) {
150 return nullptr; 163 return nullptr;
(...skipping 28 matching lines...) Expand all
179 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke y) { 192 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke y) {
180 ASSERT_SINGLE_OWNER 193 ASSERT_SINGLE_OWNER
181 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); 194 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
182 if (resource) { 195 if (resource) {
183 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); 196 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
184 SkASSERT(texture); 197 SkASSERT(texture);
185 return texture; 198 return texture;
186 } 199 }
187 return NULL; 200 return NULL;
188 } 201 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/gl/GrGLGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698