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 GrStencilAttachment; |
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 | |
31 | virtual bool alwaysClearStencil() const { return false; } |
32 | |
33 | // GrSurface overrides |
34 | GrRenderTarget* asRenderTarget() override { return this; } |
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 | */ |
40 | int numSamples() const { return fSampleCnt; } |
41 | |
42 | virtual GrBackendRenderTarget getBackendRenderTarget() const = 0; |
43 | |
44 | GrStencilAttachment* getStencilAttachment() const { return fStencilAttachment.get(); } |
45 | // Checked when this object is asked to attach a stencil buffer. |
46 | virtual bool canAttemptStencilAttachment() const = 0; |
47 | |
48 | void attachStencilAttachment(sk_sp<GrStencilAttachment> stencil); |
49 | |
50 | int numStencilBits() const; |
51 | |
52 | /** |
53 | * Returns a unique key that identifies this render target's sample pattern. (Must be |
54 | * multisampled.) |
55 | */ |
56 | int getSamplePatternKey(); |
57 | |
58 | /** |
59 | * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the |
60 | * actual number of samples in use. (This may differ from fSampleCnt.) Sample locations are |
61 | * returned as 0..1 offsets relative to the top-left corner of the pixel. |
62 | */ |
63 | const SkTArray<SkPoint>& getSampleLocations(); |
64 | |
65 | protected: |
66 | GrRenderTarget(GrGpu*, const SkISize&, int sampleCount, GrProtected, |
67 | GrStencilAttachment* = nullptr); |
68 | ~GrRenderTarget() override; |
69 | |
70 | // override of GrResource |
71 | void onAbandon() override; |
72 | void onRelease() override; |
73 | |
74 | private: |
75 | // Allows the backends to perform any additional work that is required for attaching a |
76 | // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto |
77 | // the GrRenderTarget. This function must return false if any failures occur when completing the |
78 | // stencil attachment. |
79 | virtual bool completeStencilAttachment() = 0; |
80 | |
81 | sk_sp<GrStencilAttachment> fStencilAttachment; |
82 | int fSampleCnt; |
83 | int fSamplePatternKey; |
84 | |
85 | typedef GrSurface INHERITED; |
86 | }; |
87 | |
88 | #endif |
89 | |