Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / gpu / command_buffer / client / share_group.h
blobc150004319042c8489ec4c550066815baf250876
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_
8 #include <GLES2/gl2.h>
9 #include "base/memory/scoped_ptr.h"
10 #include "gles2_impl_export.h"
11 #include "gpu/command_buffer/client/ref_counted.h"
12 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 namespace gpu {
15 namespace gles2 {
17 class GLES2Implementation;
18 class GLES2ImplementationTest;
19 class ProgramInfoManager;
21 typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids);
22 typedef void (GLES2Implementation::*BindFn)(GLenum target, GLuint id);
23 typedef void (GLES2Implementation::*BindIndexedFn)( \
24 GLenum target, GLuint index, GLuint id);
25 typedef void (GLES2Implementation::*BindIndexedRangeFn)( \
26 GLenum target, GLuint index, GLuint id, GLintptr offset, GLsizeiptr size);
28 class ShareGroupContextData {
29 public:
30 struct IdHandlerData {
31 IdHandlerData();
32 ~IdHandlerData();
34 std::vector<GLuint> freed_ids_;
35 uint32 flush_generation_;
38 IdHandlerData* id_handler_data(int namespace_id) {
39 return &id_handler_data_[namespace_id];
42 private:
43 IdHandlerData id_handler_data_[id_namespaces::kNumIdNamespaces];
46 // Base class for IdHandlers
47 class IdHandlerInterface {
48 public:
49 IdHandlerInterface() { }
50 virtual ~IdHandlerInterface() { }
52 // Makes some ids at or above id_offset.
53 virtual void MakeIds(
54 GLES2Implementation* gl_impl,
55 GLuint id_offset, GLsizei n, GLuint* ids) = 0;
57 // Frees some ids.
58 virtual bool FreeIds(
59 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids,
60 DeleteFn delete_fn) = 0;
62 // Marks an id as used for glBind functions. id = 0 does nothing.
63 virtual bool MarkAsUsedForBind(
64 GLES2Implementation* gl_impl,
65 GLenum target,
66 GLuint id,
67 BindFn bind_fn) = 0;
68 // This is for glBindBufferBase.
69 virtual bool MarkAsUsedForBind(
70 GLES2Implementation* gl_impl,
71 GLenum target,
72 GLuint index,
73 GLuint id,
74 BindIndexedFn bind_fn) = 0;
75 // This is for glBindBufferRange.
76 virtual bool MarkAsUsedForBind(
77 GLES2Implementation* gl_impl,
78 GLenum target,
79 GLuint index,
80 GLuint id,
81 GLintptr offset,
82 GLsizeiptr size,
83 BindIndexedRangeFn bind_fn) = 0;
85 // Called when a context in the share group is destructed.
86 virtual void FreeContext(GLES2Implementation* gl_impl) = 0;
89 // ShareGroup manages shared resources for contexts that are sharing resources.
90 class GLES2_IMPL_EXPORT ShareGroup
91 : public gpu::RefCountedThreadSafe<ShareGroup> {
92 public:
93 ShareGroup(bool bind_generates_resource);
95 bool bind_generates_resource() const {
96 return bind_generates_resource_;
99 IdHandlerInterface* GetIdHandler(int namespace_id) const {
100 return id_handlers_[namespace_id].get();
103 ProgramInfoManager* program_info_manager() {
104 return program_info_manager_.get();
107 void FreeContext(GLES2Implementation* gl_impl) {
108 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
109 id_handlers_[i]->FreeContext(gl_impl);
113 private:
114 friend class gpu::RefCountedThreadSafe<ShareGroup>;
115 friend class gpu::gles2::GLES2ImplementationTest;
116 ~ShareGroup();
118 // Install a new program info manager. Used for testing only;
119 void set_program_info_manager(ProgramInfoManager* manager);
121 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces];
122 scoped_ptr<ProgramInfoManager> program_info_manager_;
124 bool bind_generates_resource_;
126 DISALLOW_COPY_AND_ASSIGN(ShareGroup);
129 } // namespace gles2
130 } // namespace gpu
132 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_