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