blob: adc755394152ec842b91955d615c3bf06c8f0302 [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
11#include "GrRenderTarget.h"
12#include "GrSurfaceProxy.h"
13#include "GrTypes.h"
14
Brian Osman32342f02017-03-04 08:12:46 -050015class GrResourceProvider;
robertphillips76948d42016-05-04 12:47:41 -070016
17// This class delays the acquisition of RenderTargets until they are actually
18// required
19// Beware: the uniqueID of the RenderTargetProxy will usually be different than
20// the uniqueID of the RenderTarget it represents!
Robert Phillips84a81202016-11-04 11:59:10 -040021class GrRenderTargetProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070022public:
robertphillips76948d42016-05-04 12:47:41 -070023 GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
24 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
25
26 // Actually instantiate the backing rendertarget, if necessary.
Brian Osman32342f02017-03-04 08:12:46 -050027 GrRenderTarget* instantiate(GrResourceProvider* resourceProvider);
robertphillips76948d42016-05-04 12:47:41 -070028
csmartdaltonf9635992016-08-10 11:09:07 -070029 bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; }
robertphillips76948d42016-05-04 12:47:41 -070030
31 /**
csmartdaltonf9635992016-08-10 11:09:07 -070032 * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color
33 * buffer is not.
robertphillips76948d42016-05-04 12:47:41 -070034 */
Brian Salomondac5f6b2017-02-28 16:11:04 -050035 bool isMixedSampled() const { return fRenderTargetFlags & GrRenderTarget::Flags::kMixedSampled; }
robertphillips76948d42016-05-04 12:47:41 -070036
37 /**
csmartdaltonf9635992016-08-10 11:09:07 -070038 * "Unified Sampled" means the stencil and color buffers are both multisampled.
robertphillips76948d42016-05-04 12:47:41 -070039 */
csmartdaltonf9635992016-08-10 11:09:07 -070040 bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); }
robertphillips76948d42016-05-04 12:47:41 -070041
42 /**
csmartdaltonf9635992016-08-10 11:09:07 -070043 * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
robertphillips76948d42016-05-04 12:47:41 -070044 */
csmartdaltonf9635992016-08-10 11:09:07 -070045 int numStencilSamples() const { return fDesc.fSampleCnt; }
robertphillips76948d42016-05-04 12:47:41 -070046
47 /**
csmartdaltonf9635992016-08-10 11:09:07 -070048 * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled).
robertphillips76948d42016-05-04 12:47:41 -070049 */
csmartdaltonf9635992016-08-10 11:09:07 -070050 int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; }
robertphillips76948d42016-05-04 12:47:41 -070051
Robert Phillipsec2249f2016-11-09 08:54:35 -050052 int maxWindowRectangles(const GrCaps& caps) const;
53
Robert Phillipsc7635fa2016-10-28 13:25:24 -040054 GrRenderTarget::Flags testingOnly_getFlags() 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 Phillips37430132016-11-09 06:50:43 -050060 friend class GrSurfaceProxy; // for ctors
61
csmartdaltonf9635992016-08-10 11:09:07 -070062 // Deferred version
Robert Phillipsc787e492017-02-28 11:26:32 -050063 GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&,
64 SkBackingFit, SkBudgeted, uint32_t flags);
robertphillips76948d42016-05-04 12:47:41 -070065
66 // Wrapped version
Robert Phillips37430132016-11-09 06:50:43 -050067 GrRenderTargetProxy(sk_sp<GrSurface>);
robertphillips76948d42016-05-04 12:47:41 -070068
Robert Phillips84a81202016-11-04 11:59:10 -040069private:
Robert Phillips8bc06d02016-11-01 17:28:40 -040070 size_t onGpuMemorySize() const override;
71
Robert Phillipsc7635fa2016-10-28 13:25:24 -040072 // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
73 // For deferred proxies that pointer is filled in when we need to instantiate the
74 // deferred resource.
robertphillips76948d42016-05-04 12:47:41 -070075
csmartdaltonf9635992016-08-10 11:09:07 -070076 // These don't usually get computed until the render target is instantiated, but the render
77 // target proxy may need to answer queries about it before then. And since in the deferred case
78 // we know the newly created render target will be internal, we are able to precompute what the
79 // flags will ultimately end up being. In the wrapped case we just copy the wrapped
robertphillips76948d42016-05-04 12:47:41 -070080 // rendertarget's info here.
Brian Salomondac5f6b2017-02-28 16:11:04 -050081 GrRenderTarget::Flags fRenderTargetFlags;
robertphillips76948d42016-05-04 12:47:41 -070082
robertphillips76948d42016-05-04 12:47:41 -070083 typedef GrSurfaceProxy INHERITED;
84};
85
86#endif