blob: 0d70920c75e83696c4be4937ee2943281a7d0332 [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)
Brian Salomonf2c2ba92019-07-17 09:59:59 -040027 : INHERITED(format, desc, GrRenderable::kYes, origin, textureSwizzle, fit, budgeted,
28 surfaceFlags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040029 , fSampleCnt(desc.fSampleCnt)
Chris Daltoneffee202019-07-01 22:28:03 -060030 , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo)
Brian Salomonf2c2ba92019-07-17 09:59:59 -040031 , fOutputSwizzle(outputSwizzle) {}
csmartdaltonf9635992016-08-10 11:09:07 -070032
Chris Dalton706a6ff2017-11-29 22:01:06 -070033// Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050034GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback,
Greg Daniel4065d452018-11-16 15:43:41 -050035 LazyInstantiationType lazyType,
36 const GrBackendFormat& format, const GrSurfaceDesc& desc,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040037 GrSurfaceOrigin origin, const GrSwizzle& textureSwizzle,
38 const GrSwizzle& outputSwizzle, SkBackingFit fit,
Greg Danielb085fa92019-03-05 16:55:12 -050039 SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags,
40 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Brian Salomonf2c2ba92019-07-17 09:59:59 -040041 : INHERITED(std::move(callback), lazyType, format, desc, GrRenderable::kYes, origin,
42 textureSwizzle, fit, budgeted, surfaceFlags)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050043 , fSampleCnt(desc.fSampleCnt)
Chris Daltoneffee202019-07-01 22:28:03 -060044 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB)
Brian Salomonf2c2ba92019-07-17 09:59:59 -040045 , fOutputSwizzle(outputSwizzle) {}
Chris Dalton706a6ff2017-11-29 22:01:06 -070046
csmartdaltonf9635992016-08-10 11:09:07 -070047// Wrapped version
Greg Danielb46add82019-01-02 14:51:29 -050048GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040049 const GrSwizzle& textureSwizzle,
50 const GrSwizzle& outputSwizzle,
Greg Danielb46add82019-01-02 14:51:29 -050051 WrapsVkSecondaryCB wrapsVkSecondaryCB)
Greg Daniel2c19e7f2019-06-18 13:29:21 -040052 : INHERITED(std::move(surf), origin, textureSwizzle, SkBackingFit::kExact)
Chris Dalton6ce447a2019-06-23 18:07:38 -060053 , fSampleCnt(fTarget->asRenderTarget()->numSamples())
Chris Daltoneffee202019-07-01 22:28:03 -060054 , fWrapsVkSecondaryCB(wrapsVkSecondaryCB)
55 , fOutputSwizzle(outputSwizzle) {
Robert Phillipsc4f0a822017-06-13 08:11:36 -040056}
robertphillips76948d42016-05-04 12:47:41 -070057
Robert Phillipsec2249f2016-11-09 08:54:35 -050058int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
Brian Salomon34a20302018-12-18 12:03:07 -050059 return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles();
Robert Phillipsec2249f2016-11-09 08:54:35 -050060}
61
Robert Phillips10d17212019-04-24 14:09:10 -040062bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
Greg Daniel0a375db2018-02-01 12:21:39 -050063 if (LazyState::kNot != this->lazyInstantiationState()) {
64 return false;
65 }
Brian Salomonf2c2ba92019-07-17 09:59:59 -040066 if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes,
Robert Phillips10d17212019-04-24 14:09:10 -040067 GrMipMapped::kNo, nullptr)) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040068 return false;
robertphillips76948d42016-05-04 12:47:41 -070069 }
Robert Phillipsb5204762019-06-19 14:12:13 -040070
71 SkASSERT(this->peekRenderTarget());
72 SkASSERT(!this->peekTexture());
Robert Phillipseee4d6e2017-06-05 09:26:07 -040073 return true;
robertphillips76948d42016-05-04 12:47:41 -070074}
75
Chris Dalton215ff332019-07-02 09:38:22 -060076bool GrRenderTargetProxy::canChangeStencilAttachment() const {
77 if (!fTarget) {
78 // If we aren't instantiated, then we definitely are an internal render target. Ganesh is
79 // free to change stencil attachments on internal render targets.
80 return true;
81 }
82 return fTarget->asRenderTarget()->canAttemptStencilAttachment();
83}
84
Robert Phillips5af44de2017-07-18 14:49:38 -040085sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const {
Chris Daltoneffee202019-07-01 22:28:03 -060086 sk_sp<GrSurface> surface = this->createSurfaceImpl(
Brian Salomonf2c2ba92019-07-17 09:59:59 -040087 resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes, GrMipMapped::kNo);
Robert Phillips5af44de2017-07-18 14:49:38 -040088 if (!surface) {
89 return nullptr;
90 }
91 SkASSERT(surface->asRenderTarget());
Greg Daniele252f082017-10-23 16:05:23 -040092 SkASSERT(!surface->asTexture());
Robert Phillips5af44de2017-07-18 14:49:38 -040093 return surface;
94}
95
Brian Salomonbb5711a2017-05-17 13:49:59 -040096size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
Chris Dalton6ce447a2019-06-23 18:07:38 -060097 int colorSamplesPerPixel = this->numSamples();
Brian Salomonbdecacf2018-02-02 20:32:49 -050098 if (colorSamplesPerPixel > 1) {
99 // Add one for the resolve buffer.
100 ++colorSamplesPerPixel;
101 }
Greg Daniele252f082017-10-23 16:05:23 -0400102
Robert Phillips8bc06d02016-11-01 17:28:40 -0400103 // TODO: do we have enough information to improve this worst case estimate?
Chris Dalton706a6ff2017-11-29 22:01:06 -0700104 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
105 colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
Robert Phillips8bc06d02016-11-01 17:28:40 -0400106}
107
Robert Phillipse2f7d182016-12-15 09:23:05 -0500108bool GrRenderTargetProxy::refsWrappedObjects() const {
Robert Phillipsb5204762019-06-19 14:12:13 -0400109 if (!this->isInstantiated()) {
Robert Phillipse2f7d182016-12-15 09:23:05 -0500110 return false;
111 }
112
Robert Phillipsb5204762019-06-19 14:12:13 -0400113 GrSurface* surface = this->peekSurface();
114 return surface->resourcePriv().refsWrappedObjects();
Robert Phillipse2f7d182016-12-15 09:23:05 -0500115}
Robert Phillipse8fabb22018-02-04 14:33:21 -0500116
117#ifdef SK_DEBUG
Greg Daniel849dce12018-04-24 14:32:53 -0400118void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500119 // We do not check that surface->asTexture returns null since, when replaying DDLs we
120 // can fulfill a renderTarget-only proxy w/ a textureRenderTarget.
Robert Phillipse8fabb22018-02-04 14:33:21 -0500121
122 // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
123 SkASSERT(surface->asRenderTarget());
Chris Dalton6ce447a2019-06-23 18:07:38 -0600124 SkASSERT(surface->asRenderTarget()->numSamples() == this->numSamples());
Greg Daniel849dce12018-04-24 14:32:53 -0400125
Greg Daniela070ed72018-04-26 16:31:38 -0400126 GrInternalSurfaceFlags proxyFlags = fSurfaceFlags;
127 GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags();
128 SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) ==
129 (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500130}
131#endif