blob: 882acf660c3ca12d4192848f22972cd6558ff0b3 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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
csmartdaltonf9635992016-08-10 11:09:07 -070010#include "GrCaps.h"
Robert Phillipse2f7d182016-12-15 09:23:05 -050011#include "GrGpuResourcePriv.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040012#include "GrRenderTargetOpList.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040013#include "GrRenderTargetPriv.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040014#include "GrTextureProvider.h"
Robert Phillips84a81202016-11-04 11:59:10 -040015#include "GrTextureRenderTargetProxy.h"
robertphillips76948d42016-05-04 12:47:41 -070016
csmartdaltonf9635992016-08-10 11:09:07 -070017// 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.
20GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
21 SkBackingFit fit, SkBudgeted budgeted)
22 : INHERITED(desc, fit, budgeted)
Robert Phillipsc7635fa2016-10-28 13:25:24 -040023 , fFlags(GrRenderTarget::Flags::kNone) {
csmartdaltonf9635992016-08-10 11:09:07 -070024 // 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 Phillipsc7635fa2016-10-28 13:25:24 -040027 fFlags |= GrRenderTarget::Flags::kMixedSampled;
csmartdaltonf9635992016-08-10 11:09:07 -070028 }
29 if (caps.maxWindowRectangles() > 0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -040030 fFlags |= GrRenderTarget::Flags::kWindowRectsSupport;
csmartdaltonf9635992016-08-10 11:09:07 -070031 }
32}
33
34// Wrapped version
Robert Phillips37430132016-11-09 06:50:43 -050035GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
36 : INHERITED(std::move(surf), SkBackingFit::kExact)
Robert Phillipsc7635fa2016-10-28 13:25:24 -040037 , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
robertphillips76948d42016-05-04 12:47:41 -070038}
39
Robert Phillipsec2249f2016-11-09 08:54:35 -050040int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
41 return (fFlags & GrRenderTarget::Flags::kWindowRectsSupport) ? caps.maxWindowRectangles() : 0;
42}
43
robertphillips76948d42016-05-04 12:47:41 -070044GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) {
Robert Phillipseaa86252016-11-08 13:49:39 +000045 SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
robertphillips76948d42016-05-04 12:47:41 -070046
Robert Phillipseaa86252016-11-08 13:49:39 +000047 GrSurface* surf = INHERITED::instantiate(texProvider);
48 if (!surf || !surf->asRenderTarget()) {
robertphillips76948d42016-05-04 12:47:41 -070049 return nullptr;
50 }
51
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000052 // Check that our a priori computation matched the ultimate reality
Robert Phillipseaa86252016-11-08 13:49:39 +000053 SkASSERT(fFlags == surf->asRenderTarget()->renderTargetPriv().flags());
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000054
Robert Phillipseaa86252016-11-08 13:49:39 +000055 return surf->asRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070056}
57
Robert Phillips8bc06d02016-11-01 17:28:40 -040058size_t GrRenderTargetProxy::onGpuMemorySize() const {
59 if (fTarget) {
60 return fTarget->gpuMemorySize();
61 }
62
Robert Phillips8bc06d02016-11-01 17:28:40 -040063 // TODO: do we have enough information to improve this worst case estimate?
Robert Phillipsb4460882016-11-17 14:43:51 -050064 return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit);
Robert Phillips8bc06d02016-11-01 17:28:40 -040065}
66
Robert Phillipse2f7d182016-12-15 09:23:05 -050067bool GrRenderTargetProxy::refsWrappedObjects() const {
68 if (!fTarget) {
69 return false;
70 }
71
72 return fTarget->resourcePriv().refsWrappedObjects();
73}