bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | /* |
reed@google.com | dd335ae | 2012-12-13 19:24:05 +0000 | [diff] [blame] | 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. |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 8 | #ifndef GrRenderTarget_DEFINED |
| 9 | #define GrRenderTarget_DEFINED |
| 10 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 11 | #include "GrSurface.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 12 | #include "SkRect.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 13 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 14 | class GrCaps; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 15 | class GrDrawTarget; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 16 | class GrStencilAttachment; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 17 | class GrRenderTargetPriv; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 22 | * created by a createTexture with the kRenderTarget_SurfaceFlag flag. |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 23 | * Additionally, GrContext provides methods for creating GrRenderTargets |
| 24 | * that wrap externally created render targets. |
| 25 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 26 | class GrRenderTarget : virtual public GrSurface { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 27 | public: |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 28 | // GrSurface overrides |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | GrRenderTarget* asRenderTarget() override { return this; } |
| 30 | const GrRenderTarget* asRenderTarget() const override { return this; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 31 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 32 | // GrRenderTarget |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 33 | bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 36 | * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color |
| 37 | * buffer is not. |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 38 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 39 | bool isMixedSampled() const { return fFlags & Flags::kMixedSampled; } |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 42 | * "Unified Sampled" means the stencil and color buffers are both multisampled. |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 43 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 44 | bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); } |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 47 | * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA). |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 48 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 49 | int numStencilSamples() const { return fDesc.fSampleCnt; } |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 52 | * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled). |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 53 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 54 | int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Call to indicate the multisample contents were modified such that the |
| 58 | * render target needs to be resolved before it can be used as texture. Gr |
| 59 | * tracks this for its own drawing and thus this only needs to be called |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 60 | * when the render target has been modified outside of Gr. This has no |
| 61 | * effect on wrapped backend render targets. |
| 62 | * |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 63 | * @param rect a rect bounding the area needing resolve. NULL indicates |
| 64 | * the whole RT needs resolving. |
| 65 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 66 | void flagAsNeedingResolve(const SkIRect* rect = NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Call to override the region that needs to be resolved. |
| 70 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 71 | void overrideResolveRect(const SkIRect rect); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Call to indicate that GrRenderTarget was externally resolved. This may |
| 75 | * allow Gr to skip a redundant resolve step. |
| 76 | */ |
| 77 | void flagAsResolved() { fResolveRect.setLargestInverted(); } |
| 78 | |
| 79 | /** |
| 80 | * @return true if the GrRenderTarget requires MSAA resolving |
| 81 | */ |
| 82 | bool needsResolve() const { return !fResolveRect.isEmpty(); } |
| 83 | |
| 84 | /** |
| 85 | * Returns a rect bounding the region needing resolving. |
| 86 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 87 | const SkIRect& getResolveRect() const { return fResolveRect; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 88 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 89 | /** |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 90 | * Provide a performance hint that the render target's contents are allowed |
| 91 | * to become undefined. |
| 92 | */ |
| 93 | void discard(); |
| 94 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 95 | // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 96 | // 0 in GL), or be unresolvable because the client didn't give us the |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 97 | // resolve destination. |
| 98 | enum ResolveType { |
| 99 | kCanResolve_ResolveType, |
| 100 | kAutoResolves_ResolveType, |
| 101 | kCantResolve_ResolveType, |
| 102 | }; |
| 103 | virtual ResolveType getResolveType() const = 0; |
| 104 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Return the native ID or handle to the rendertarget, depending on the |
| 107 | * platform. e.g. on OpenGL, return the FBO ID. |
| 108 | */ |
| 109 | virtual GrBackendObject getRenderTargetHandle() const = 0; |
| 110 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 111 | // Checked when this object is asked to attach a stencil buffer. |
| 112 | virtual bool canAttemptStencilAttachment() const = 0; |
| 113 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 114 | // Provides access to functions that aren't part of the public API. |
| 115 | GrRenderTargetPriv renderTargetPriv(); |
| 116 | const GrRenderTargetPriv renderTargetPriv() const; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 117 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 118 | void setLastDrawTarget(GrDrawTarget* dt); |
| 119 | GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } |
| 120 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 121 | protected: |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 122 | enum class Flags { |
| 123 | kNone = 0, |
| 124 | kMixedSampled = 1 << 0, |
| 125 | kWindowRectsSupport = 1 << 1 |
| 126 | }; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 127 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 128 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); |
| 129 | |
| 130 | GrRenderTarget(GrGpu*, const GrSurfaceDesc&, Flags = Flags::kNone, |
| 131 | GrStencilAttachment* = nullptr); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 132 | ~GrRenderTarget() override; |
| 133 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 134 | // override of GrResource |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 135 | void onAbandon() override; |
| 136 | void onRelease() override; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 137 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 138 | private: |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 139 | // Allows the backends to perform any additional work that is required for attaching a |
| 140 | // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto |
| 141 | // the GrRenderTarget. This function must return false if any failures occur when completing the |
| 142 | // stencil attachment. |
| 143 | virtual bool completeStencilAttachment() = 0; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 144 | |
| 145 | friend class GrRenderTargetPriv; |
| 146 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 147 | GrStencilAttachment* fStencilAttachment; |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 148 | uint8_t fMultisampleSpecsID; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 149 | Flags fFlags; |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 150 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 151 | SkIRect fResolveRect; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 152 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 153 | // The last drawTarget that wrote to or is currently going to write to this renderTarget |
| 154 | // The drawTarget can be closed (e.g., no draw context is currently bound |
| 155 | // to this renderTarget). |
| 156 | // This back-pointer is required so that we can add a dependancy between |
| 157 | // the drawTarget used to create the current contents of this renderTarget |
| 158 | // and the drawTarget of a destination renderTarget to which this one is being drawn. |
| 159 | GrDrawTarget* fLastDrawTarget; |
| 160 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 161 | typedef GrSurface INHERITED; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame^] | 164 | GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTarget::Flags); |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 165 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 166 | #endif |