Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTextureRenderTargetProxy.h" |
| 9 | |
| 10 | // Deferred version |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 11 | // This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 12 | // GrRenderTargetProxy) so its constructor must be explicitly called. |
| 13 | GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps, |
| 14 | const GrSurfaceDesc& desc, |
| 15 | SkBackingFit fit, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 16 | SkBudgeted budgeted, |
| 17 | uint32_t flags) |
| 18 | : GrSurfaceProxy(desc, fit, budgeted, flags) |
| 19 | // for now textures w/ data are always wrapped |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 20 | , GrTextureProxy(desc, fit, budgeted, nullptr, 0, flags) |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 21 | , GrRenderTargetProxy(caps, desc, fit, budgeted, flags) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | // Wrapped version |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 25 | // This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 26 | // GrRenderTargetProxy) so its constructor must be explicitly called. |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 27 | GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf, |
| 28 | GrSurfaceOrigin origin) |
| 29 | : GrSurfaceProxy(surf, origin, SkBackingFit::kExact) |
| 30 | , GrTextureProxy(surf, origin) |
| 31 | , GrRenderTargetProxy(surf, origin) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 32 | SkASSERT(surf->asTexture()); |
| 33 | SkASSERT(surf->asRenderTarget()); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 36 | size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const { |
| 37 | int colorSamplesPerPixel = this->numColorSamples() + 1; |
| 38 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 39 | // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created |
| 40 | // with mip maps but not whether a texture read from the proxy will lazily generate mip maps. |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 41 | |
| 42 | // TODO: do we have enough information to improve this worst case estimate? |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame^] | 43 | return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, GrMipMapped::kYes, |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 44 | SkBackingFit::kApprox == fFit); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 47 | bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 48 | static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; |
| 49 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 50 | const GrUniqueKey& key = this->getUniqueKey(); |
| 51 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 52 | if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(), |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame^] | 53 | kFlags, this->mipMapped(), this->mipColorMode(), |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 54 | key.isValid() ? &key : nullptr)) { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 55 | return false; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 56 | } |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 57 | if (key.isValid()) { |
| 58 | SkASSERT(key == this->getUniqueKey()); |
| 59 | } |
| 60 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 61 | SkASSERT(fTarget->asRenderTarget()); |
| 62 | SkASSERT(fTarget->asTexture()); |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 63 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 64 | return true; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 65 | } |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 66 | |
| 67 | sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface( |
| 68 | GrResourceProvider* resourceProvider) const { |
| 69 | static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; |
| 70 | |
| 71 | sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(), |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 72 | this->needsStencil(), kFlags, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame^] | 73 | this->mipMapped(), this->mipColorMode()); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 74 | if (!surface) { |
| 75 | return nullptr; |
| 76 | } |
| 77 | SkASSERT(surface->asRenderTarget()); |
| 78 | SkASSERT(surface->asTexture()); |
| 79 | |
| 80 | return surface; |
| 81 | } |
| 82 | |