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 | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame^] | 34 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf) |
| 35 | : INHERITED(std::move(surf), SkBackingFit::kExact) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 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) { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 40 | SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 41 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 42 | GrSurface* surf = INHERITED::instantiate(texProvider); |
| 43 | if (!surf || !surf->asRenderTarget()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 44 | return nullptr; |
| 45 | } |
| 46 | |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 47 | // Check that our a priori computation matched the ultimate reality |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 48 | SkASSERT(fFlags == surf->asRenderTarget()->renderTargetPriv().flags()); |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 49 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 50 | return surf->asRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 53 | |
| 54 | #ifdef SK_DEBUG |
| 55 | void GrRenderTargetProxy::validate(GrContext* context) const { |
| 56 | if (fTarget) { |
| 57 | SkASSERT(fTarget->getContext() == context); |
| 58 | } |
| 59 | |
| 60 | INHERITED::validate(); |
| 61 | } |
| 62 | #endif |
| 63 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 64 | size_t GrRenderTargetProxy::onGpuMemorySize() const { |
| 65 | if (fTarget) { |
| 66 | return fTarget->gpuMemorySize(); |
| 67 | } |
| 68 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 69 | // TODO: do we have enough information to improve this worst case estimate? |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 70 | return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 71 | } |
| 72 | |