OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_INDEXED_BUFFER_BINDING_HOST_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_INDEXED_BUFFER_BINDING_HOST_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "gpu/command_buffer/service/gl_utils.h" |
| 12 #include "gpu/gpu_export.h" |
| 13 |
| 14 namespace gfx { |
| 15 struct GLVersionInfo; |
| 16 }; |
| 17 |
| 18 namespace gpu { |
| 19 namespace gles2 { |
| 20 |
| 21 class Buffer; |
| 22 |
| 23 // This is a base class for indexed buffer bindings tracking. |
| 24 // TransformFeedback and Program should inherit from this base class, |
| 25 // for tracking indexed TRANSFORM_FEEDBACK_BUFFER / UNIFORM_BUFFER bindings. |
| 26 class GPU_EXPORT IndexedBufferBindingHost : |
| 27 public base::RefCounted<IndexedBufferBindingHost> { |
| 28 public: |
| 29 IndexedBufferBindingHost(uint32_t max_bindings); |
| 30 |
| 31 // The following two functions do state update and call the underlying GL |
| 32 // function. All validations have been done already and the GL function is |
| 33 // guaranteed to succeed. |
| 34 void DoBindBufferBase(GLenum target, GLuint index, Buffer* buffer); |
| 35 void DoBindBufferRange( |
| 36 const gfx::GLVersionInfo& gl_version_info, GLenum target, GLuint index, |
| 37 Buffer* buffer, GLintptr offset, GLsizeiptr size); |
| 38 |
| 39 // This is called on the active host when glBufferData is called and buffer |
| 40 // size might change. |
| 41 void OnBufferData( |
| 42 const gfx::GLVersionInfo& gl_version_info, GLenum target, Buffer* buffer); |
| 43 |
| 44 // This is called when the host become active. |
| 45 void OnBindHost( |
| 46 const gfx::GLVersionInfo& gl_version_info, GLenum target); |
| 47 |
| 48 void RemoveBoundBuffer(Buffer* buffer); |
| 49 |
| 50 Buffer* GetBufferBinding(GLuint index) const; |
| 51 GLsizeiptr GetBufferSize(GLuint index) const; |
| 52 GLintptr GetBufferStart(GLuint index) const; |
| 53 |
| 54 protected: |
| 55 friend class base::RefCounted<IndexedBufferBindingHost>; |
| 56 |
| 57 virtual ~IndexedBufferBindingHost(); |
| 58 |
| 59 private: |
| 60 enum IndexedBufferBindingType { |
| 61 kBindBufferBase, |
| 62 kBindBufferRange, |
| 63 kBindBufferNone |
| 64 }; |
| 65 |
| 66 struct IndexedBufferBinding { |
| 67 IndexedBufferBindingType type; |
| 68 scoped_refptr<Buffer> buffer; |
| 69 |
| 70 // The following fields are only used if |type| is kBindBufferRange. |
| 71 GLintptr offset; |
| 72 GLsizeiptr size; |
| 73 // The full buffer size at the last successful glBindBufferRange call. |
| 74 GLsizeiptr effective_full_buffer_size; |
| 75 |
| 76 IndexedBufferBinding(); |
| 77 IndexedBufferBinding(const IndexedBufferBinding& other); |
| 78 ~IndexedBufferBinding(); |
| 79 |
| 80 void SetBindBufferBase(Buffer* _buffer); |
| 81 void SetBindBufferRange( |
| 82 Buffer* _buffer, GLintptr _offset, GLsizeiptr _size); |
| 83 void Reset(); |
| 84 }; |
| 85 |
| 86 // This is called on Desktop GL lower than 4.2, where the range |
| 87 // (offset + size) can't go beyond the buffer's size. |
| 88 static void DoAdjustedBindBufferRange( |
| 89 GLenum target, GLuint index, GLuint service_id, GLintptr offset, |
| 90 GLsizeiptr size, GLsizeiptr full_buffer_size); |
| 91 |
| 92 std::vector<IndexedBufferBinding> buffer_bindings_; |
| 93 }; |
| 94 |
| 95 } // namespace gles2 |
| 96 } // namespace gpu |
| 97 |
| 98 #endif // GPU_COMMAND_BUFFER_SERVICE_INDEXED_BUFFER_BINDING_HOST_H_ |
OLD | NEW |