Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Prior to creating a texture, make sure the type of texture being created is | 93 * Prior to creating a texture, make sure the type of texture being created is |
| 94 * supported by calling check_texture_creation_params. | 94 * supported by calling check_texture_creation_params. |
| 95 * | 95 * |
| 96 * @param caps The capabilities of the GL device. | 96 * @param caps The capabilities of the GL device. |
| 97 * @param desc The descriptor of the texture to create. | 97 * @param desc The descriptor of the texture to create. |
| 98 * @param isRT Indicates if the texture can be a render target. | 98 * @param isRT Indicates if the texture can be a render target. |
| 99 */ | 99 */ |
| 100 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc, | 100 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc, |
| 101 bool* isRT) { | 101 bool* isRT, const SkTArray<GrMipLevel> & texels) { |
| 102 if (!caps.isConfigTexturable(desc.fConfig)) { | 102 if (!caps.isConfigTexturable(desc.fConfig)) { |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 106 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 107 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 107 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // We currently do not support multisampled textures | 111 // We currently do not support multisampled textures |
| 112 if (!*isRT && desc.fSampleCnt > 0) { | 112 if (!*isRT && desc.fSampleCnt > 0) { |
| 113 return false; | 113 return false; |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (*isRT) { | 116 if (*isRT) { |
| 117 int maxRTSize = caps.maxRenderTargetSize(); | 117 int maxRTSize = caps.maxRenderTargetSize(); |
| 118 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | 118 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 } else { | 121 } else { |
| 122 int maxSize = caps.maxTextureSize(); | 122 int maxSize = caps.maxTextureSize(); |
| 123 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 123 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | |
| 128 for (int i = 0; i < texels.count(); ++i) { | |
| 129 if (!texels[i].fPixels) { | |
| 130 return false; | |
| 131 } | |
| 132 } | |
| 127 return true; | 133 return true; |
| 128 } | 134 } |
| 129 | 135 |
| 130 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed, | 136 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget ed, |
| 131 const SkTArray<GrMipLevel>& texels) { | 137 const SkTArray<GrMipLevel>& texels) { |
| 138 | |
| 132 GrSurfaceDesc desc = origDesc; | 139 GrSurfaceDesc desc = origDesc; |
| 133 | 140 |
| 134 const GrCaps* caps = this->caps(); | 141 const GrCaps* caps = this->caps(); |
| 135 bool isRT = false; | 142 bool isRT = false; |
| 136 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT); | 143 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT, texels); |
| 137 if (!textureCreationParamsValid) { | 144 if (!textureCreationParamsValid) { |
| 138 return nullptr; | 145 return nullptr; |
| 139 } | 146 } |
| 140 | 147 |
| 141 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); | 148 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
| 142 // Attempt to catch un- or wrongly intialized sample counts; | 149 // Attempt to catch un- or wrongly intialized sample counts; |
| 143 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | 150 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 144 | 151 |
| 145 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | 152 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 146 | 153 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 174 if (texels[0].fPixels) { | 181 if (texels[0].fPixels) { |
| 175 fStats.incTextureUploads(); | 182 fStats.incTextureUploads(); |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 return tex; | 186 return tex; |
| 180 } | 187 } |
| 181 | 188 |
| 182 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, | 189 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
| 183 const void* srcData, size_t rowBytes) { | 190 const void* srcData, size_t rowBytes) { |
| 184 GrMipLevel level; | 191 return this->createTexture(desc, budgeted, SkTArray<GrMipLevel>()); |
|
cblume
2016/03/03 22:54:46
I'm not sure I understand this bit.
Won't this be
bsalomon
2016/03/03 23:02:40
Oops, I fixed this locally but uploaded without. W
| |
| 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 } |
| 192 | 193 |
| 193 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { | 194 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { |
| 194 this->handleDirtyContext(); | 195 this->handleDirtyContext(); |
| 195 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 196 if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
| 196 return nullptr; | 197 return nullptr; |
| 197 } | 198 } |
| 198 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && | 199 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && |
| 199 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 200 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 200 return nullptr; | 201 return nullptr; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 config, buffer, | 385 config, buffer, |
| 385 rowBytes); | 386 rowBytes); |
| 386 } | 387 } |
| 387 | 388 |
| 388 bool GrGpu::writePixels(GrSurface* surface, | 389 bool GrGpu::writePixels(GrSurface* surface, |
| 389 int left, int top, int width, int height, | 390 int left, int top, int width, int height, |
| 390 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) { | 391 GrPixelConfig config, const SkTArray<GrMipLevel>& texels ) { |
| 391 if (!surface) { | 392 if (!surface) { |
| 392 return false; | 393 return false; |
| 393 } | 394 } |
| 394 bool validMipDataFound = false; | |
| 395 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) { | 395 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) { |
| 396 if (texels[currentMipLevel].fPixels != nullptr) { | 396 if (!texels[currentMipLevel].fPixels ) { |
| 397 validMipDataFound = true; | 397 return false; |
| 398 break; | |
| 399 } | 398 } |
| 400 } | 399 } |
| 401 if (!validMipDataFound) { | |
| 402 return false; | |
| 403 } | |
| 404 | 400 |
| 405 this->handleDirtyContext(); | 401 this->handleDirtyContext(); |
| 406 if (this->onWritePixels(surface, left, top, width, height, config, texels)) { | 402 if (this->onWritePixels(surface, left, top, width, height, config, texels)) { |
| 407 fStats.incTextureUploads(); | 403 fStats.incTextureUploads(); |
| 408 return true; | 404 return true; |
| 409 } | 405 } |
| 410 return false; | 406 return false; |
| 411 } | 407 } |
| 412 | 408 |
| 413 bool GrGpu::writePixels(GrSurface* surface, | 409 bool GrGpu::writePixels(GrSurface* surface, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 } | 449 } |
| 454 | 450 |
| 455 GrVertices::Iterator iter; | 451 GrVertices::Iterator iter; |
| 456 const GrNonInstancedVertices* verts = iter.init(vertices); | 452 const GrNonInstancedVertices* verts = iter.init(vertices); |
| 457 do { | 453 do { |
| 458 this->onDraw(args, *verts); | 454 this->onDraw(args, *verts); |
| 459 fStats.incNumDraws(); | 455 fStats.incNumDraws(); |
| 460 } while ((verts = iter.next())); | 456 } while ((verts = iter.next())); |
| 461 } | 457 } |
| 462 | 458 |
| OLD | NEW |