| 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, const SkTArray<GrMipLevel>
& texels) { | 101 bool* isRT) { |
| 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 } | |
| 133 return true; | 127 return true; |
| 134 } | 128 } |
| 135 | 129 |
| 136 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget
ed, | 130 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget
ed, |
| 137 const SkTArray<GrMipLevel>& texels) { | 131 const SkTArray<GrMipLevel>& texels) { |
| 138 GrSurfaceDesc desc = origDesc; | 132 GrSurfaceDesc desc = origDesc; |
| 139 | 133 |
| 140 const GrCaps* caps = this->caps(); | 134 const GrCaps* caps = this->caps(); |
| 141 bool isRT = false; | 135 bool isRT = false; |
| 142 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc,
&isRT, texels); | 136 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc,
&isRT); |
| 143 if (!textureCreationParamsValid) { | 137 if (!textureCreationParamsValid) { |
| 144 return nullptr; | 138 return nullptr; |
| 145 } | 139 } |
| 146 | 140 |
| 147 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); | 141 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
| 148 // Attempt to catch un- or wrongly intialized sample counts; | 142 // Attempt to catch un- or wrongly intialized sample counts; |
| 149 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | 143 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 150 | 144 |
| 151 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | 145 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 152 | 146 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 178 fStats.incTextureCreates(); | 172 fStats.incTextureCreates(); |
| 179 if (!texels.empty()) { | 173 if (!texels.empty()) { |
| 180 if (texels[0].fPixels) { | 174 if (texels[0].fPixels) { |
| 181 fStats.incTextureUploads(); | 175 fStats.incTextureUploads(); |
| 182 } | 176 } |
| 183 } | 177 } |
| 184 } | 178 } |
| 185 return tex; | 179 return tex; |
| 186 } | 180 } |
| 187 | 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 |
| 188 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { | 193 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { |
| 189 this->handleDirtyContext(); | 194 this->handleDirtyContext(); |
| 190 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 195 if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
| 191 return nullptr; | 196 return nullptr; |
| 192 } | 197 } |
| 193 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && | 198 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && |
| 194 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 199 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 195 return nullptr; | 200 return nullptr; |
| 196 } | 201 } |
| 197 int maxSize = this->caps()->maxTextureSize(); | 202 int maxSize = this->caps()->maxTextureSize(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 config, buffer, | 384 config, buffer, |
| 380 rowBytes); | 385 rowBytes); |
| 381 } | 386 } |
| 382 | 387 |
| 383 bool GrGpu::writePixels(GrSurface* surface, | 388 bool GrGpu::writePixels(GrSurface* surface, |
| 384 int left, int top, int width, int height, | 389 int left, int top, int width, int height, |
| 385 GrPixelConfig config, const SkTArray<GrMipLevel>& texels
) { | 390 GrPixelConfig config, const SkTArray<GrMipLevel>& texels
) { |
| 386 if (!surface) { | 391 if (!surface) { |
| 387 return false; | 392 return false; |
| 388 } | 393 } |
| 394 bool validMipDataFound = false; |
| 389 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe
vel++) { | 395 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe
vel++) { |
| 390 if (!texels[currentMipLevel].fPixels ) { | 396 if (texels[currentMipLevel].fPixels != nullptr) { |
| 391 return false; | 397 validMipDataFound = true; |
| 398 break; |
| 392 } | 399 } |
| 393 } | 400 } |
| 401 if (!validMipDataFound) { |
| 402 return false; |
| 403 } |
| 394 | 404 |
| 395 this->handleDirtyContext(); | 405 this->handleDirtyContext(); |
| 396 if (this->onWritePixels(surface, left, top, width, height, config, texels))
{ | 406 if (this->onWritePixels(surface, left, top, width, height, config, texels))
{ |
| 397 fStats.incTextureUploads(); | 407 fStats.incTextureUploads(); |
| 398 return true; | 408 return true; |
| 399 } | 409 } |
| 400 return false; | 410 return false; |
| 401 } | 411 } |
| 402 | 412 |
| 403 bool GrGpu::writePixels(GrSurface* surface, | 413 bool GrGpu::writePixels(GrSurface* surface, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 453 } |
| 444 | 454 |
| 445 GrVertices::Iterator iter; | 455 GrVertices::Iterator iter; |
| 446 const GrNonInstancedVertices* verts = iter.init(vertices); | 456 const GrNonInstancedVertices* verts = iter.init(vertices); |
| 447 do { | 457 do { |
| 448 this->onDraw(args, *verts); | 458 this->onDraw(args, *verts); |
| 449 fStats.incNumDraws(); | 459 fStats.incNumDraws(); |
| 450 } while ((verts = iter.next())); | 460 } while ((verts = iter.next())); |
| 451 } | 461 } |
| 452 | 462 |
| OLD | NEW |