blob: 29c4fc300ab211fc334333b7c030d87e9aa45fcf [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#ifndef GrRenderTargetProxy_DEFINED
9#define GrRenderTargetProxy_DEFINED
10
robertphillips76948d42016-05-04 12:47:41 -070011#include "GrSurfaceProxy.h"
Robert Phillipsc4f0a822017-06-13 08:11:36 -040012#include "GrTypesPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070013
Brian Osman32342f02017-03-04 08:12:46 -050014class GrResourceProvider;
robertphillips76948d42016-05-04 12:47:41 -070015
16// This class delays the acquisition of RenderTargets until they are actually
17// required
18// Beware: the uniqueID of the RenderTargetProxy will usually be different than
19// the uniqueID of the RenderTarget it represents!
Robert Phillips84a81202016-11-04 11:59:10 -040020class GrRenderTargetProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070021public:
robertphillips76948d42016-05-04 12:47:41 -070022 GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
23 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
24
25 // Actually instantiate the backing rendertarget, if necessary.
Robert Phillips5af44de2017-07-18 14:49:38 -040026 bool instantiate(GrResourceProvider*) override;
robertphillips76948d42016-05-04 12:47:41 -070027
Brian Salomon7c8460e2017-05-12 11:36:10 -040028 GrFSAAType fsaaType() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -050029 if (fSampleCnt <= 1) {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040030 SkASSERT(!this->hasMixedSamples());
Brian Salomon7c8460e2017-05-12 11:36:10 -040031 return GrFSAAType::kNone;
32 }
Robert Phillipsfe0253f2018-03-16 16:47:25 -040033 return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
Brian Salomon7c8460e2017-05-12 11:36:10 -040034 }
Brian Salomonbb5711a2017-05-17 13:49:59 -040035
Robert Phillips65048132017-08-10 08:44:49 -040036 /*
37 * When instantiated does this proxy require a stencil buffer?
38 */
39 void setNeedsStencil() { fNeedsStencil = true; }
40 bool needsStencil() const { return fNeedsStencil; }
41
Brian Salomonbb5711a2017-05-17 13:49:59 -040042 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -050043 * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA).
Brian Salomonbb5711a2017-05-17 13:49:59 -040044 */
45 int numStencilSamples() const { return fSampleCnt; }
46
robertphillips76948d42016-05-04 12:47:41 -070047 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -050048 * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled).
robertphillips76948d42016-05-04 12:47:41 -070049 */
Brian Salomon7c8460e2017-05-12 11:36:10 -040050 int numColorSamples() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -050051 return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
Brian Salomon7c8460e2017-05-12 11:36:10 -040052 }
robertphillips76948d42016-05-04 12:47:41 -070053
Robert Phillipsec2249f2016-11-09 08:54:35 -050054 int maxWindowRectangles(const GrCaps& caps) const;
55
Robert Phillipse2f7d182016-12-15 09:23:05 -050056 // TODO: move this to a priv class!
57 bool refsWrappedObjects() const;
58
Robert Phillips84a81202016-11-04 11:59:10 -040059protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050060 friend class GrProxyProvider; // for ctors
Robert Phillips37430132016-11-09 06:50:43 -050061
csmartdaltonf9635992016-08-10 11:09:07 -070062 // Deferred version
Brian Salomon2a4f9832018-03-03 22:43:43 -050063 GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, GrSurfaceOrigin, SkBackingFit,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040064 SkBudgeted, GrInternalSurfaceFlags);
robertphillips76948d42016-05-04 12:47:41 -070065
Chris Dalton706a6ff2017-11-29 22:01:06 -070066 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050067 // There are two main use cases for lazily-instantiated proxies:
68 // basic knowledge - width, height, config, samples, origin are known
69 // minimal knowledge - only config is known.
70 //
71 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
72 // use, but we don't have access to the GPU yet to instantiate it.
73 //
74 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
75 // know the final size until flush time.
Greg Daniel457469c2018-02-08 15:05:44 -050076 GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType,
Brian Salomon2a4f9832018-03-03 22:43:43 -050077 const GrSurfaceDesc&, GrSurfaceOrigin, SkBackingFit, SkBudgeted,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040078 GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070079
robertphillips76948d42016-05-04 12:47:41 -070080 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040081 GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -070082
Robert Phillips5af44de2017-07-18 14:49:38 -040083 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
84
Robert Phillips84a81202016-11-04 11:59:10 -040085private:
Brian Salomonbb5711a2017-05-17 13:49:59 -040086 size_t onUninstantiatedGpuMemorySize() const override;
Greg Daniel849dce12018-04-24 14:32:53 -040087 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
Robert Phillips8bc06d02016-11-01 17:28:40 -040088
Robert Phillipsc4f0a822017-06-13 08:11:36 -040089 int fSampleCnt;
Robert Phillips65048132017-08-10 08:44:49 -040090 bool fNeedsStencil;
91
Robert Phillipsc7635fa2016-10-28 13:25:24 -040092 // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
93 // For deferred proxies that pointer is filled in when we need to instantiate the
94 // deferred resource.
robertphillips76948d42016-05-04 12:47:41 -070095
robertphillips76948d42016-05-04 12:47:41 -070096 typedef GrSurfaceProxy INHERITED;
97};
98
99#endif