Flutter Engine
The Flutter Engine
GrRenderTarget.h
Go to the documentation of this file.
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"
14
15class GrCaps;
16class GrAttachment;
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 */
26class GrRenderTarget : virtual public GrSurface {
27public:
28 // Make manual MSAA resolve publicly accessible from GrRenderTarget.
31
32 virtual bool alwaysClearStencil() const { return false; }
33
34 // GrSurface overrides
35 GrRenderTarget* asRenderTarget() override { return this; }
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 */
41 int numSamples() const { return fSampleCnt; }
42
44
45 GrAttachment* getStencilAttachment(bool useMSAASurface) const {
46 return (useMSAASurface) ? fMSAAStencilAttachment.get() : fStencilAttachment.get();
47 }
48
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 */
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 */
72
73protected:
75 const SkISize&,
76 int sampleCount,
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
86private:
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
Definition: GrCaps.h:57
Definition: GrGpu.h:62
GrAttachment * getStencilAttachment() const
GrRenderTarget * asRenderTarget() override
void onAbandon() override
void onRelease() override
virtual GrBackendRenderTarget getBackendRenderTarget() const =0
const skia_private::TArray< SkPoint > & getSampleLocations()
void attachStencilAttachment(sk_sp< GrAttachment > stencil, bool useMSAASurface)
virtual bool alwaysClearStencil() const
int numSamples() const
int getSamplePatternKey()
GrAttachment * getStencilAttachment(bool useMSAASurface) const
GrRenderTarget(GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
virtual bool canAttemptStencilAttachment(bool useMSAASurface) const =0
virtual bool completeStencilAttachment(GrAttachment *stencil, bool useMSAASurface)=0
~GrRenderTarget() override
int numStencilBits(bool useMSAASurface) const
const GrRenderTarget * asRenderTarget() const override
void setRequiresManualMSAAResolve()
Definition: GrSurface.h:121
GrSurface(GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
Definition: GrSurface.h:140
bool requiresManualMSAAResolve() const
Definition: GrSurface.h:126
T * get() const
Definition: SkRefCnt.h:303
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16