blob: 7cc51dfcd6343d36623ff0ec395a2688d945580e [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"
Brian Osman32342f02017-03-04 08:12:46 -050014#include "GrResourceProvider.h"
Robert Phillips84a81202016-11-04 11:59:10 -040015#include "GrTextureRenderTargetProxy.h"
Brian Salomonbb5711a2017-05-17 13:49:59 -040016#include "SkMathPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070017
csmartdaltonf9635992016-08-10 11:09:07 -070018// Deferred version
19// TODO: we can probably munge the 'desc' in both the wrapped and deferred
20// cases to make the sampleConfig/numSamples stuff more rational.
21GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
Robert Phillipsc787e492017-02-28 11:26:32 -050022 SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040023 : INHERITED(desc, fit, budgeted, flags)
24 , fSampleCnt(desc.fSampleCnt)
25 , fRenderTargetFlags(GrRenderTarget::Flags::kNone) {
csmartdaltonf9635992016-08-10 11:09:07 -070026 // Since we know the newly created render target will be internal, we are able to precompute
27 // what the flags will ultimately end up being.
Brian Salomonbb5711a2017-05-17 13:49:59 -040028 if (caps.usesMixedSamples() && fSampleCnt > 0) {
Brian Salomondac5f6b2017-02-28 16:11:04 -050029 fRenderTargetFlags |= GrRenderTarget::Flags::kMixedSampled;
csmartdaltonf9635992016-08-10 11:09:07 -070030 }
31 if (caps.maxWindowRectangles() > 0) {
Brian Salomondac5f6b2017-02-28 16:11:04 -050032 fRenderTargetFlags |= GrRenderTarget::Flags::kWindowRectsSupport;
csmartdaltonf9635992016-08-10 11:09:07 -070033 }
34}
35
36// Wrapped version
Robert Phillips37430132016-11-09 06:50:43 -050037GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
Brian Salomonbb5711a2017-05-17 13:49:59 -040038 : INHERITED(std::move(surf), SkBackingFit::kExact)
39 , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples())
40 , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {}
robertphillips76948d42016-05-04 12:47:41 -070041
Robert Phillipsec2249f2016-11-09 08:54:35 -050042int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
Brian Salomondac5f6b2017-02-28 16:11:04 -050043 return (fRenderTargetFlags & GrRenderTarget::Flags::kWindowRectsSupport)
44 ? caps.maxWindowRectangles()
45 : 0;
Robert Phillipsec2249f2016-11-09 08:54:35 -050046}
47
Brian Salomonbb5711a2017-05-17 13:49:59 -040048GrSurface* GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
49 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -070050
Brian Salomonbb5711a2017-05-17 13:49:59 -040051 GrSurface* surf = this->instantiateImpl(resourceProvider, fSampleCnt, kFlags,
Brian Salomon081e0e62017-05-17 14:27:58 -040052 /* isMipped = */ false,
53 SkDestinationSurfaceColorMode::kLegacy);
Brian Salomonbb5711a2017-05-17 13:49:59 -040054 if (!surf) {
robertphillips76948d42016-05-04 12:47:41 -070055 return nullptr;
56 }
Brian Salomonbb5711a2017-05-17 13:49:59 -040057 SkASSERT(surf->asRenderTarget());
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000058 // Check that our a priori computation matched the ultimate reality
Brian Salomondac5f6b2017-02-28 16:11:04 -050059 SkASSERT(fRenderTargetFlags == surf->asRenderTarget()->renderTargetPriv().flags());
Leon Scroggins7d7d7d12016-11-07 21:26:31 +000060
Brian Salomonbb5711a2017-05-17 13:49:59 -040061 return surf;
robertphillips76948d42016-05-04 12:47:41 -070062}
63
Brian Salomonbb5711a2017-05-17 13:49:59 -040064int GrRenderTargetProxy::worstCaseWidth() const {
Robert Phillips8bc06d02016-11-01 17:28:40 -040065 if (fTarget) {
Brian Salomonbb5711a2017-05-17 13:49:59 -040066 return fTarget->width();
Robert Phillips8bc06d02016-11-01 17:28:40 -040067 }
68
Brian Salomonbb5711a2017-05-17 13:49:59 -040069 if (SkBackingFit::kExact == fFit) {
70 return fWidth;
71 }
72 return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth));
73}
74
75int GrRenderTargetProxy::worstCaseHeight() const {
76 if (fTarget) {
77 return fTarget->height();
78 }
79
80 if (SkBackingFit::kExact == fFit) {
81 return fHeight;
82 }
83 return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight));
84}
85
86size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
87 int colorSamplesPerPixel = this->numColorSamples() + 1;
Robert Phillips8bc06d02016-11-01 17:28:40 -040088 // TODO: do we have enough information to improve this worst case estimate?
Brian Salomonbb5711a2017-05-17 13:49:59 -040089 return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, false,
90 SkBackingFit::kApprox == fFit);
Robert Phillips8bc06d02016-11-01 17:28:40 -040091}
92
Robert Phillipse2f7d182016-12-15 09:23:05 -050093bool GrRenderTargetProxy::refsWrappedObjects() const {
94 if (!fTarget) {
95 return false;
96 }
97
98 return fTarget->resourcePriv().refsWrappedObjects();
99}