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