Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / gpu / command_buffer / client / share_group.h
blobc66704b7fd6736679f20be67b574e7be8d589b72
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);
23 class ShareGroupContextData {
24 public:
25 struct IdHandlerData {
26 IdHandlerData();
27 ~IdHandlerData();
29 std::vector<GLuint> freed_ids_;
30 uint32 flush_generation_;
33 IdHandlerData* id_handler_data(int namespace_id) {
34 return &id_handler_data_[namespace_id];
37 private:
38 IdHandlerData id_handler_data_[id_namespaces::kNumIdNamespaces];
41 // Base class for IdHandlers
42 class IdHandlerInterface {
43 public:
44 IdHandlerInterface() { }
45 virtual ~IdHandlerInterface() { }
47 // Makes some ids at or above id_offset.
48 virtual void MakeIds(
49 GLES2Implementation* gl_impl,
50 GLuint id_offset, GLsizei n, GLuint* ids) = 0;
52 // Frees some ids.
53 virtual bool FreeIds(
54 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids,
55 DeleteFn delete_fn) = 0;
57 // Marks an id as used for glBind functions. id = 0 does nothing.
58 virtual bool MarkAsUsedForBind(GLuint id) = 0;
60 // Called when a context in the share group is destructed.
61 virtual void FreeContext(GLES2Implementation* gl_impl) = 0;
64 // ShareGroup manages shared resources for contexts that are sharing resources.
65 class GLES2_IMPL_EXPORT ShareGroup
66 : public gpu::RefCountedThreadSafe<ShareGroup> {
67 public:
68 ShareGroup(bool bind_generates_resource);
70 bool bind_generates_resource() const {
71 return bind_generates_resource_;
74 IdHandlerInterface* GetIdHandler(int namespace_id) const {
75 return id_handlers_[namespace_id].get();
78 ProgramInfoManager* program_info_manager() {
79 return program_info_manager_.get();
82 void FreeContext(GLES2Implementation* gl_impl) {
83 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
84 id_handlers_[i]->FreeContext(gl_impl);
88 private:
89 friend class gpu::RefCountedThreadSafe<ShareGroup>;
90 friend class gpu::gles2::GLES2ImplementationTest;
91 ~ShareGroup();
93 // Install a new program info manager. Used for testing only;
94 void set_program_info_manager(ProgramInfoManager* manager);
96 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces];
97 scoped_ptr<ProgramInfoManager> program_info_manager_;
99 bool bind_generates_resource_;
101 DISALLOW_COPY_AND_ASSIGN(ShareGroup);
104 } // namespace gles2
105 } // namespace gpu
107 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_