OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "gpu/command_buffer/service/context_group.h" | 17 #include "gpu/command_buffer/service/context_group.h" |
18 #include "gpu/command_buffer/service/gl_utils.h" | 18 #include "gpu/command_buffer/service/gl_utils.h" |
| 19 #include "gpu/command_buffer/service/shader_manager.h" |
19 #include "gpu/gpu_export.h" | 20 #include "gpu/gpu_export.h" |
20 | 21 |
21 namespace gpu { | 22 namespace gpu { |
22 namespace gles2 { | 23 namespace gles2 { |
23 | 24 |
24 class FeatureInfo; | 25 class FeatureInfo; |
25 class FramebufferCompletenessCache; | 26 class FramebufferCompletenessCache; |
26 class FramebufferManager; | 27 class FramebufferManager; |
27 class Renderbuffer; | 28 class Renderbuffer; |
28 class RenderbufferManager; | 29 class RenderbufferManager; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Check all attachments are cleared | 172 // Check all attachments are cleared |
172 bool IsCleared() const; | 173 bool IsCleared() const; |
173 | 174 |
174 GLenum GetDrawBuffer(GLenum draw_buffer) const; | 175 GLenum GetDrawBuffer(GLenum draw_buffer) const; |
175 | 176 |
176 void SetDrawBuffers(GLsizei n, const GLenum* bufs); | 177 void SetDrawBuffers(GLsizei n, const GLenum* bufs); |
177 | 178 |
178 // If a color buffer is attached to GL_COLOR_ATTACHMENTi, enable that | 179 // If a color buffer is attached to GL_COLOR_ATTACHMENTi, enable that |
179 // draw buffer for glClear(). | 180 // draw buffer for glClear(). |
180 // Return true if the DrawBuffers() is actually called. | 181 // Return true if the DrawBuffers() is actually called. |
181 bool PrepareDrawBuffersForClear() const; | 182 bool PrepareDrawBuffersForClearingUninitializedAttachments() const; |
182 | 183 |
183 // Restore draw buffers states that have been changed in | 184 // Restore |adjusted_draw_buffers_|. |
184 // PrepareDrawBuffersForClear(). | 185 void RestoreDrawBuffers() const; |
185 void RestoreDrawBuffersAfterClear() const; | 186 |
| 187 // Checks if a draw buffer's format and its corresponding fragment shader |
| 188 // output's type are compatible, i.e., a signed integer typed variable is |
| 189 // incompatible with a float or unsigned integer buffer. |
| 190 // Return false if incompaticle. |
| 191 // Otherwise, filter out the draw buffers that are not written to but are not |
| 192 // NONE through DrawBuffers, to be on the safe side. Return true. |
| 193 // This is applied before a draw call. |
| 194 bool ValidateAndAdjustDrawBuffers(uint32_t fragment_output_type_mask, |
| 195 uint32_t fragment_output_written_mask); |
| 196 |
| 197 bool ContainsActiveIntegerAttachments() const; |
186 | 198 |
187 // Return true if any draw buffers has an alpha channel. | 199 // Return true if any draw buffers has an alpha channel. |
188 bool HasAlphaMRT() const; | 200 bool HasAlphaMRT() const; |
189 | 201 |
190 // Return false if any two active color attachments have different internal | 202 // Return false if any two active color attachments have different internal |
191 // formats. | 203 // formats. |
192 bool HasSameInternalFormatsMRT() const; | 204 bool HasSameInternalFormatsMRT() const; |
193 | 205 |
194 void set_read_buffer(GLenum read_buffer) { | 206 void set_read_buffer(GLenum read_buffer) { |
195 read_buffer_ = read_buffer; | 207 read_buffer_ = read_buffer; |
196 } | 208 } |
197 | 209 |
198 GLenum read_buffer() const { | 210 GLenum read_buffer() const { |
199 return read_buffer_; | 211 return read_buffer_; |
200 } | 212 } |
201 | 213 |
| 214 // See member declaration for details. |
| 215 // The data are only valid if fbo is complete. |
| 216 uint32_t draw_buffer_type_mask() const { |
| 217 return draw_buffer_type_mask_; |
| 218 } |
| 219 uint32_t draw_buffer_bound_mask() const { |
| 220 return draw_buffer_bound_mask_; |
| 221 } |
| 222 |
202 private: | 223 private: |
203 friend class FramebufferManager; | 224 friend class FramebufferManager; |
204 friend class base::RefCounted<Framebuffer>; | 225 friend class base::RefCounted<Framebuffer>; |
205 | 226 |
206 ~Framebuffer(); | 227 ~Framebuffer(); |
207 | 228 |
208 void MarkAsDeleted(); | 229 void MarkAsDeleted(); |
209 | 230 |
210 void MarkAttachmentsAsCleared( | 231 void MarkAttachmentsAsCleared( |
211 RenderbufferManager* renderbuffer_manager, | 232 RenderbufferManager* renderbuffer_manager, |
212 TextureManager* texture_manager, | 233 TextureManager* texture_manager, |
213 bool cleared); | 234 bool cleared); |
214 | 235 |
215 void MarkAsComplete(unsigned state_id) { | 236 void MarkAsComplete(unsigned state_id) { |
| 237 UpdateDrawBufferMasks(); |
216 framebuffer_complete_state_count_id_ = state_id; | 238 framebuffer_complete_state_count_id_ = state_id; |
217 } | 239 } |
218 | 240 |
219 unsigned framebuffer_complete_state_count_id() const { | 241 unsigned framebuffer_complete_state_count_id() const { |
220 return framebuffer_complete_state_count_id_; | 242 return framebuffer_complete_state_count_id_; |
221 } | 243 } |
222 | 244 |
| 245 // Cache color attachments' base type mask (FLOAT, INT, UINT) and bound mask. |
| 246 // If an attachment point has no image, it's set as UNDEFINED_TYPE. |
| 247 // This call is only valid on a complete fbo. |
| 248 void UpdateDrawBufferMasks(); |
| 249 |
223 // The managers that owns this. | 250 // The managers that owns this. |
224 FramebufferManager* manager_; | 251 FramebufferManager* manager_; |
225 | 252 |
226 bool deleted_; | 253 bool deleted_; |
227 | 254 |
228 // Service side framebuffer id. | 255 // Service side framebuffer id. |
229 GLuint service_id_; | 256 GLuint service_id_; |
230 | 257 |
231 // Whether this framebuffer has ever been bound. | 258 // Whether this framebuffer has ever been bound. |
232 bool has_been_bound_; | 259 bool has_been_bound_; |
233 | 260 |
234 // state count when this framebuffer was last checked for completeness. | 261 // state count when this framebuffer was last checked for completeness. |
235 unsigned framebuffer_complete_state_count_id_; | 262 unsigned framebuffer_complete_state_count_id_; |
236 | 263 |
237 // A map of attachments. | 264 // A map of attachments. |
238 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; | 265 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; |
239 AttachmentMap attachments_; | 266 AttachmentMap attachments_; |
240 | 267 |
| 268 // User's draw buffers setting through DrawBuffers() call. |
241 std::unique_ptr<GLenum[]> draw_buffers_; | 269 std::unique_ptr<GLenum[]> draw_buffers_; |
242 | 270 |
| 271 // If a draw buffer does not have an image, or it has no corresponding |
| 272 // fragment shader output variable, it might be filtered out as NONE. |
| 273 // Note that the actually draw buffers setting sent to the driver is always |
| 274 // consistent with |adjusted_draw_buffers_|, not |draw_buffers_|. |
| 275 std::unique_ptr<GLenum[]> adjusted_draw_buffers_; |
| 276 |
| 277 // Draw buffer base types: FLOAT, INT, or UINT. |
| 278 // We have up to 16 draw buffers, each is encoded into 2 bits, total 32 bits: |
| 279 // the lowest 2 bits for draw buffer 0, the highest 2 bits for draw buffer 15. |
| 280 uint32_t draw_buffer_type_mask_; |
| 281 // Same layout as above, 2 bits per draw buffer, 0x03 if a draw buffer has a |
| 282 // bound image, 0x00 if not. |
| 283 uint32_t draw_buffer_bound_mask_; |
| 284 // This is the mask for the actual draw buffers sent to driver. |
| 285 uint32_t adjusted_draw_buffer_bound_mask_; |
| 286 |
243 GLenum read_buffer_; | 287 GLenum read_buffer_; |
244 | 288 |
245 DISALLOW_COPY_AND_ASSIGN(Framebuffer); | 289 DISALLOW_COPY_AND_ASSIGN(Framebuffer); |
246 }; | 290 }; |
247 | 291 |
248 struct DecoderFramebufferState { | 292 struct DecoderFramebufferState { |
249 DecoderFramebufferState(); | 293 DecoderFramebufferState(); |
250 ~DecoderFramebufferState(); | 294 ~DecoderFramebufferState(); |
251 | 295 |
252 // State saved for clearing so we can clear render buffers and then | 296 // State saved for clearing so we can clear render buffers and then |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 377 |
334 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; | 378 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; |
335 | 379 |
336 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); | 380 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
337 }; | 381 }; |
338 | 382 |
339 } // namespace gles2 | 383 } // namespace gles2 |
340 } // namespace gpu | 384 } // namespace gpu |
341 | 385 |
342 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 386 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
OLD | NEW |