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 // If it's for Clear(), then |fragment_output_base_types| is nullptr. |
| 191 // Return false if incompaticle. |
| 192 // Otherwise, filter out the draw buffers that are not written to but are not |
| 193 // NONE through DrawBuffers, to be on the safe side. Return true. |
| 194 bool ValidateAndAdjustDrawBuffers( |
| 195 const ShaderVariableBaseType* fragment_output_base_types); |
186 | 196 |
187 // Return true if any draw buffers has an alpha channel. | 197 // Return true if any draw buffers has an alpha channel. |
188 bool HasAlphaMRT() const; | 198 bool HasAlphaMRT() const; |
189 | 199 |
190 // Return false if any two active color attachments have different internal | 200 // Return false if any two active color attachments have different internal |
191 // formats. | 201 // formats. |
192 bool HasSameInternalFormatsMRT() const; | 202 bool HasSameInternalFormatsMRT() const; |
193 | 203 |
194 void set_read_buffer(GLenum read_buffer) { | 204 void set_read_buffer(GLenum read_buffer) { |
195 read_buffer_ = read_buffer; | 205 read_buffer_ = read_buffer; |
196 } | 206 } |
197 | 207 |
198 GLenum read_buffer() const { | 208 GLenum read_buffer() const { |
199 return read_buffer_; | 209 return read_buffer_; |
200 } | 210 } |
201 | 211 |
| 212 const ShaderVariableBaseType* GetColorAttachmentBaseTypes() const { |
| 213 return color_attachment_base_types_.get(); |
| 214 } |
| 215 |
202 private: | 216 private: |
203 friend class FramebufferManager; | 217 friend class FramebufferManager; |
204 friend class base::RefCounted<Framebuffer>; | 218 friend class base::RefCounted<Framebuffer>; |
205 | 219 |
206 ~Framebuffer(); | 220 ~Framebuffer(); |
207 | 221 |
208 void MarkAsDeleted(); | 222 void MarkAsDeleted(); |
209 | 223 |
210 void MarkAttachmentsAsCleared( | 224 void MarkAttachmentsAsCleared( |
211 RenderbufferManager* renderbuffer_manager, | 225 RenderbufferManager* renderbuffer_manager, |
212 TextureManager* texture_manager, | 226 TextureManager* texture_manager, |
213 bool cleared); | 227 bool cleared); |
214 | 228 |
215 void MarkAsComplete(unsigned state_id) { | 229 void MarkAsComplete(unsigned state_id) { |
| 230 UpdateColorAttachmentBaseTypes(); |
216 framebuffer_complete_state_count_id_ = state_id; | 231 framebuffer_complete_state_count_id_ = state_id; |
217 } | 232 } |
218 | 233 |
219 unsigned framebuffer_complete_state_count_id() const { | 234 unsigned framebuffer_complete_state_count_id() const { |
220 return framebuffer_complete_state_count_id_; | 235 return framebuffer_complete_state_count_id_; |
221 } | 236 } |
222 | 237 |
| 238 // Cache color attachments' base types (FLOAT, INT, UINT) for optimization |
| 239 // purpose. If an attachment point has no image, it's set as UNDEFINED_TYPE. |
| 240 // This call is only valid on a complete fbo. |
| 241 void UpdateColorAttachmentBaseTypes(); |
| 242 |
| 243 void ResetColorAttachmentBaseTypes(); |
| 244 |
223 // The managers that owns this. | 245 // The managers that owns this. |
224 FramebufferManager* manager_; | 246 FramebufferManager* manager_; |
225 | 247 |
226 bool deleted_; | 248 bool deleted_; |
227 | 249 |
228 // Service side framebuffer id. | 250 // Service side framebuffer id. |
229 GLuint service_id_; | 251 GLuint service_id_; |
230 | 252 |
231 // Whether this framebuffer has ever been bound. | 253 // Whether this framebuffer has ever been bound. |
232 bool has_been_bound_; | 254 bool has_been_bound_; |
233 | 255 |
234 // state count when this framebuffer was last checked for completeness. | 256 // state count when this framebuffer was last checked for completeness. |
235 unsigned framebuffer_complete_state_count_id_; | 257 unsigned framebuffer_complete_state_count_id_; |
236 | 258 |
237 // A map of attachments. | 259 // A map of attachments. |
238 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; | 260 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; |
239 AttachmentMap attachments_; | 261 AttachmentMap attachments_; |
240 | 262 |
| 263 // User's draw buffers setting through DrawBuffers() call. |
241 std::unique_ptr<GLenum[]> draw_buffers_; | 264 std::unique_ptr<GLenum[]> draw_buffers_; |
242 | 265 |
| 266 // If a draw buffer does not have an image, or it has no corresponding |
| 267 // fragment shader output variable, it might be filtered out as NONE. |
| 268 // Note that the actually draw buffers setting sent to the driver is always |
| 269 // consistent with |adjusted_draw_buffers_|, not |draw_buffers_|. |
| 270 std::unique_ptr<GLenum[]> adjusted_draw_buffers_; |
| 271 |
| 272 std::unique_ptr<ShaderVariableBaseType[]> color_attachment_base_types_; |
| 273 |
243 GLenum read_buffer_; | 274 GLenum read_buffer_; |
244 | 275 |
245 DISALLOW_COPY_AND_ASSIGN(Framebuffer); | 276 DISALLOW_COPY_AND_ASSIGN(Framebuffer); |
246 }; | 277 }; |
247 | 278 |
248 struct DecoderFramebufferState { | 279 struct DecoderFramebufferState { |
249 DecoderFramebufferState(); | 280 DecoderFramebufferState(); |
250 ~DecoderFramebufferState(); | 281 ~DecoderFramebufferState(); |
251 | 282 |
252 // State saved for clearing so we can clear render buffers and then | 283 // 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 | 364 |
334 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; | 365 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; |
335 | 366 |
336 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); | 367 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
337 }; | 368 }; |
338 | 369 |
339 } // namespace gles2 | 370 } // namespace gles2 |
340 } // namespace gpu | 371 } // namespace gpu |
341 | 372 |
342 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 373 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
OLD | NEW |