blob: a9f23ff0ab7887bf5840ddf41f3f1ab360457235 [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"
Greg Daniel849dce12018-04-24 14:32:53 -040015#include "GrSurfacePriv.h"
Robert Phillips84a81202016-11-04 11:59:10 -040016#include "GrTextureRenderTargetProxy.h"
Brian Salomonbb5711a2017-05-17 13:49:59 -040017#include "SkMathPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070018
csmartdaltonf9635992016-08-10 11:09:07 -070019// Deferred version
20// TODO: we can probably munge the 'desc' in both the wrapped and deferred
21// cases to make the sampleConfig/numSamples stuff more rational.
Greg Daniel4065d452018-11-16 15:43:41 -050022GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrBackendFormat& format,
23 const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
24 SkBackingFit fit, SkBudgeted budgeted,
25 GrInternalSurfaceFlags surfaceFlags)
26 : INHERITED(format, desc, origin, fit, budgeted, surfaceFlags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040027 , fSampleCnt(desc.fSampleCnt)
Greg Danielb46add82019-01-02 14:51:29 -050028 , fNeedsStencil(false)
29 , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo) {
csmartdaltonf9635992016-08-10 11:09:07 -070030 // Since we know the newly created render target will be internal, we are able to precompute
31 // what the flags will ultimately end up being.
Brian Salomonbdecacf2018-02-02 20:32:49 -050032 if (caps.usesMixedSamples() && fSampleCnt > 1) {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040033 this->setHasMixedSamples();
csmartdaltonf9635992016-08-10 11:09:07 -070034 }
csmartdaltonf9635992016-08-10 11:09:07 -070035}
36
Chris Dalton706a6ff2017-11-29 22:01:06 -070037// Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050038GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback,
Greg Daniel4065d452018-11-16 15:43:41 -050039 LazyInstantiationType lazyType,
40 const GrBackendFormat& format, const GrSurfaceDesc& desc,
41 GrSurfaceOrigin origin, SkBackingFit fit,
Greg Danielb085fa92019-03-05 16:55:12 -050042 SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags,
43 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Greg Daniel4065d452018-11-16 15:43:41 -050044 : INHERITED(std::move(callback), lazyType, format, desc, origin, fit, budgeted,
45 surfaceFlags)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050046 , fSampleCnt(desc.fSampleCnt)
Greg Danielb46add82019-01-02 14:51:29 -050047 , fNeedsStencil(false)
Greg Danielb085fa92019-03-05 16:55:12 -050048 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -050049 SkASSERT(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags));
Chris Dalton706a6ff2017-11-29 22:01:06 -070050}
51
csmartdaltonf9635992016-08-10 11:09:07 -070052// Wrapped version
Greg Danielb46add82019-01-02 14:51:29 -050053GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin,
54 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Chris Dalton706a6ff2017-11-29 22:01:06 -070055 : INHERITED(std::move(surf), origin, SkBackingFit::kExact)
56 , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples())
Greg Danielb46add82019-01-02 14:51:29 -050057 , fNeedsStencil(false)
58 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) {
Robert Phillipsc4f0a822017-06-13 08:11:36 -040059}
robertphillips76948d42016-05-04 12:47:41 -070060
Robert Phillipsec2249f2016-11-09 08:54:35 -050061int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
Brian Salomon34a20302018-12-18 12:03:07 -050062 return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles();
Robert Phillipsec2249f2016-11-09 08:54:35 -050063}
64
Robert Phillipseee4d6e2017-06-05 09:26:07 -040065bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
Greg Daniel0a375db2018-02-01 12:21:39 -050066 if (LazyState::kNot != this->lazyInstantiationState()) {
67 return false;
68 }
Robert Phillipsfe0253f2018-03-16 16:47:25 -040069 static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -070070
Robert Phillipsfe0253f2018-03-16 16:47:25 -040071 if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kDescFlags,
Greg Danield2d8e922018-02-12 12:07:39 -050072 GrMipMapped::kNo, nullptr)) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040073 return false;
robertphillips76948d42016-05-04 12:47:41 -070074 }
Robert Phillipseee4d6e2017-06-05 09:26:07 -040075 SkASSERT(fTarget->asRenderTarget());
Greg Daniele252f082017-10-23 16:05:23 -040076 SkASSERT(!fTarget->asTexture());
Robert Phillipseee4d6e2017-06-05 09:26:07 -040077 return true;
robertphillips76948d42016-05-04 12:47:41 -070078}
79
Robert Phillips5af44de2017-07-18 14:49:38 -040080sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040081 static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag;
Robert Phillips5af44de2017-07-18 14:49:38 -040082
Robert Phillips65048132017-08-10 08:44:49 -040083 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, fNeedsStencil,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040084 kDescFlags, GrMipMapped::kNo);
Robert Phillips5af44de2017-07-18 14:49:38 -040085 if (!surface) {
86 return nullptr;
87 }
88 SkASSERT(surface->asRenderTarget());
Greg Daniele252f082017-10-23 16:05:23 -040089 SkASSERT(!surface->asTexture());
Robert Phillips5af44de2017-07-18 14:49:38 -040090 return surface;
91}
92
Brian Salomonbb5711a2017-05-17 13:49:59 -040093size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -050094 int colorSamplesPerPixel = this->numColorSamples();
95 if (colorSamplesPerPixel > 1) {
96 // Add one for the resolve buffer.
97 ++colorSamplesPerPixel;
98 }
Greg Daniele252f082017-10-23 16:05:23 -040099
Robert Phillips8bc06d02016-11-01 17:28:40 -0400100 // TODO: do we have enough information to improve this worst case estimate?
Chris Dalton706a6ff2017-11-29 22:01:06 -0700101 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
102 colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
Robert Phillips8bc06d02016-11-01 17:28:40 -0400103}
104
Robert Phillipse2f7d182016-12-15 09:23:05 -0500105bool GrRenderTargetProxy::refsWrappedObjects() const {
106 if (!fTarget) {
107 return false;
108 }
109
110 return fTarget->resourcePriv().refsWrappedObjects();
111}
Robert Phillipse8fabb22018-02-04 14:33:21 -0500112
113#ifdef SK_DEBUG
Greg Daniel849dce12018-04-24 14:32:53 -0400114void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500115 // We do not check that surface->asTexture returns null since, when replaying DDLs we
116 // can fulfill a renderTarget-only proxy w/ a textureRenderTarget.
Robert Phillipse8fabb22018-02-04 14:33:21 -0500117
118 // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
119 SkASSERT(surface->asRenderTarget());
120 SkASSERT(surface->asRenderTarget()->numStencilSamples() == this->numStencilSamples());
Greg Daniel849dce12018-04-24 14:32:53 -0400121
Greg Daniela070ed72018-04-26 16:31:38 -0400122 GrInternalSurfaceFlags proxyFlags = fSurfaceFlags;
123 GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags();
124 SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) ==
125 (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500126}
127#endif