Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrRenderTarget.h
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 GrDrawTarget;
16 class GrStencilAttachment;
17 class GrRenderTargetPriv;
18 
26 class GrRenderTarget : virtual public GrSurface {
27 public:
28  // GrSurface overrides
29  GrRenderTarget* asRenderTarget() override { return this; }
30  const GrRenderTarget* asRenderTarget() const override { return this; }
31 
32  // GrRenderTarget
33  bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; }
34 
39  bool isMixedSampled() const { return fFlags & Flags::kMixedSampled; }
40 
44  bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); }
45 
49  int numStencilSamples() const { return fDesc.fSampleCnt; }
50 
54  int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; }
55 
66  void flagAsNeedingResolve(const SkIRect* rect = NULL);
67 
71  void overrideResolveRect(const SkIRect rect);
72 
77  void flagAsResolved() { fResolveRect.setLargestInverted(); }
78 
82  bool needsResolve() const { return !fResolveRect.isEmpty(); }
83 
87  const SkIRect& getResolveRect() const { return fResolveRect; }
88 
93  void discard();
94 
95  // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
96  // 0 in GL), or be unresolvable because the client didn't give us the
97  // resolve destination.
98  enum ResolveType {
99  kCanResolve_ResolveType,
100  kAutoResolves_ResolveType,
101  kCantResolve_ResolveType,
102  };
103  virtual ResolveType getResolveType() const = 0;
104 
109  virtual GrBackendObject getRenderTargetHandle() const = 0;
110 
111  // Checked when this object is asked to attach a stencil buffer.
112  virtual bool canAttemptStencilAttachment() const = 0;
113 
114  // Provides access to functions that aren't part of the public API.
115  GrRenderTargetPriv renderTargetPriv();
116  const GrRenderTargetPriv renderTargetPriv() const;
117 
118  void setLastDrawTarget(GrDrawTarget* dt);
119  GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; }
120 
121 protected:
122  enum class Flags {
123  kNone = 0,
124  kMixedSampled = 1 << 0,
125  kWindowRectsSupport = 1 << 1
126  };
127 
128  GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);
129 
130  GrRenderTarget(GrGpu*, const GrSurfaceDesc&, Flags = Flags::kNone,
131  GrStencilAttachment* = nullptr);
132  ~GrRenderTarget() override;
133 
134  // override of GrResource
135  void onAbandon() override;
136  void onRelease() override;
137 
138 private:
139  // Allows the backends to perform any additional work that is required for attaching a
140  // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
141  // the GrRenderTarget. This function must return false if any failures occur when completing the
142  // stencil attachment.
143  virtual bool completeStencilAttachment() = 0;
144 
145  friend class GrRenderTargetPriv;
146 
147  GrStencilAttachment* fStencilAttachment;
148  uint8_t fMultisampleSpecsID;
149  Flags fFlags;
150 
151  SkIRect fResolveRect;
152 
153  // The last drawTarget that wrote to or is currently going to write to this renderTarget
154  // The drawTarget can be closed (e.g., no draw context is currently bound
155  // to this renderTarget).
156  // This back-pointer is required so that we can add a dependancy between
157  // the drawTarget used to create the current contents of this renderTarget
158  // and the drawTarget of a destination renderTarget to which this one is being drawn.
159  GrDrawTarget* fLastDrawTarget;
160 
161  typedef GrSurface INHERITED;
162 };
163 
164 GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTarget::Flags);
165 
166 #endif
Represents the capabilities of a GrContext.
Definition: GrCaps.h:130
bool isUnifiedMultisampled() const
"Unified Sampled" means the stencil and color buffers are both multisampled.
Definition: GrRenderTarget.h:44
Describes a surface to be created.
Definition: GrTypes.h:467
void overrideResolveRect(const SkIRect rect)
Call to override the region that needs to be resolved.
bool needsResolve() const
Definition: GrRenderTarget.h:82
Definition: GrSurface.h:21
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:103
void onRelease() override
Overridden to free GPU resources in the backend API.
GrRenderTarget * asRenderTarget() override
Definition: GrRenderTarget.h:29
int numColorSamples() const
Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled)...
Definition: GrRenderTarget.h:54
const SkIRect & getResolveRect() const
Returns a rect bounding the region needing resolving.
Definition: GrRenderTarget.h:87
void discard()
Provide a performance hint that the render target's contents are allowed to become undefined...
int fSampleCnt
The number of samples per pixel or 0 to disable full scene AA.
Definition: GrTypes.h:496
virtual GrBackendObject getRenderTargetHandle() const =0
Return the native ID or handle to the rendertarget, depending on the platform.
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
bool isMixedSampled() const
For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color buffer is no...
Definition: GrRenderTarget.h:39
void onAbandon() override
Overridden to abandon any internal handles, ptrs, etc to backend API resources.
void flagAsResolved()
Call to indicate that GrRenderTarget was externally resolved.
Definition: GrRenderTarget.h:77
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
void flagAsNeedingResolve(const SkIRect *rect=NULL)
Call to indicate the multisample contents were modified such that the render target needs to be resol...
int numStencilSamples() const
Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
Definition: GrRenderTarget.h:49
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:157