blob: 03637cf9af1a2e89987899c8ca9f9b77387de0f4 [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 Phillipsf2361d22016-10-25 14:20:06 -040011#include "GrRenderTargetOpList.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040012#include "GrRenderTargetPriv.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040013#include "GrTextureProvider.h"
Robert Phillips84a81202016-11-04 11:59:10 -040014#include "GrTextureRenderTargetProxy.h"
robertphillips76948d42016-05-04 12:47:41 -070015
csmartdaltonf9635992016-08-10 11:09:07 -070016// 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.
19GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
20 SkBackingFit fit, SkBudgeted budgeted)
21 : INHERITED(desc, fit, budgeted)
Robert Phillipsc7635fa2016-10-28 13:25:24 -040022 , fFlags(GrRenderTarget::Flags::kNone) {
csmartdaltonf9635992016-08-10 11:09:07 -070023 // 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 Phillipsc7635fa2016-10-28 13:25:24 -040026 fFlags |= GrRenderTarget::Flags::kMixedSampled;
csmartdaltonf9635992016-08-10 11:09:07 -070027 }
28 if (caps.maxWindowRectangles() > 0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -040029 fFlags |= GrRenderTarget::Flags::kWindowRectsSupport;
csmartdaltonf9635992016-08-10 11:09:07 -070030 }
31}
32
33// Wrapped version
Robert Phillips37430132016-11-09 06:50:43 -050034GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
35 : INHERITED(std::move(surf), SkBackingFit::kExact)
Robert Phillipsc7635fa2016-10-28 13:25:24 -040036 , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
robertphillips76948d42016-05-04 12:47:41 -070037}
38
Robert Phillipsec2249f2016-11-09 08:54:35 -050039int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
40 return (fFlags & GrRenderTarget::Flags::kWindowRectsSupport) ? caps.maxWindowRectangles() : 0;
41}
42
robertphillips76948d42016-05-04 12:47:41 -070043GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) {
Robert Phillipseaa86252016-11-08 13:49:39 +000044 SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
robertphillips76948d42016-05-04 12:47:41 -070045
Robert Phillipseaa86252016-11-08 13:49:39 +000046 GrSurface* surf = INHERITED::instantiate(texProvider);
47 if (!surf || !surf->asRenderTarget()) {
robertphillips76948d42016-05-04 12:47:41 -070048 return nullptr;
49 }
50
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000051 // Check that our a priori computation matched the ultimate reality
Robert Phillipseaa86252016-11-08 13:49:39 +000052 SkASSERT(fFlags == surf->asRenderTarget()->renderTargetPriv().flags());
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000053
Robert Phillipseaa86252016-11-08 13:49:39 +000054 return surf->asRenderTarget();
robertphillips76948d42016-05-04 12:47:41 -070055}
56
Robert Phillips8bc06d02016-11-01 17:28:40 -040057size_t GrRenderTargetProxy::onGpuMemorySize() const {
58 if (fTarget) {
59 return fTarget->gpuMemorySize();
60 }
61
Robert Phillips8bc06d02016-11-01 17:28:40 -040062 // TODO: do we have enough information to improve this worst case estimate?
Robert Phillipsb4460882016-11-17 14:43:51 -050063 return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit);
Robert Phillips8bc06d02016-11-01 17:28:40 -040064}
65