Skia
2DGraphicsLibrary
 All Classes Namespaces 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 GrRenderTargetOpList;
16 class GrRenderTargetPriv;
17 class GrStencilAttachment;
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 fSampleCnt > 0; }
34 
35  GrFSAAType fsaaType() const {
36  if (!fSampleCnt) {
37  SkASSERT(!(fFlags & GrRenderTargetFlags::kMixedSampled));
38  return GrFSAAType::kNone;
39  }
40  return (fFlags & GrRenderTargetFlags::kMixedSampled) ? GrFSAAType::kMixedSamples
41  : GrFSAAType::kUnifiedMSAA;
42  }
43 
47  int numStencilSamples() const { return fSampleCnt; }
48 
52  int numColorSamples() const {
53  return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fSampleCnt;
54  }
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 
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 
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  GrRenderTarget(GrGpu*, const GrSurfaceDesc&,
114  GrRenderTargetFlags = GrRenderTargetFlags::kNone,
115  GrStencilAttachment* = nullptr);
116 
117  // override of GrResource
118  void onAbandon() override;
119  void onRelease() override;
120 
121 private:
122  // Allows the backends to perform any additional work that is required for attaching a
123  // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
124  // the GrRenderTarget. This function must return false if any failures occur when completing the
125  // stencil attachment.
126  virtual bool completeStencilAttachment() = 0;
127 
128  friend class GrRenderTargetPriv;
129 
130  int fSampleCnt;
131  GrStencilAttachment* fStencilAttachment;
132  uint8_t fMultisampleSpecsID;
133  GrRenderTargetFlags fFlags;
134 
135  SkIRect fResolveRect;
136 
137  typedef GrSurface INHERITED;
138 };
139 
140 #endif
Represents the capabilities of a GrContext.
Definition: GrCaps.h:24
Describes a surface to be created.
Definition: GrTypes.h:589
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:52
const SkIRect & getResolveRect() const
Returns a rect bounding the region needing resolving.
Definition: GrRenderTarget.h:87
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
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:47
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:157