| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrRenderTarget_DEFINED | 8 #ifndef GrRenderTarget_DEFINED |
| 9 #define GrRenderTarget_DEFINED | 9 #define GrRenderTarget_DEFINED |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * Additionally, GrContext provides methods for creating GrRenderTargets | 23 * Additionally, GrContext provides methods for creating GrRenderTargets |
| 24 * that wrap externally created render targets. | 24 * that wrap externally created render targets. |
| 25 */ | 25 */ |
| 26 class GrRenderTarget : virtual public GrSurface { | 26 class GrRenderTarget : virtual public GrSurface { |
| 27 public: | 27 public: |
| 28 // GrSurface overrides | 28 // GrSurface overrides |
| 29 GrRenderTarget* asRenderTarget() override { return this; } | 29 GrRenderTarget* asRenderTarget() override { return this; } |
| 30 const GrRenderTarget* asRenderTarget() const override { return this; } | 30 const GrRenderTarget* asRenderTarget() const override { return this; } |
| 31 | 31 |
| 32 // GrRenderTarget | 32 // GrRenderTarget |
| 33 /** | 33 bool isOffscreen() const { return fFlags & Flags::kOffscreen; } |
| 34 * On some hardware it is possible for a render target to have multisampling | 34 |
| 35 * only in certain buffers. | 35 bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } |
| 36 * Enforce only two legal sample configs. | |
| 37 * kUnified_SampleConfig signifies multisampling in both color and stencil | |
| 38 * buffers and is available across all hardware. | |
| 39 * kStencil_SampleConfig means multisampling is present in stencil buffer | |
| 40 * only; this config requires hardware support of | |
| 41 * NV_framebuffer_mixed_samples. | |
| 42 */ | |
| 43 enum SampleConfig { | |
| 44 kUnified_SampleConfig = 0, | |
| 45 kStencil_SampleConfig = 1 | |
| 46 }; | |
| 47 | 36 |
| 48 /** | 37 /** |
| 49 * @return true if the surface is multisampled in all buffers, | 38 * For our purposes, "Mixed Sampled" means the stencil buffer is multisample
d but the color |
| 50 * false otherwise | 39 * buffer is not. |
| 51 */ | 40 */ |
| 52 bool isUnifiedMultisampled() const { | 41 bool isMixedSampled() const { return fFlags & Flags::kMixedSampled; } |
| 53 if (fSampleConfig != kUnified_SampleConfig) { | |
| 54 return false; | |
| 55 } | |
| 56 return 0 != fDesc.fSampleCnt; | |
| 57 } | |
| 58 | 42 |
| 59 /** | 43 /** |
| 60 * @return true if the surface is multisampled in the stencil buffer, | 44 * "Unified Sampled" means the stencil and color buffers are both multisampl
ed. |
| 61 * false otherwise | |
| 62 */ | 45 */ |
| 63 bool isStencilBufferMultisampled() const { | 46 bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->i
sMixedSampled(); } |
| 64 return 0 != fDesc.fSampleCnt; | |
| 65 } | |
| 66 | 47 |
| 67 /** | 48 /** |
| 68 * @return the number of color samples-per-pixel, or zero if non-MSAA or | 49 * Returns the number of samples/pixel in the stencil buffer (Zero if non-MS
AA). |
| 69 * multisampled in the stencil buffer only. | |
| 70 */ | 50 */ |
| 71 int numColorSamples() const { | 51 int numStencilSamples() const { return fDesc.fSampleCnt; } |
| 72 if (fSampleConfig == kUnified_SampleConfig) { | |
| 73 return fDesc.fSampleCnt; | |
| 74 } | |
| 75 return 0; | |
| 76 } | |
| 77 | 52 |
| 78 /** | 53 /** |
| 79 * @return the number of stencil samples-per-pixel, or zero if non-MSAA. | 54 * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA
or mixed sampled). |
| 80 */ | 55 */ |
| 81 int numStencilSamples() const { | 56 int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSam
pleCnt; } |
| 82 return fDesc.fSampleCnt; | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * @return true if the surface is mixed sampled, false otherwise. | |
| 87 */ | |
| 88 bool hasMixedSamples() const { | |
| 89 SkASSERT(kStencil_SampleConfig != fSampleConfig || | |
| 90 this->isStencilBufferMultisampled()); | |
| 91 return kStencil_SampleConfig == fSampleConfig; | |
| 92 } | |
| 93 | 57 |
| 94 /** | 58 /** |
| 95 * Call to indicate the multisample contents were modified such that the | 59 * Call to indicate the multisample contents were modified such that the |
| 96 * render target needs to be resolved before it can be used as texture. Gr | 60 * render target needs to be resolved before it can be used as texture. Gr |
| 97 * tracks this for its own drawing and thus this only needs to be called | 61 * tracks this for its own drawing and thus this only needs to be called |
| 98 * when the render target has been modified outside of Gr. This has no | 62 * when the render target has been modified outside of Gr. This has no |
| 99 * effect on wrapped backend render targets. | 63 * effect on wrapped backend render targets. |
| 100 * | 64 * |
| 101 * @param rect a rect bounding the area needing resolve. NULL indicates | 65 * @param rect a rect bounding the area needing resolve. NULL indicates |
| 102 * the whole RT needs resolving. | 66 * the whole RT needs resolving. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Checked when this object is asked to attach a stencil buffer. | 113 // Checked when this object is asked to attach a stencil buffer. |
| 150 virtual bool canAttemptStencilAttachment() const = 0; | 114 virtual bool canAttemptStencilAttachment() const = 0; |
| 151 | 115 |
| 152 // Provides access to functions that aren't part of the public API. | 116 // Provides access to functions that aren't part of the public API. |
| 153 GrRenderTargetPriv renderTargetPriv(); | 117 GrRenderTargetPriv renderTargetPriv(); |
| 154 const GrRenderTargetPriv renderTargetPriv() const; | 118 const GrRenderTargetPriv renderTargetPriv() const; |
| 155 | 119 |
| 156 void setLastDrawTarget(GrDrawTarget* dt); | 120 void setLastDrawTarget(GrDrawTarget* dt); |
| 157 GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } | 121 GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } |
| 158 | 122 |
| 159 static SampleConfig ComputeSampleConfig(const GrCaps& caps, int sampleCnt); | 123 protected: |
| 124 enum class Flags { |
| 125 kNone = 0, |
| 126 kOffscreen = 1 << 0, |
| 127 kMixedSampled = 1 << 1 |
| 128 }; |
| 160 | 129 |
| 161 protected: | 130 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); |
| 162 GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, | 131 |
| 163 SampleConfig sampleConfig, GrStencilAttachment* stencil = nul
lptr) | 132 GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, Flags flags, |
| 133 GrStencilAttachment* stencil = nullptr) |
| 164 : INHERITED(gpu, desc) | 134 : INHERITED(gpu, desc) |
| 165 , fStencilAttachment(stencil) | 135 , fStencilAttachment(stencil) |
| 166 , fMultisampleSpecsID(0) | 136 , fMultisampleSpecsID(0) |
| 167 , fSampleConfig(sampleConfig) | 137 , fFlags(flags) |
| 168 , fLastDrawTarget(nullptr) { | 138 , fLastDrawTarget(nullptr) { |
| 139 SkASSERT(!(fFlags & Flags::kMixedSampled) || fDesc.fSampleCnt > 0); |
| 169 fResolveRect.setLargestInverted(); | 140 fResolveRect.setLargestInverted(); |
| 170 } | 141 } |
| 171 | 142 |
| 172 ~GrRenderTarget() override; | 143 ~GrRenderTarget() override; |
| 173 | 144 |
| 174 // override of GrResource | 145 // override of GrResource |
| 175 void onAbandon() override; | 146 void onAbandon() override; |
| 176 void onRelease() override; | 147 void onRelease() override; |
| 177 | 148 |
| 178 private: | 149 private: |
| 179 // Allows the backends to perform any additional work that is required for a
ttaching a | 150 // Allows the backends to perform any additional work that is required for a
ttaching a |
| 180 // GrStencilAttachment. When this is called, the GrStencilAttachment has alr
eady been put onto | 151 // GrStencilAttachment. When this is called, the GrStencilAttachment has alr
eady been put onto |
| 181 // the GrRenderTarget. This function must return false if any failures occur
when completing the | 152 // the GrRenderTarget. This function must return false if any failures occur
when completing the |
| 182 // stencil attachment. | 153 // stencil attachment. |
| 183 virtual bool completeStencilAttachment() = 0; | 154 virtual bool completeStencilAttachment() = 0; |
| 184 | 155 |
| 185 friend class GrRenderTargetPriv; | 156 friend class GrRenderTargetPriv; |
| 186 | 157 |
| 187 GrStencilAttachment* fStencilAttachment; | 158 GrStencilAttachment* fStencilAttachment; |
| 188 uint8_t fMultisampleSpecsID; | 159 uint8_t fMultisampleSpecsID; |
| 189 SampleConfig fSampleConfig; | 160 Flags fFlags; |
| 190 | 161 |
| 191 SkIRect fResolveRect; | 162 SkIRect fResolveRect; |
| 192 | 163 |
| 193 // The last drawTarget that wrote to or is currently going to write to this
renderTarget | 164 // The last drawTarget that wrote to or is currently going to write to this
renderTarget |
| 194 // The drawTarget can be closed (e.g., no draw context is currently bound | 165 // The drawTarget can be closed (e.g., no draw context is currently bound |
| 195 // to this renderTarget). | 166 // to this renderTarget). |
| 196 // This back-pointer is required so that we can add a dependancy between | 167 // This back-pointer is required so that we can add a dependancy between |
| 197 // the drawTarget used to create the current contents of this renderTarget | 168 // the drawTarget used to create the current contents of this renderTarget |
| 198 // and the drawTarget of a destination renderTarget to which this one is bei
ng drawn. | 169 // and the drawTarget of a destination renderTarget to which this one is bei
ng drawn. |
| 199 GrDrawTarget* fLastDrawTarget; | 170 GrDrawTarget* fLastDrawTarget; |
| 200 | 171 |
| 201 typedef GrSurface INHERITED; | 172 typedef GrSurface INHERITED; |
| 202 }; | 173 }; |
| 203 | 174 |
| 175 GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTarget::Flags); |
| 204 | 176 |
| 205 #endif | 177 #endif |
| OLD | NEW |