• 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 "src/gpu/GrSurface.h"
13 
14 class GrCaps;
15 class GrAttachment;
16 class GrBackendRenderTarget;
17 
18 /**
19  * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
20  * A context's render target is set by setRenderTarget(). Render targets are
21  * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
22  * Additionally, GrContext provides methods for creating GrRenderTargets
23  * that wrap externally created render targets.
24  */
25 class GrRenderTarget : virtual public GrSurface {
26 public:
27     // Make manual MSAA resolve publicly accessible from GrRenderTarget.
28     using GrSurface::setRequiresManualMSAAResolve;
29     using GrSurface::requiresManualMSAAResolve;
30 
alwaysClearStencil()31     virtual bool alwaysClearStencil() const { return false; }
32 
33     // GrSurface overrides
asRenderTarget()34     GrRenderTarget* asRenderTarget() override { return this; }
asRenderTarget()35     const GrRenderTarget* asRenderTarget() const  override { return this; }
36 
37     /**
38      * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
39      */
numSamples()40     int numSamples() const { return fSampleCnt; }
41 
42     virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
43 
getStencilAttachment(bool useMSAASurface)44     GrAttachment* getStencilAttachment(bool useMSAASurface) const {
45         return (useMSAASurface) ? fMSAAStencilAttachment.get() : fStencilAttachment.get();
46     }
47 
getStencilAttachment()48     GrAttachment* getStencilAttachment() const {
49         return getStencilAttachment(this->numSamples() > 1);
50     }
51 
52     // Checked when this object is asked to attach a stencil buffer.
53     virtual bool canAttemptStencilAttachment(bool useMSAASurface) const = 0;
54 
55     void attachStencilAttachment(sk_sp<GrAttachment> stencil, bool useMSAASurface);
56 
57     int numStencilBits(bool useMSAASurface) const;
58 
59     /**
60      * Returns a unique key that identifies this render target's sample pattern. (Must be
61      * multisampled.)
62      */
63     int getSamplePatternKey();
64 
65     /**
66      * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the
67      * actual number of samples in use. (This may differ from fSampleCnt.) Sample locations are
68      * returned as 0..1 offsets relative to the top-left corner of the pixel.
69      */
70     const SkTArray<SkPoint>& getSampleLocations();
71 
72 protected:
73     GrRenderTarget(GrGpu*, const SkISize&, int sampleCount, GrProtected,
74                    sk_sp<GrAttachment> stenicl = nullptr);
75     ~GrRenderTarget() override;
76 
77     // override of GrResource
78     void onAbandon() override;
79     void onRelease() override;
80 
81 private:
82     // Allows the backends to perform any additional work that is required for attaching a
83     // GrAttachment. When this is called, the GrAttachment has already been put onto
84     // the GrRenderTarget. This function must return false if any failures occur when completing the
85     // stencil attachment.
86     virtual bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) = 0;
87 
88     sk_sp<GrAttachment> fStencilAttachment;
89     sk_sp<GrAttachment> fMSAAStencilAttachment;
90     int fSampleCnt;
91 
92     using INHERITED = GrSurface;
93 };
94 
95 #endif
96