Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 | 8 |
| 10 #include "GrGpu.h" | 9 #include "GrGpu.h" |
| 11 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 // By default, GrRenderTargets are GL's normal orientation so that they | 81 // By default, GrRenderTargets are GL's normal orientation so that they |
| 83 // can be drawn to by the outside world without the client having | 82 // can be drawn to by the outside world without the client having |
| 84 // to render upside down. | 83 // to render upside down. |
| 85 if (kDefault_GrSurfaceOrigin == origin) { | 84 if (kDefault_GrSurfaceOrigin == origin) { |
| 86 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; | 85 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; |
| 87 } else { | 86 } else { |
| 88 return origin; | 87 return origin; |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, | 91 /** |
| 93 const void* srcData, size_t rowBytes) { | 92 * Prior to creating a texture, make sure the type of texture being created is |
| 94 GrSurfaceDesc desc = origDesc; | 93 * supported by calling check_texture_creation_params. |
| 95 | 94 * |
| 96 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 95 * @param caps The capabilities of the GL device. |
| 97 return nullptr; | 96 * @param desc The descriptor of the texture to create. |
| 97 * @param isRT Indicates if the texture can be a render target. | |
| 98 */ | |
| 99 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc, | |
| 100 bool* isRT) { | |
| 101 if (!caps.isConfigTexturable(desc.fConfig)) { | |
| 102 return false; | |
| 98 } | 103 } |
| 99 | 104 |
| 100 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 105 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 101 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 106 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 102 return nullptr; | 107 return false; |
| 103 } | 108 } |
| 104 | 109 |
| 105 // We currently do not support multisampled textures | 110 // We currently do not support multisampled textures |
| 106 if (!isRT && desc.fSampleCnt > 0) { | 111 if (!*isRT && desc.fSampleCnt > 0) { |
| 107 return nullptr; | 112 return false; |
| 108 } | 113 } |
| 109 | 114 |
| 110 GrTexture *tex = nullptr; | 115 if (*isRT) { |
| 111 | 116 int maxRTSize = caps.maxRenderTargetSize(); |
| 112 if (isRT) { | |
| 113 int maxRTSize = this->caps()->maxRenderTargetSize(); | |
| 114 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | 117 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 115 return nullptr; | 118 return false; |
| 116 } | 119 } |
| 117 } else { | 120 } else { |
| 118 int maxSize = this->caps()->maxTextureSize(); | 121 int maxSize = caps.maxTextureSize(); |
| 119 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 122 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 120 return nullptr; | 123 return false; |
| 121 } | 124 } |
| 122 } | 125 } |
| 126 return true; | |
| 127 } | |
| 123 | 128 |
| 124 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle : | 129 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
| 125 GrGpuResource::kUncached_Lif eCycle; | 130 const SkTArray<SkMipMapLevel>& texels) { |
| 131 GrSurfaceDesc desc = origDesc; | |
| 126 | 132 |
| 127 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); | 133 const GrCaps* caps = this->caps(); |
| 128 // Attempt to catch un- or wrongly initialized sample counts; | 134 if (!caps) { |
|
bsalomon
2016/01/11 17:16:38
This will never be null. This object is holding a
Chris Blume
2016/01/12 12:49:33
Done.
| |
| 129 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | 135 return nullptr; |
| 130 | 136 } else { |
| 131 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | 137 bool isRT = false; |
| 132 | 138 bool textureCreationParamsValid = check_texture_creation_params(*caps, d esc, &isRT); |
| 133 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 139 if (!textureCreationParamsValid) { |
| 134 // We shouldn't be rendering into this | |
| 135 SkASSERT(!isRT); | |
| 136 SkASSERT(0 == desc.fSampleCnt); | |
| 137 | |
| 138 if (!this->caps()->npotTextureTileSupport() && | |
| 139 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | |
| 140 return nullptr; | 140 return nullptr; |
| 141 } | 141 } |
| 142 | 142 |
| 143 this->handleDirtyContext(); | 143 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
| 144 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); | 144 // Attempt to catch un- or wrongly intialized sample counts; |
| 145 } else { | 145 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 146 this->handleDirtyContext(); | 146 |
| 147 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); | 147 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 148 | |
| 149 GrTexture* tex = nullptr; | |
| 150 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_L ifeCycle : | |
| 151 GrGpuResource::kUncached _LifeCycle; | |
| 152 | |
| 153 if (GrPixelConfigIsCompressed(desc.fConfig)) { | |
| 154 // We shouldn't be rendering into this | |
| 155 SkASSERT(!isRT); | |
| 156 SkASSERT(0 == desc.fSampleCnt); | |
| 157 | |
| 158 if (!caps->npotTextureTileSupport() && | |
| 159 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | |
| 160 return nullptr; | |
| 161 } | |
| 162 | |
| 163 this->handleDirtyContext(); | |
| 164 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels); | |
| 165 } else { | |
| 166 this->handleDirtyContext(); | |
| 167 tex = this->onCreateTexture(desc, lifeCycle, texels); | |
| 168 } | |
| 169 if (tex) { | |
| 170 if (!caps->reuseScratchTextures() && !isRT) { | |
| 171 tex->resourcePriv().removeScratchKey(); | |
| 172 } | |
| 173 fStats.incTextureCreates(); | |
| 174 if (!texels.empty()) { | |
| 175 if (texels[0].fTexelsOrOffset) { | |
| 176 fStats.incTextureUploads(); | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 return tex; | |
| 148 } | 181 } |
| 149 if (!this->caps()->reuseScratchTextures() && !isRT) { | 182 } |
| 150 tex->resourcePriv().removeScratchKey(); | 183 |
| 151 } | 184 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 152 if (tex) { | 185 const void* srcData, size_t rowBytes) { |
| 153 fStats.incTextureCreates(); | 186 SkMipMapLevel level(srcData, rowBytes, desc.fWidth, desc.fHeight); |
| 154 if (srcData) { | 187 const int mipLevelCount = 1; |
| 155 fStats.incTextureUploads(); | 188 SkTArray<SkMipMapLevel> levels(mipLevelCount); |
| 156 } | 189 levels.push_back(level); |
| 157 } | 190 |
| 158 return tex; | 191 return this->createTexture(desc, budgeted, levels); |
| 159 } | 192 } |
| 160 | 193 |
| 161 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { | 194 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn ership ownership) { |
| 162 this->handleDirtyContext(); | 195 this->handleDirtyContext(); |
| 163 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 196 if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
| 164 return nullptr; | 197 return nullptr; |
| 165 } | 198 } |
| 166 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && | 199 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && |
| 167 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 200 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 168 return nullptr; | 201 return nullptr; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig , false)) { | 295 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig , false)) { |
| 263 // If we don't have a fallback to a straight read then fail. | 296 // If we don't have a fallback to a straight read then fail. |
| 264 if (kRequireDraw_DrawPreference == *drawPreference) { | 297 if (kRequireDraw_DrawPreference == *drawPreference) { |
| 265 return false; | 298 return false; |
| 266 } | 299 } |
| 267 *drawPreference = kNoDraw_DrawPreference; | 300 *drawPreference = kNoDraw_DrawPreference; |
| 268 } | 301 } |
| 269 | 302 |
| 270 return true; | 303 return true; |
| 271 } | 304 } |
| 272 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, siz e_t rowBytes, | 305 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 273 GrPixelConfig srcConfig, DrawPreference* drawPref erence, | 306 GrPixelConfig srcConfig, DrawPreference* drawPref erence, |
| 274 WritePixelTempDrawInfo* tempDrawInfo) { | 307 WritePixelTempDrawInfo* tempDrawInfo) { |
| 275 SkASSERT(drawPreference); | 308 SkASSERT(drawPreference); |
| 276 SkASSERT(tempDrawInfo); | 309 SkASSERT(tempDrawInfo); |
| 277 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); | 310 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 278 | 311 |
| 279 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && | 312 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && |
| 280 dstSurface->desc().fConfig != srcConfig) { | 313 dstSurface->desc().fConfig != srcConfig) { |
| 281 return false; | 314 return false; |
| 282 } | 315 } |
| 283 | 316 |
| 284 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && | 317 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && |
| 285 SkToBool(dstSurface->asRenderTarget()) && | 318 SkToBool(dstSurface->asRenderTarget()) && |
| 286 (width < dstSurface->width() || height < dstSurface->height())) { | 319 (width < dstSurface->width() || height < dstSurface->height())) { |
| 287 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 320 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 288 } | 321 } |
| 289 | 322 |
| 290 if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConf ig, drawPreference, | 323 if (!this->onGetWritePixelsInfo(dstSurface, width, height, srcConfig, drawPr eference, |
| 291 tempDrawInfo)) { | 324 tempDrawInfo)) { |
| 292 return false; | 325 return false; |
| 293 } | 326 } |
| 294 | 327 |
| 295 // Check to see if we're going to request that the caller draw when drawing is not possible. | 328 // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 296 if (!dstSurface->asRenderTarget() || | 329 if (!dstSurface->asRenderTarget() || |
| 297 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig )) { | 330 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig )) { |
| 298 // If we don't have a fallback to a straight upload then fail. | 331 // If we don't have a fallback to a straight upload then fail. |
| 299 if (kRequireDraw_DrawPreference == *drawPreference || | 332 if (kRequireDraw_DrawPreference == *drawPreference || |
| 300 !this->caps()->isConfigTexturable(srcConfig)) { | 333 !this->caps()->isConfigTexturable(srcConfig)) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 325 } | 358 } |
| 326 | 359 |
| 327 return this->onReadPixels(surface, | 360 return this->onReadPixels(surface, |
| 328 left, top, width, height, | 361 left, top, width, height, |
| 329 config, buffer, | 362 config, buffer, |
| 330 rowBytes); | 363 rowBytes); |
| 331 } | 364 } |
| 332 | 365 |
| 333 bool GrGpu::writePixels(GrSurface* surface, | 366 bool GrGpu::writePixels(GrSurface* surface, |
| 334 int left, int top, int width, int height, | 367 int left, int top, int width, int height, |
| 335 GrPixelConfig config, const void* buffer, | 368 GrPixelConfig config, const SkTArray<SkMipMapLevel>& tex els) { |
| 336 size_t rowBytes) { | 369 if (!surface) { |
| 337 if (!buffer || !surface) { | 370 return false; |
| 371 } | |
| 372 bool validMipDataFound = false; | |
| 373 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe vel++) { | |
| 374 if (texels[currentMipLevel].fTexelsOrOffset != nullptr) { | |
| 375 validMipDataFound = true; | |
| 376 break; | |
| 377 } | |
| 378 } | |
| 379 if (!validMipDataFound) { | |
| 338 return false; | 380 return false; |
| 339 } | 381 } |
| 340 | 382 |
| 341 this->handleDirtyContext(); | 383 this->handleDirtyContext(); |
| 342 if (this->onWritePixels(surface, left, top, width, height, config, buffer, r owBytes)) { | 384 if (this->onWritePixels(surface, left, top, width, height, config, texels)) { |
| 343 fStats.incTextureUploads(); | 385 fStats.incTextureUploads(); |
| 344 return true; | 386 return true; |
| 345 } | 387 } |
| 346 return false; | 388 return false; |
| 347 } | 389 } |
| 348 | 390 |
| 391 bool GrGpu::writePixels(GrSurface* surface, | |
| 392 int left, int top, int width, int height, | |
| 393 GrPixelConfig config, const void* buffer, | |
| 394 size_t rowBytes) { | |
| 395 SkMipMapLevel mipLevel(buffer, rowBytes, width, height); | |
| 396 const int mipLevelCount = 1; | |
| 397 SkTArray<SkMipMapLevel> texels(mipLevelCount); | |
| 398 texels.push_back(mipLevel); | |
| 399 | |
| 400 return this->writePixels(surface, left, top, width, height, config, texels); | |
| 401 } | |
| 402 | |
| 349 bool GrGpu::transferPixels(GrSurface* surface, | 403 bool GrGpu::transferPixels(GrSurface* surface, |
| 350 int left, int top, int width, int height, | 404 int left, int top, int width, int height, |
| 351 GrPixelConfig config, GrTransferBuffer* buffer, | 405 GrPixelConfig config, GrTransferBuffer* buffer, |
| 352 size_t offset, size_t rowBytes) { | 406 size_t offset, size_t rowBytes) { |
| 353 SkASSERT(buffer); | 407 SkASSERT(buffer); |
| 354 | 408 |
| 355 this->handleDirtyContext(); | 409 this->handleDirtyContext(); |
| 356 if (this->onTransferPixels(surface, left, top, width, height, config, | 410 if (this->onTransferPixels(surface, left, top, width, height, config, |
| 357 buffer, offset, rowBytes)) { | 411 buffer, offset, rowBytes)) { |
| 358 fStats.incTransfersToTexture(); | 412 fStats.incTransfersToTexture(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 375 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 429 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
| 376 } | 430 } |
| 377 | 431 |
| 378 GrVertices::Iterator iter; | 432 GrVertices::Iterator iter; |
| 379 const GrNonInstancedVertices* verts = iter.init(vertices); | 433 const GrNonInstancedVertices* verts = iter.init(vertices); |
| 380 do { | 434 do { |
| 381 this->onDraw(args, *verts); | 435 this->onDraw(args, *verts); |
| 382 fStats.incNumDraws(); | 436 fStats.incNumDraws(); |
| 383 } while ((verts = iter.next())); | 437 } while ((verts = iter.next())); |
| 384 } | 438 } |
| OLD | NEW |