blob: 50e0c5c6f5d3b7f8758b4f03d293feb78eb32aa2 [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
Greg Danielf91aeb22019-06-18 09:58:02 -04008#include "src/gpu/GrRenderTargetProxy.h"
robertphillips76948d42016-05-04 12:47:41 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/core/SkMathPriv.h"
11#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrGpuResourcePriv.h"
13#include "src/gpu/GrRenderTargetOpList.h"
14#include "src/gpu/GrRenderTargetPriv.h"
15#include "src/gpu/GrResourceProvider.h"
16#include "src/gpu/GrSurfacePriv.h"
17#include "src/gpu/GrTextureRenderTargetProxy.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,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040024 const GrSwizzle& textureSwizzle,
25 const GrSwizzle& outputSwizzle, SkBackingFit fit,
26 SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
27 : INHERITED(format, desc, origin, textureSwizzle, fit, budgeted, surfaceFlags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040028 , fSampleCnt(desc.fSampleCnt)
Greg Daniel2c19e7f2019-06-18 13:29:21 -040029 , fOutputSwizzle(outputSwizzle)
Greg Danielb46add82019-01-02 14:51:29 -050030 , fNeedsStencil(false)
31 , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo) {
csmartdaltonf9635992016-08-10 11:09:07 -070032 // Since we know the newly created render target will be internal, we are able to precompute
33 // what the flags will ultimately end up being.
Brian Salomonbdecacf2018-02-02 20:32:49 -050034 if (caps.usesMixedSamples() && fSampleCnt > 1) {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040035 this->setHasMixedSamples();
csmartdaltonf9635992016-08-10 11:09:07 -070036 }
csmartdaltonf9635992016-08-10 11:09:07 -070037}
38
Chris Dalton706a6ff2017-11-29 22:01:06 -070039// Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050040GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback,
Greg Daniel4065d452018-11-16 15:43:41 -050041 LazyInstantiationType lazyType,
42 const GrBackendFormat& format, const GrSurfaceDesc& desc,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040043 GrSurfaceOrigin origin, const GrSwizzle& textureSwizzle,
44 const GrSwizzle& outputSwizzle, SkBackingFit fit,
Greg Danielb085fa92019-03-05 16:55:12 -050045 SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags,
46 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Greg Daniel2c19e7f2019-06-18 13:29:21 -040047 : INHERITED(std::move(callback), lazyType, format, desc, origin, textureSwizzle, fit,
48 budgeted, surfaceFlags)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050049 , fSampleCnt(desc.fSampleCnt)
Greg Daniel2c19e7f2019-06-18 13:29:21 -040050 , fOutputSwizzle(outputSwizzle)
Greg Danielb46add82019-01-02 14:51:29 -050051 , fNeedsStencil(false)
Greg Danielb085fa92019-03-05 16:55:12 -050052 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -050053 SkASSERT(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags));
Chris Dalton706a6ff2017-11-29 22:01:06 -070054}
55
csmartdaltonf9635992016-08-10 11:09:07 -070056// Wrapped version
Greg Danielb46add82019-01-02 14:51:29 -050057GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040058 const GrSwizzle& textureSwizzle,
59 const GrSwizzle& outputSwizzle,
Greg Danielb46add82019-01-02 14:51:29 -050060 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Greg Daniel2c19e7f2019-06-18 13:29:21 -040061 : INHERITED(std::move(surf), origin, textureSwizzle, SkBackingFit::kExact)
Chris Dalton706a6ff2017-11-29 22:01:06 -070062 , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples())
Greg Daniel2c19e7f2019-06-18 13:29:21 -040063 , fOutputSwizzle(outputSwizzle)
Greg Danielb46add82019-01-02 14:51:29 -050064 , fNeedsStencil(false)
65 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) {
Robert Phillipsc4f0a822017-06-13 08:11:36 -040066}
robertphillips76948d42016-05-04 12:47:41 -070067
Robert Phillipsec2249f2016-11-09 08:54:35 -050068int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
Brian Salomon34a20302018-12-18 12:03:07 -050069 return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles();
Robert Phillipsec2249f2016-11-09 08:54:35 -050070}
71
Robert Phillips10d17212019-04-24 14:09:10 -040072bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
Greg Daniel0a375db2018-02-01 12:21:39 -050073 if (LazyState::kNot != this->lazyInstantiationState()) {
74 return false;
75 }
Robert Phillipsfe0253f2018-03-16 16:47:25 -040076 static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -070077
Robert Phillipsfe0253f2018-03-16 16:47:25 -040078 if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kDescFlags,
Robert Phillips10d17212019-04-24 14:09:10 -040079 GrMipMapped::kNo, nullptr)) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040080 return false;
robertphillips76948d42016-05-04 12:47:41 -070081 }
Robert Phillipseee4d6e2017-06-05 09:26:07 -040082 SkASSERT(fTarget->asRenderTarget());
Greg Daniele252f082017-10-23 16:05:23 -040083 SkASSERT(!fTarget->asTexture());
Robert Phillipseee4d6e2017-06-05 09:26:07 -040084 return true;
robertphillips76948d42016-05-04 12:47:41 -070085}
86
Robert Phillips5af44de2017-07-18 14:49:38 -040087sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040088 static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag;
Robert Phillips5af44de2017-07-18 14:49:38 -040089
Robert Phillips65048132017-08-10 08:44:49 -040090 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, fNeedsStencil,
Robert Phillips10d17212019-04-24 14:09:10 -040091 kDescFlags, GrMipMapped::kNo);
Robert Phillips5af44de2017-07-18 14:49:38 -040092 if (!surface) {
93 return nullptr;
94 }
95 SkASSERT(surface->asRenderTarget());
Greg Daniele252f082017-10-23 16:05:23 -040096 SkASSERT(!surface->asTexture());
Robert Phillips5af44de2017-07-18 14:49:38 -040097 return surface;
98}
99
Brian Salomonbb5711a2017-05-17 13:49:59 -0400100size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500101 int colorSamplesPerPixel = this->numColorSamples();
102 if (colorSamplesPerPixel > 1) {
103 // Add one for the resolve buffer.
104 ++colorSamplesPerPixel;
105 }
Greg Daniele252f082017-10-23 16:05:23 -0400106
Robert Phillips8bc06d02016-11-01 17:28:40 -0400107 // TODO: do we have enough information to improve this worst case estimate?
Chris Dalton706a6ff2017-11-29 22:01:06 -0700108 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
109 colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
Robert Phillips8bc06d02016-11-01 17:28:40 -0400110}
111
Robert Phillipse2f7d182016-12-15 09:23:05 -0500112bool GrRenderTargetProxy::refsWrappedObjects() const {
113 if (!fTarget) {
114 return false;
115 }
116
117 return fTarget->resourcePriv().refsWrappedObjects();
118}
Robert Phillipse8fabb22018-02-04 14:33:21 -0500119
120#ifdef SK_DEBUG
Greg Daniel849dce12018-04-24 14:32:53 -0400121void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500122 // We do not check that surface->asTexture returns null since, when replaying DDLs we
123 // can fulfill a renderTarget-only proxy w/ a textureRenderTarget.
Robert Phillipse8fabb22018-02-04 14:33:21 -0500124
125 // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
126 SkASSERT(surface->asRenderTarget());
127 SkASSERT(surface->asRenderTarget()->numStencilSamples() == this->numStencilSamples());
Greg Daniel849dce12018-04-24 14:32:53 -0400128
Greg Daniela070ed72018-04-26 16:31:38 -0400129 GrInternalSurfaceFlags proxyFlags = fSurfaceFlags;
130 GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags();
131 SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) ==
132 (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500133}
134#endif