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" |
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) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 21 | , fFlags(GrRenderTarget::Flags::kNone) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 22 | // Since we know the newly created render target will be internal, we are able to precompute |
| 23 | // what the flags will ultimately end up being. |
| 24 | if (caps.usesMixedSamples() && fDesc.fSampleCnt > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 25 | fFlags |= GrRenderTarget::Flags::kMixedSampled; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 26 | } |
| 27 | if (caps.maxWindowRectangles() > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 28 | fFlags |= GrRenderTarget::Flags::kWindowRectsSupport; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | |
| 32 | // Wrapped version |
| 33 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, sk_sp<GrRenderTarget> rt) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 34 | : INHERITED(std::move(rt), SkBackingFit::kExact) |
| 35 | , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) { |
| 39 | if (fTarget) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 40 | return fTarget->asRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // TODO: it would be nice to not have to copy the desc here |
| 44 | GrSurfaceDesc desc = fDesc; |
| 45 | desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag; |
| 46 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 47 | if (SkBackingFit::kApprox == fFit) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 48 | fTarget = texProvider->createApproxTexture(desc); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 49 | } else { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 50 | fTarget = texProvider->createTexture(desc, fBudgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 51 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 52 | if (!fTarget) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 53 | return nullptr; |
| 54 | } |
| 55 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 56 | // Check that our a priori computation matched the ultimate reality |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 57 | SkASSERT(fFlags == fTarget->asRenderTarget()->renderTargetPriv().flags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 58 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 59 | return fTarget->asRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame^] | 62 | |
| 63 | #ifdef SK_DEBUG |
| 64 | void GrRenderTargetProxy::validate(GrContext* context) const { |
| 65 | if (fTarget) { |
| 66 | SkASSERT(fTarget->getContext() == context); |
| 67 | } |
| 68 | |
| 69 | INHERITED::validate(); |
| 70 | } |
| 71 | #endif |
| 72 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 73 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, |
| 74 | const GrSurfaceDesc& desc, |
| 75 | SkBackingFit fit, |
| 76 | SkBudgeted budgeted) { |
| 77 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, desc, fit, budgeted)); |
| 78 | } |
| 79 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 80 | sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, sk_sp<GrRenderTarget> rt) { |
| 81 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, rt)); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 82 | } |
| 83 | |