• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkRect.h"
12 #include "include/gpu/GrSurface.h"
13 
14 class GrCaps;
15 class GrRenderTargetOpList;
16 class GrRenderTargetPriv;
17 class GrStencilAttachment;
18 class GrBackendRenderTarget;
19 
20 /**
21  * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
22  * A context's render target is set by setRenderTarget(). Render targets are
23  * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
24  * Additionally, GrContext provides methods for creating GrRenderTargets
25  * that wrap externally created render targets.
26  */
27 class GrRenderTarget : virtual public GrSurface {
28 public:
alwaysClearStencil()29     virtual bool alwaysClearStencil() const { return false; }
30 
31     // GrSurface overrides
asRenderTarget()32     GrRenderTarget* asRenderTarget() override { return this; }
asRenderTarget()33     const GrRenderTarget* asRenderTarget() const  override { return this; }
34 
35     /**
36      * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
37      */
numSamples()38     int numSamples() const { return fSampleCnt; }
39 
40     /**
41      * Call to indicate the multisample contents were modified such that the
42      * render target needs to be resolved before it can be used as texture. Gr
43      * tracks this for its own drawing and thus this only needs to be called
44      * when the render target has been modified outside of Gr. This has no
45      * effect on wrapped backend render targets.
46      *
47      * @param rect  a rect bounding the area needing resolve. NULL indicates
48      *              the whole RT needs resolving.
49      */
50     void flagAsNeedingResolve(const SkIRect* rect = nullptr);
51 
52     /**
53      * Call to indicate that GrRenderTarget was externally resolved. This may
54      * allow Gr to skip a redundant resolve step.
55      */
56     void flagAsResolved();
57 
58     /**
59      * @return true if the GrRenderTarget requires MSAA resolving
60      */
needsResolve()61     bool needsResolve() const { return !fResolveRect.isEmpty(); }
62 
63     /**
64      * Returns a rect bounding the region needing resolving.
65      */
getResolveRect()66     const SkIRect& getResolveRect() const { return fResolveRect; }
67 
68     // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
69     // 0 in GL), or be unresolvable because the client didn't give us the
70     // resolve destination.
71     enum ResolveType {
72         kCanResolve_ResolveType,
73         kAutoResolves_ResolveType,
74         kCantResolve_ResolveType,
75     };
76     virtual ResolveType getResolveType() const = 0;
77 
78     virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
79 
80     // Checked when this object is asked to attach a stencil buffer.
81     virtual bool canAttemptStencilAttachment() const = 0;
82 
83     // Provides access to functions that aren't part of the public API.
84     GrRenderTargetPriv renderTargetPriv();
85     const GrRenderTargetPriv renderTargetPriv() const;
86 
87 protected:
88     GrRenderTarget(GrGpu*, const SkISize&, GrPixelConfig, int sampleCount, GrProtected,
89                    GrStencilAttachment* = nullptr);
90     ~GrRenderTarget() override;
91 
92     // override of GrResource
93     void onAbandon() override;
94     void onRelease() override;
95 
96 private:
97     // Allows the backends to perform any additional work that is required for attaching a
98     // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
99     // the GrRenderTarget. This function must return false if any failures occur when completing the
100     // stencil attachment.
101     virtual bool completeStencilAttachment() = 0;
102 
103     friend class GrRenderTargetPriv;
104 
105     int fSampleCnt;
106     int fSamplePatternKey;
107     sk_sp<GrStencilAttachment> fStencilAttachment;
108     SkIRect fResolveRect;
109 
110     typedef GrSurface INHERITED;
111 };
112 
113 #endif
114