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" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 11 | #include "GrGpuResourcePriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame^] | 12 | #include "GrRenderTargetOpList.h" |
| 13 | #include "GrTextureProvider.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 14 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 15 | // Deferred version |
| 16 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 17 | // cases to make the sampleConfig/numSamples stuff more rational. |
| 18 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, |
| 19 | SkBackingFit fit, SkBudgeted budgeted) |
| 20 | : INHERITED(desc, fit, budgeted) |
| 21 | , fTarget(nullptr) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame^] | 22 | , fFlags(GrRenderTargetPriv::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) { |
| 26 | fFlags |= GrRenderTargetPriv::Flags::kMixedSampled; |
| 27 | } |
| 28 | if (caps.maxWindowRectangles() > 0) { |
| 29 | fFlags |= GrRenderTargetPriv::Flags::kWindowRectsSupport; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Wrapped version |
| 34 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, sk_sp<GrRenderTarget> rt) |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 35 | : INHERITED(rt->desc(), SkBackingFit::kExact, |
| 36 | rt->resourcePriv().isBudgeted(), rt->uniqueID()) |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 37 | , fTarget(std::move(rt)) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame^] | 38 | , fFlags(fTarget->renderTargetPriv().flags()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) { |
| 42 | if (fTarget) { |
| 43 | return fTarget.get(); |
| 44 | } |
| 45 | |
| 46 | // TODO: it would be nice to not have to copy the desc here |
| 47 | GrSurfaceDesc desc = fDesc; |
| 48 | desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag; |
| 49 | |
| 50 | sk_sp<GrTexture> tex; |
| 51 | if (SkBackingFit::kApprox == fFit) { |
| 52 | tex.reset(texProvider->createApproxTexture(desc)); |
| 53 | } else { |
| 54 | tex.reset(texProvider->createTexture(desc, fBudgeted)); |
| 55 | } |
| 56 | if (!tex || !tex->asRenderTarget()) { |
| 57 | return nullptr; |
| 58 | } |
| 59 | |
| 60 | fTarget = sk_ref_sp(tex->asRenderTarget()); |
| 61 | |
| 62 | // Check that our a priori computation matched the ultimate reality |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 63 | SkASSERT(fFlags == fTarget->renderTargetPriv().flags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 64 | |
| 65 | return fTarget.get(); |
| 66 | } |
| 67 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 68 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, |
| 69 | const GrSurfaceDesc& desc, |
| 70 | SkBackingFit fit, |
| 71 | SkBudgeted budgeted) { |
| 72 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, desc, fit, budgeted)); |
| 73 | } |
| 74 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 75 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, sk_sp<GrRenderTarget> rt) { |
| 76 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, rt)); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 77 | } |
| 78 | |