blob: 7a6f44c570dfff230d5bf500b42e5289b16619ee [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001/*
reed@google.comdd335ae2012-12-13 19:24:05 +00002 * 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.
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00006 */
7
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00008#ifndef GrRenderTarget_DEFINED
9#define GrRenderTarget_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
12#include "include/gpu/GrSurface.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000013
robertphillips76948d42016-05-04 12:47:41 -070014class GrCaps;
Robert Phillipsf2361d22016-10-25 14:20:06 -040015class GrRenderTargetOpList;
bsalomon6bc1b5f2015-02-23 09:06:38 -080016class GrRenderTargetPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040017class GrStencilAttachment;
Robert Phillipsb67821d2017-12-13 15:00:45 -050018class GrBackendRenderTarget;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000019
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
bsalomon37dd3312014-11-03 08:47:23 -080023 * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000024 * Additionally, GrContext provides methods for creating GrRenderTargets
25 * that wrap externally created render targets.
26 */
bsalomon37dd3312014-11-03 08:47:23 -080027class GrRenderTarget : virtual public GrSurface {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000028public:
Chris Dalton3f7932e2019-08-19 00:39:13 -060029 // Make setRequiresManualMSAAResolve publicly accessible from GrRenderTarget.
30 using GrSurface::setRequiresManualMSAAResolve;
31
Robert Phillipscb2e2352017-08-30 16:44:40 -040032 virtual bool alwaysClearStencil() const { return false; }
33
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000034 // GrSurface overrides
mtklein36352bf2015-03-25 18:17:31 -070035 GrRenderTarget* asRenderTarget() override { return this; }
Brian Salomon9f7d9a22018-12-11 19:01:32 +000036 const GrRenderTarget* asRenderTarget() const override { return this; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000037
vbuzinovdded6962015-06-12 08:59:45 -070038 /**
Chris Dalton6ce447a2019-06-23 18:07:38 -060039 * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
vbuzinovdded6962015-06-12 08:59:45 -070040 */
Chris Dalton6ce447a2019-06-23 18:07:38 -060041 int numSamples() const { return fSampleCnt; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000042
43 /**
44 * Call to indicate the multisample contents were modified such that the
45 * render target needs to be resolved before it can be used as texture. Gr
46 * tracks this for its own drawing and thus this only needs to be called
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000047 * when the render target has been modified outside of Gr. This has no
48 * effect on wrapped backend render targets.
49 *
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000050 * @param rect a rect bounding the area needing resolve. NULL indicates
51 * the whole RT needs resolving.
52 */
Ben Wagnera93a14a2017-08-28 10:34:05 -040053 void flagAsNeedingResolve(const SkIRect* rect = nullptr);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000054
55 /**
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000056 * Call to indicate that GrRenderTarget was externally resolved. This may
57 * allow Gr to skip a redundant resolve step.
58 */
Mike Reed274218e2018-01-08 15:05:02 -050059 void flagAsResolved();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000060
61 /**
62 * @return true if the GrRenderTarget requires MSAA resolving
63 */
64 bool needsResolve() const { return !fResolveRect.isEmpty(); }
65
66 /**
67 * Returns a rect bounding the region needing resolving.
68 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000069 const SkIRect& getResolveRect() const { return fResolveRect; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000071 // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
rmistry@google.comfbfcd562012-08-23 18:09:54 +000072 // 0 in GL), or be unresolvable because the client didn't give us the
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073 // resolve destination.
74 enum ResolveType {
75 kCanResolve_ResolveType,
76 kAutoResolves_ResolveType,
77 kCantResolve_ResolveType,
78 };
79 virtual ResolveType getResolveType() const = 0;
80
Robert Phillipsb67821d2017-12-13 15:00:45 -050081 virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
82
egdanielec00d942015-09-14 12:56:10 -070083 // Checked when this object is asked to attach a stencil buffer.
84 virtual bool canAttemptStencilAttachment() const = 0;
85
bsalomon6bc1b5f2015-02-23 09:06:38 -080086 // Provides access to functions that aren't part of the public API.
87 GrRenderTargetPriv renderTargetPriv();
88 const GrRenderTargetPriv renderTargetPriv() const;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000089
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090protected:
Brian Salomona9c22572019-08-05 12:57:09 -040091 GrRenderTarget(GrGpu*, const SkISize&, GrPixelConfig, int sampleCount, GrProtected,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040092 GrStencilAttachment* = nullptr);
Ben Wagner9ec70c62018-07-12 13:30:47 -040093 ~GrRenderTarget() override;
robertphillips498d7ac2015-10-30 10:11:30 -070094
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000095 // override of GrResource
mtklein36352bf2015-03-25 18:17:31 -070096 void onAbandon() override;
97 void onRelease() override;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000098
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000099private:
egdanielec00d942015-09-14 12:56:10 -0700100 // Allows the backends to perform any additional work that is required for attaching a
101 // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
102 // the GrRenderTarget. This function must return false if any failures occur when completing the
103 // stencil attachment.
104 virtual bool completeStencilAttachment() = 0;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800105
106 friend class GrRenderTargetPriv;
107
Chris Daltond7291ba2019-03-07 14:17:03 -0700108 int fSampleCnt;
109 int fSamplePatternKey;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400110 sk_sp<GrStencilAttachment> fStencilAttachment;
Chris Daltond7291ba2019-03-07 14:17:03 -0700111 SkIRect fResolveRect;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000112
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000113 typedef GrSurface INHERITED;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000114};
115
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000116#endif