OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_CLIENT_GLES2_IMPLEMENTATION_H | 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H |
6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H | 6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H |
7 | 7 |
8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
10 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 10 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
11 #include "gpu/command_buffer/client/id_allocator.h" | 11 #include "gpu/command_buffer/client/id_allocator.h" |
| 12 #include "gpu/command_buffer/client/fenced_allocator.h" |
12 | 13 |
13 namespace command_buffer { | 14 namespace command_buffer { |
14 namespace gles2 { | 15 namespace gles2 { |
15 | 16 |
16 // A class to help with shared memory. | |
17 class SharedMemoryHelper { | |
18 public: | |
19 SharedMemoryHelper(void* address, int id) | |
20 : address_(address), | |
21 id_(id) { | |
22 } | |
23 | |
24 unsigned int GetOffset(void* address) const { | |
25 return static_cast<int8*>(address) - | |
26 static_cast<int8*>(address_); | |
27 } | |
28 | |
29 void* GetAddress(unsigned int offset) const { | |
30 return static_cast<int8*>(address_) + offset; | |
31 } | |
32 | |
33 template <typename T> | |
34 T GetAddressAs(unsigned int offset) const { | |
35 return static_cast<T>(GetAddress(offset)); | |
36 } | |
37 | |
38 unsigned int GetId() const { | |
39 return id_; | |
40 } | |
41 | |
42 private: | |
43 void* address_; | |
44 int id_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(SharedMemoryHelper); | |
47 }; | |
48 | |
49 // This class emulates GLES2 over command buffers. It can be used by a client | 17 // This class emulates GLES2 over command buffers. It can be used by a client |
50 // program so that the program does not need deal with shared memory and command | 18 // program so that the program does not need deal with shared memory and command |
51 // buffer management. See gl2_lib.h. Note that there is a performance gain to | 19 // buffer management. See gl2_lib.h. Note that there is a performance gain to |
52 // be had by changing your code to use command buffers directly by using the | 20 // be had by changing your code to use command buffers directly by using the |
53 // GLES2CmdHelper but that entails changing your code to use and deal with | 21 // GLES2CmdHelper but that entails changing your code to use and deal with |
54 // shared memory and synchronization issues. | 22 // shared memory and synchronization issues. |
55 class GLES2Implementation { | 23 class GLES2Implementation { |
56 public: | 24 public: |
57 GLES2Implementation( | 25 GLES2Implementation( |
58 GLES2CmdHelper* helper, | 26 GLES2CmdHelper* helper, |
| 27 size_t transfer_buffer_size, |
59 void* transfer_buffer, | 28 void* transfer_buffer, |
60 int transfer_buffer_id); // TODO: add size. | 29 int32 transfer_buffer_id); |
61 | 30 |
62 // Include the auto-generated part of this class. We split this because | 31 // Include the auto-generated part of this class. We split this because |
63 // it means we can easily edit the non-auto generated parts right here in | 32 // it means we can easily edit the non-auto generated parts right here in |
64 // this file instead of having to edit some template or the code generator. | 33 // this file instead of having to edit some template or the code generator. |
65 #include "gpu/command_buffer/client/gles2_implementation_autogen.h" | 34 #include "gpu/command_buffer/client/gles2_implementation_autogen.h" |
66 | 35 |
67 private: | 36 private: |
68 // Makes a set of Ids for glGen___ functions. | 37 // Makes a set of Ids for glGen___ functions. |
69 void MakeIds(GLsizei n, GLuint* ids); | 38 void MakeIds(GLsizei n, GLuint* ids); |
70 | 39 |
71 // Frees a set of Ids for glDelete___ functions. | 40 // Frees a set of Ids for glDelete___ functions. |
72 void FreeIds(GLsizei n, const GLuint* ids); | 41 void FreeIds(GLsizei n, const GLuint* ids); |
73 | 42 |
| 43 // Gets the shared memory id for the result buffer. |
| 44 uint32 result_shm_id() const { |
| 45 return transfer_buffer_id_; |
| 46 } |
| 47 |
| 48 // Gets the shared memory offset for the result buffer. |
| 49 uint32 result_shm_offset() const { |
| 50 return result_shm_offset_; |
| 51 } |
| 52 |
| 53 // Gets the value of the result. |
| 54 template <typename T> |
| 55 T GetResultAs() const { |
| 56 return *static_cast<T*>(result_buffer_); |
| 57 } |
| 58 |
| 59 // Waits for all commands to execute. |
| 60 void WaitForCmd(); |
| 61 |
| 62 // The maxiumum result size from simple GL get commands. |
| 63 static const size_t kMaxSizeOfSimpleResult = 4 * sizeof(uint32); // NOLINT. |
| 64 |
74 GLES2Util util_; | 65 GLES2Util util_; |
75 GLES2CmdHelper* helper_; | 66 GLES2CmdHelper* helper_; |
76 IdAllocator id_allocator_; | 67 IdAllocator id_allocator_; |
77 SharedMemoryHelper shared_memory_; // TODO(gman): rename transfer_buffer_. | 68 FencedAllocatorWrapper transfer_buffer_; |
| 69 int transfer_buffer_id_; |
| 70 void* result_buffer_; |
| 71 uint32 result_shm_offset_; |
78 | 72 |
79 // pack alignment as last set by glPixelStorei | 73 // pack alignment as last set by glPixelStorei |
80 GLint pack_alignment_; | 74 GLint pack_alignment_; |
81 | 75 |
82 // unpack alignment as last set by glPixelStorei | 76 // unpack alignment as last set by glPixelStorei |
83 GLint unpack_alignment_; | 77 GLint unpack_alignment_; |
84 | 78 |
85 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation); | 79 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation); |
86 }; | 80 }; |
87 | 81 |
88 | 82 |
89 } // namespace gles2 | 83 } // namespace gles2 |
90 } // namespace command_buffer | 84 } // namespace command_buffer |
91 | 85 |
92 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H | 86 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H |
93 | 87 |
OLD | NEW |