blob: 4e594229c9a0bf8035d9d51649f70058685d338d [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;
bsalomon6bc1b5f2015-02-23 09:06:38 -080015class GrRenderTargetPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040016class GrStencilAttachment;
Robert Phillipsb67821d2017-12-13 15:00:45 -050017class GrBackendRenderTarget;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000018
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
bsalomon37dd3312014-11-03 08:47:23 -080022 * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000023 * Additionally, GrContext provides methods for creating GrRenderTargets
24 * that wrap externally created render targets.
25 */
bsalomon37dd3312014-11-03 08:47:23 -080026class GrRenderTarget : virtual public GrSurface {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000027public:
Chris Dalton3f7932e2019-08-19 00:39:13 -060028 // Make setRequiresManualMSAAResolve publicly accessible from GrRenderTarget.
29 using GrSurface::setRequiresManualMSAAResolve;
30
Robert Phillipscb2e2352017-08-30 16:44:40 -040031 virtual bool alwaysClearStencil() const { return false; }
32
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000033 // GrSurface overrides
mtklein36352bf2015-03-25 18:17:31 -070034 GrRenderTarget* asRenderTarget() override { return this; }
Brian Salomon9f7d9a22018-12-11 19:01:32 +000035 const GrRenderTarget* asRenderTarget() const override { return this; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000036
vbuzinovdded6962015-06-12 08:59:45 -070037 /**
Chris Dalton6ce447a2019-06-23 18:07:38 -060038 * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
vbuzinovdded6962015-06-12 08:59:45 -070039 */
Chris Dalton6ce447a2019-06-23 18:07:38 -060040 int numSamples() const { return fSampleCnt; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000041
42 /**
43 * Call to indicate the multisample contents were modified such that the
44 * render target needs to be resolved before it can be used as texture. Gr
45 * tracks this for its own drawing and thus this only needs to be called
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000046 * when the render target has been modified outside of Gr. This has no
47 * effect on wrapped backend render targets.
48 *
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000049 * @param rect a rect bounding the area needing resolve. NULL indicates
50 * the whole RT needs resolving.
51 */
Ben Wagnera93a14a2017-08-28 10:34:05 -040052 void flagAsNeedingResolve(const SkIRect* rect = nullptr);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000053
54 /**
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000055 * Call to indicate that GrRenderTarget was externally resolved. This may
56 * allow Gr to skip a redundant resolve step.
57 */
Mike Reed274218e2018-01-08 15:05:02 -050058 void flagAsResolved();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000059
60 /**
61 * @return true if the GrRenderTarget requires MSAA resolving
62 */
63 bool needsResolve() const { return !fResolveRect.isEmpty(); }
64
65 /**
66 * Returns a rect bounding the region needing resolving.
67 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000068 const SkIRect& getResolveRect() const { return fResolveRect; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000069
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070 // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
rmistry@google.comfbfcd562012-08-23 18:09:54 +000071 // 0 in GL), or be unresolvable because the client didn't give us the
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072 // resolve destination.
73 enum ResolveType {
74 kCanResolve_ResolveType,
75 kAutoResolves_ResolveType,
76 kCantResolve_ResolveType,
77 };
78 virtual ResolveType getResolveType() const = 0;
79
Robert Phillipsb67821d2017-12-13 15:00:45 -050080 virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
81
egdanielec00d942015-09-14 12:56:10 -070082 // Checked when this object is asked to attach a stencil buffer.
83 virtual bool canAttemptStencilAttachment() const = 0;
84
bsalomon6bc1b5f2015-02-23 09:06:38 -080085 // Provides access to functions that aren't part of the public API.
86 GrRenderTargetPriv renderTargetPriv();
87 const GrRenderTargetPriv renderTargetPriv() const;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000088
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089protected:
Brian Salomona9c22572019-08-05 12:57:09 -040090 GrRenderTarget(GrGpu*, const SkISize&, GrPixelConfig, int sampleCount, GrProtected,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040091 GrStencilAttachment* = nullptr);
Ben Wagner9ec70c62018-07-12 13:30:47 -040092 ~GrRenderTarget() override;
robertphillips498d7ac2015-10-30 10:11:30 -070093
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000094 // override of GrResource
mtklein36352bf2015-03-25 18:17:31 -070095 void onAbandon() override;
96 void onRelease() override;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000097
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000098private:
egdanielec00d942015-09-14 12:56:10 -070099 // Allows the backends to perform any additional work that is required for attaching a
100 // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
101 // the GrRenderTarget. This function must return false if any failures occur when completing the
102 // stencil attachment.
103 virtual bool completeStencilAttachment() = 0;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800104
105 friend class GrRenderTargetPriv;
106
Chris Daltond7291ba2019-03-07 14:17:03 -0700107 int fSampleCnt;
108 int fSamplePatternKey;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400109 sk_sp<GrStencilAttachment> fStencilAttachment;
Chris Daltond7291ba2019-03-07 14:17:03 -0700110 SkIRect fResolveRect;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000111
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000112 typedef GrSurface INHERITED;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000113};
114
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000115#endif