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 | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 11 | #include "GrGpuResourcePriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetOpList.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetPriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 14 | #include "GrTextureProvider.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 15 | #include "GrTextureRenderTargetProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 16 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 17 | // Deferred version |
| 18 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 19 | // cases to make the sampleConfig/numSamples stuff more rational. |
| 20 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, |
| 21 | SkBackingFit fit, SkBudgeted budgeted) |
| 22 | : INHERITED(desc, fit, budgeted) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 23 | , fFlags(GrRenderTarget::Flags::kNone) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 24 | // Since we know the newly created render target will be internal, we are able to precompute |
| 25 | // what the flags will ultimately end up being. |
| 26 | if (caps.usesMixedSamples() && fDesc.fSampleCnt > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 27 | fFlags |= GrRenderTarget::Flags::kMixedSampled; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 28 | } |
| 29 | if (caps.maxWindowRectangles() > 0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 30 | fFlags |= GrRenderTarget::Flags::kWindowRectsSupport; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | // Wrapped version |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 35 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf) |
| 36 | : INHERITED(std::move(surf), SkBackingFit::kExact) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 37 | , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 40 | int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { |
| 41 | return (fFlags & GrRenderTarget::Flags::kWindowRectsSupport) ? caps.maxWindowRectangles() : 0; |
| 42 | } |
| 43 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 44 | GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 45 | SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 46 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 47 | GrSurface* surf = INHERITED::instantiate(texProvider); |
| 48 | if (!surf || !surf->asRenderTarget()) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 49 | return nullptr; |
| 50 | } |
| 51 | |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 52 | // Check that our a priori computation matched the ultimate reality |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 53 | SkASSERT(fFlags == surf->asRenderTarget()->renderTargetPriv().flags()); |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 54 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 55 | return surf->asRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 58 | size_t GrRenderTargetProxy::onGpuMemorySize() const { |
| 59 | if (fTarget) { |
| 60 | return fTarget->gpuMemorySize(); |
| 61 | } |
| 62 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 63 | // TODO: do we have enough information to improve this worst case estimate? |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 64 | return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 67 | bool GrRenderTargetProxy::refsWrappedObjects() const { |
| 68 | if (!fTarget) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | return fTarget->resourcePriv().refsWrappedObjects(); |
| 73 | } |