blob: 2c330dadf40839ee4e693e380c414623d3fc02c7 [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:
Robert Phillipscb2e2352017-08-30 16:44:40 -040029 virtual bool alwaysClearStencil() const { return false; }
30
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031 // GrSurface overrides
mtklein36352bf2015-03-25 18:17:31 -070032 GrRenderTarget* asRenderTarget() override { return this; }
Brian Salomon9f7d9a22018-12-11 19:01:32 +000033 const GrRenderTarget* asRenderTarget() const override { return this; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000034
vbuzinovdded6962015-06-12 08:59:45 -070035 /**
Chris Dalton6ce447a2019-06-23 18:07:38 -060036 * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
vbuzinovdded6962015-06-12 08:59:45 -070037 */
Chris Dalton6ce447a2019-06-23 18:07:38 -060038 int numSamples() const { return fSampleCnt; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000039
40 /**
41 * Call to indicate the multisample contents were modified such that the
42 * render target needs to be resolved before it can be used as texture. Gr
43 * tracks this for its own drawing and thus this only needs to be called
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000044 * when the render target has been modified outside of Gr. This has no
45 * effect on wrapped backend render targets.
46 *
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000047 * @param rect a rect bounding the area needing resolve. NULL indicates
48 * the whole RT needs resolving.
49 */
Ben Wagnera93a14a2017-08-28 10:34:05 -040050 void flagAsNeedingResolve(const SkIRect* rect = nullptr);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000051
52 /**
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000053 * Call to indicate that GrRenderTarget was externally resolved. This may
54 * allow Gr to skip a redundant resolve step.
55 */
Mike Reed274218e2018-01-08 15:05:02 -050056 void flagAsResolved();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000057
58 /**
59 * @return true if the GrRenderTarget requires MSAA resolving
60 */
61 bool needsResolve() const { return !fResolveRect.isEmpty(); }
62
63 /**
64 * Returns a rect bounding the region needing resolving.
65 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000066 const SkIRect& getResolveRect() const { return fResolveRect; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000067
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000068 // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
rmistry@google.comfbfcd562012-08-23 18:09:54 +000069 // 0 in GL), or be unresolvable because the client didn't give us the
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070 // resolve destination.
71 enum ResolveType {
72 kCanResolve_ResolveType,
73 kAutoResolves_ResolveType,
74 kCantResolve_ResolveType,
75 };
76 virtual ResolveType getResolveType() const = 0;
77
Robert Phillipsb67821d2017-12-13 15:00:45 -050078 virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
79
egdanielec00d942015-09-14 12:56:10 -070080 // Checked when this object is asked to attach a stencil buffer.
81 virtual bool canAttemptStencilAttachment() const = 0;
82
bsalomon6bc1b5f2015-02-23 09:06:38 -080083 // Provides access to functions that aren't part of the public API.
84 GrRenderTargetPriv renderTargetPriv();
85 const GrRenderTargetPriv renderTargetPriv() const;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000086
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000087protected:
Brian Salomona9c22572019-08-05 12:57:09 -040088 GrRenderTarget(GrGpu*, const SkISize&, GrPixelConfig, int sampleCount, GrProtected,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040089 GrStencilAttachment* = nullptr);
Ben Wagner9ec70c62018-07-12 13:30:47 -040090 ~GrRenderTarget() override;
robertphillips498d7ac2015-10-30 10:11:30 -070091
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000092 // override of GrResource
mtklein36352bf2015-03-25 18:17:31 -070093 void onAbandon() override;
94 void onRelease() override;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000095
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000096private:
egdanielec00d942015-09-14 12:56:10 -070097 // Allows the backends to perform any additional work that is required for attaching a
98 // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
99 // the GrRenderTarget. This function must return false if any failures occur when completing the
100 // stencil attachment.
101 virtual bool completeStencilAttachment() = 0;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800102
103 friend class GrRenderTargetPriv;
104
Chris Daltond7291ba2019-03-07 14:17:03 -0700105 int fSampleCnt;
106 int fSamplePatternKey;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400107 sk_sp<GrStencilAttachment> fStencilAttachment;
Chris Daltond7291ba2019-03-07 14:17:03 -0700108 SkIRect fResolveRect;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000109
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000110 typedef GrSurface INHERITED;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000111};
112
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000113#endif