robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [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 "GrRenderTargetProxy.h" |
| 9 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 11 | #include "GrRenderTargetOpList.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetPriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 13 | #include "GrTextureProvider.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 14 | #include "GrTextureRenderTargetProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 15 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 16 | // Deferred version |
| 17 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 18 | // cases to make the sampleConfig/numSamples stuff more rational. |
| 19 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, |
| 20 | SkBackingFit fit, SkBudgeted budgeted) |
| 21 | : INHERITED(desc, fit, budgeted) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 22 | , fFlags(GrRenderTarget::Flags::kNone) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 23 | // Since we know the newly created render target will be internal, we are able to precompute |
| 24 | // what the flags will ultimately end up being. |
| 25 | if (caps.usesMixedSamples() && fDesc.fSampleCnt > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 26 | fFlags |= GrRenderTarget::Flags::kMixedSampled; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 27 | } |
| 28 | if (caps.maxWindowRectangles() > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 29 | fFlags |= GrRenderTarget::Flags::kWindowRectsSupport; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | // Wrapped version |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 34 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrRenderTarget> rt) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 35 | : INHERITED(std::move(rt), SkBackingFit::kExact) |
| 36 | , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) { |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame^] | 40 | if (fTarget) { |
| 41 | return fTarget->asRenderTarget(); |
| 42 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 43 | |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame^] | 44 | // TODO: it would be nice to not have to copy the desc here |
| 45 | GrSurfaceDesc desc = fDesc; |
| 46 | desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag; |
| 47 | |
| 48 | if (SkBackingFit::kApprox == fFit) { |
| 49 | fTarget = texProvider->createApproxTexture(desc); |
| 50 | } else { |
| 51 | fTarget = texProvider->createTexture(desc, fBudgeted); |
| 52 | } |
| 53 | if (!fTarget) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 54 | return nullptr; |
| 55 | } |
| 56 | |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame^] | 57 | #ifdef SK_DEBUG |
| 58 | if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) { |
| 59 | SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly()); |
| 60 | } |
| 61 | #endif |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 62 | |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame^] | 63 | // Check that our a priori computation matched the ultimate reality |
| 64 | SkASSERT(fFlags == fTarget->asRenderTarget()->renderTargetPriv().flags()); |
| 65 | |
| 66 | return fTarget->asRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 69 | |
| 70 | #ifdef SK_DEBUG |
| 71 | void GrRenderTargetProxy::validate(GrContext* context) const { |
| 72 | if (fTarget) { |
| 73 | SkASSERT(fTarget->getContext() == context); |
| 74 | } |
| 75 | |
| 76 | INHERITED::validate(); |
| 77 | } |
| 78 | #endif |
| 79 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 80 | size_t GrRenderTargetProxy::onGpuMemorySize() const { |
| 81 | if (fTarget) { |
| 82 | return fTarget->gpuMemorySize(); |
| 83 | } |
| 84 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 85 | // TODO: do we have enough information to improve this worst case estimate? |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 86 | return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 87 | } |
| 88 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 89 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, |
| 90 | const GrSurfaceDesc& desc, |
| 91 | SkBackingFit fit, |
| 92 | SkBudgeted budgeted) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 93 | // We know anything we instantiate later from this deferred path will be |
| 94 | // both texturable and renderable |
| 95 | return GrTextureRenderTargetProxy::Make(caps, desc, fit, budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 98 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(sk_sp<GrRenderTarget> rt) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 99 | if (rt->asTexture()) { |
| 100 | return GrTextureRenderTargetProxy::Make(std::move(rt)); |
| 101 | } |
| 102 | |
| 103 | // Not texturable |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 104 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(rt)); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 105 | } |
| 106 | |