Line data Source code
1 : /*
2 : * Copyright 2011 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 GrRenderTarget_DEFINED
9 : #define GrRenderTarget_DEFINED
10 :
11 : #include "GrSurface.h"
12 : #include "SkRect.h"
13 :
14 : class GrCaps;
15 : class GrRenderTargetOpList;
16 : class GrRenderTargetPriv;
17 : class GrStencilAttachment;
18 :
19 : /**
20 : * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
21 : * A context's render target is set by setRenderTarget(). Render targets are
22 : * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
23 : * Additionally, GrContext provides methods for creating GrRenderTargets
24 : * that wrap externally created render targets.
25 : */
26 0 : class GrRenderTarget : virtual public GrSurface {
27 : public:
28 : // GrSurface overrides
29 0 : GrRenderTarget* asRenderTarget() override { return this; }
30 0 : const GrRenderTarget* asRenderTarget() const override { return this; }
31 :
32 : // GrRenderTarget
33 0 : bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; }
34 :
35 : /**
36 : * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color
37 : * buffer is not.
38 : */
39 0 : bool isMixedSampled() const { return fFlags & Flags::kMixedSampled; }
40 :
41 : /**
42 : * "Unified Sampled" means the stencil and color buffers are both multisampled.
43 : */
44 0 : bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); }
45 :
46 : /**
47 : * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
48 : */
49 0 : int numStencilSamples() const { return fDesc.fSampleCnt; }
50 :
51 : /**
52 : * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled).
53 : */
54 0 : int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; }
55 :
56 : /**
57 : * Call to indicate the multisample contents were modified such that the
58 : * render target needs to be resolved before it can be used as texture. Gr
59 : * tracks this for its own drawing and thus this only needs to be called
60 : * when the render target has been modified outside of Gr. This has no
61 : * effect on wrapped backend render targets.
62 : *
63 : * @param rect a rect bounding the area needing resolve. NULL indicates
64 : * the whole RT needs resolving.
65 : */
66 : void flagAsNeedingResolve(const SkIRect* rect = NULL);
67 :
68 : /**
69 : * Call to override the region that needs to be resolved.
70 : */
71 : void overrideResolveRect(const SkIRect rect);
72 :
73 : /**
74 : * Call to indicate that GrRenderTarget was externally resolved. This may
75 : * allow Gr to skip a redundant resolve step.
76 : */
77 0 : void flagAsResolved() { fResolveRect.setLargestInverted(); }
78 :
79 : /**
80 : * @return true if the GrRenderTarget requires MSAA resolving
81 : */
82 0 : bool needsResolve() const { return !fResolveRect.isEmpty(); }
83 :
84 : /**
85 : * Returns a rect bounding the region needing resolving.
86 : */
87 0 : const SkIRect& getResolveRect() const { return fResolveRect; }
88 :
89 : // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
90 : // 0 in GL), or be unresolvable because the client didn't give us the
91 : // resolve destination.
92 : enum ResolveType {
93 : kCanResolve_ResolveType,
94 : kAutoResolves_ResolveType,
95 : kCantResolve_ResolveType,
96 : };
97 : virtual ResolveType getResolveType() const = 0;
98 :
99 : /**
100 : * Return the native ID or handle to the rendertarget, depending on the
101 : * platform. e.g. on OpenGL, return the FBO ID.
102 : */
103 : virtual GrBackendObject getRenderTargetHandle() const = 0;
104 :
105 : // Checked when this object is asked to attach a stencil buffer.
106 : virtual bool canAttemptStencilAttachment() const = 0;
107 :
108 : // Provides access to functions that aren't part of the public API.
109 : GrRenderTargetPriv renderTargetPriv();
110 : const GrRenderTargetPriv renderTargetPriv() const;
111 :
112 : protected:
113 : enum class Flags {
114 : kNone = 0,
115 : kMixedSampled = 1 << 0,
116 : kWindowRectsSupport = 1 << 1
117 : };
118 :
119 : GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);
120 :
121 : GrRenderTarget(GrGpu*, const GrSurfaceDesc&, Flags = Flags::kNone,
122 : GrStencilAttachment* = nullptr);
123 :
124 : // override of GrResource
125 : void onAbandon() override;
126 : void onRelease() override;
127 :
128 : private:
129 : // Allows the backends to perform any additional work that is required for attaching a
130 : // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
131 : // the GrRenderTarget. This function must return false if any failures occur when completing the
132 : // stencil attachment.
133 : virtual bool completeStencilAttachment() = 0;
134 :
135 : friend class GrRenderTargetPriv;
136 : friend class GrRenderTargetProxy; // for Flags
137 :
138 : GrStencilAttachment* fStencilAttachment;
139 : uint8_t fMultisampleSpecsID;
140 : Flags fFlags;
141 :
142 : SkIRect fResolveRect;
143 :
144 : typedef GrSurface INHERITED;
145 : };
146 :
147 0 : GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTarget::Flags);
148 :
149 : #endif
|