Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: gpu/command_buffer/client/share_group.h

Issue 162023002: Reduce internal Flush() in GL resource glGen/Delete APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test_contexts_[2] -> test_contexts_[kNumTestContexts] Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_CLIENT_SHARE_GROUP_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_
7 7
8 #include <GLES2/gl2.h> 8 #include <GLES2/gl2.h>
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "gles2_impl_export.h" 10 #include "gles2_impl_export.h"
11 #include "gpu/command_buffer/client/ref_counted.h" 11 #include "gpu/command_buffer/client/ref_counted.h"
12 #include "gpu/command_buffer/common/gles2_cmd_format.h" 12 #include "gpu/command_buffer/common/gles2_cmd_format.h"
13 13
14 namespace gpu { 14 namespace gpu {
15 namespace gles2 { 15 namespace gles2 {
16 16
17 class GLES2Implementation; 17 class GLES2Implementation;
18 class GLES2ImplementationTest; 18 class GLES2ImplementationTest;
19 class ProgramInfoManager; 19 class ProgramInfoManager;
20 20
21 typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids); 21 typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids);
22 22
23 class ShareGroupContextData {
24 public:
25 struct IdHandlerData {
26 IdHandlerData();
27
28 std::vector<GLuint> freed_ids_;
29 uint32 flush_generation_;
30 };
31
32 IdHandlerData* id_handler_data(int namespace_id) {
33 return &id_handler_data_[namespace_id];
34 }
35
36 private:
37 IdHandlerData id_handler_data_[id_namespaces::kNumIdNamespaces];
38 };
39
23 // Base class for IdHandlers 40 // Base class for IdHandlers
24 class IdHandlerInterface { 41 class IdHandlerInterface {
25 public: 42 public:
26 IdHandlerInterface() { } 43 IdHandlerInterface() { }
27 virtual ~IdHandlerInterface() { } 44 virtual ~IdHandlerInterface() { }
28 45
29 // Makes some ids at or above id_offset. 46 // Makes some ids at or above id_offset.
30 virtual void MakeIds( 47 virtual void MakeIds(
31 GLES2Implementation* gl_impl, 48 GLES2Implementation* gl_impl,
32 GLuint id_offset, GLsizei n, GLuint* ids) = 0; 49 GLuint id_offset, GLsizei n, GLuint* ids) = 0;
33 50
34 // Frees some ids. 51 // Frees some ids.
35 virtual bool FreeIds( 52 virtual bool FreeIds(
36 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids, 53 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids,
37 DeleteFn delete_fn) = 0; 54 DeleteFn delete_fn) = 0;
38 55
39 // Marks an id as used for glBind functions. id = 0 does nothing. 56 // Marks an id as used for glBind functions. id = 0 does nothing.
40 virtual bool MarkAsUsedForBind(GLuint id) = 0; 57 virtual bool MarkAsUsedForBind(GLES2Implementation* gl_impl, GLuint id) = 0;
58
59 // Called when a context in the share group is destructed.
60 virtual void FreeContext(GLES2Implementation* gl_impl) = 0;
41 }; 61 };
42 62
43 // ShareGroup manages shared resources for contexts that are sharing resources. 63 // ShareGroup manages shared resources for contexts that are sharing resources.
44 class GLES2_IMPL_EXPORT ShareGroup 64 class GLES2_IMPL_EXPORT ShareGroup
45 : public gpu::RefCountedThreadSafe<ShareGroup> { 65 : public gpu::RefCountedThreadSafe<ShareGroup> {
46 public: 66 public:
47 ShareGroup(bool bind_generates_resource); 67 ShareGroup(bool bind_generates_resource);
48 68
49 bool bind_generates_resource() const { 69 bool bind_generates_resource() const {
50 return bind_generates_resource_; 70 return bind_generates_resource_;
51 } 71 }
52 72
53 bool Initialize(); 73 bool Initialize();
54 74
55 IdHandlerInterface* GetIdHandler(int namespace_id) const { 75 IdHandlerInterface* GetIdHandler(int namespace_id) const {
56 return id_handlers_[namespace_id].get(); 76 return id_handlers_[namespace_id].get();
57 } 77 }
58 78
59 ProgramInfoManager* program_info_manager() { 79 ProgramInfoManager* program_info_manager() {
60 return program_info_manager_.get(); 80 return program_info_manager_.get();
61 } 81 }
62 82
83 void FreeContext(GLES2Implementation* gl_impl) {
84 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
85 id_handlers_[i]->FreeContext(gl_impl);
86 }
87 }
88
63 private: 89 private:
64 friend class gpu::RefCountedThreadSafe<ShareGroup>; 90 friend class gpu::RefCountedThreadSafe<ShareGroup>;
65 friend class gpu::gles2::GLES2ImplementationTest; 91 friend class gpu::gles2::GLES2ImplementationTest;
66 ~ShareGroup(); 92 ~ShareGroup();
67 93
68 // Install a new program info manager. Used for testing only; 94 // Install a new program info manager. Used for testing only;
69 void set_program_info_manager(ProgramInfoManager* manager); 95 void set_program_info_manager(ProgramInfoManager* manager);
70 96
71 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces]; 97 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces];
72 scoped_ptr<ProgramInfoManager> program_info_manager_; 98 scoped_ptr<ProgramInfoManager> program_info_manager_;
73 99
74 bool bind_generates_resource_; 100 bool bind_generates_resource_;
75 101
76 DISALLOW_COPY_AND_ASSIGN(ShareGroup); 102 DISALLOW_COPY_AND_ASSIGN(ShareGroup);
77 }; 103 };
78 104
79 } // namespace gles2 105 } // namespace gles2
80 } // namespace gpu 106 } // namespace gpu
81 107
82 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ 108 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698