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 #include "gpu/command_buffer/service/vertex_array_manager.h"
6 #include "base/debug/trace_event.h"
7 #include "base/logging.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "gpu/command_buffer/service/buffer_manager.h"
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
11 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
16 VertexArrayManager::VertexArrayManager()
17 : vertex_attrib_manager_count_(0),
21 VertexArrayManager::~VertexArrayManager() {
22 DCHECK(vertex_attrib_managers_
.empty());
23 CHECK_EQ(vertex_attrib_manager_count_
, 0u);
26 void VertexArrayManager::Destroy(bool have_context
) {
27 have_context_
= have_context
;
28 vertex_attrib_managers_
.clear();
31 scoped_refptr
<VertexAttribManager
>
32 VertexArrayManager::CreateVertexAttribManager(GLuint client_id
,
34 uint32 num_vertex_attribs
,
35 bool client_visible
) {
36 scoped_refptr
<VertexAttribManager
> vertex_attrib_manager(
37 new VertexAttribManager(this, service_id
, num_vertex_attribs
));
40 std::pair
<VertexAttribManagerMap::iterator
, bool> result
=
41 vertex_attrib_managers_
.insert(
42 std::make_pair(client_id
, vertex_attrib_manager
));
43 DCHECK(result
.second
);
46 return vertex_attrib_manager
;
49 VertexAttribManager
* VertexArrayManager::GetVertexAttribManager(
51 VertexAttribManagerMap::iterator it
= vertex_attrib_managers_
.find(client_id
);
52 return it
!= vertex_attrib_managers_
.end() ? it
->second
.get() : NULL
;
55 void VertexArrayManager::RemoveVertexAttribManager(GLuint client_id
) {
56 VertexAttribManagerMap::iterator it
= vertex_attrib_managers_
.find(client_id
);
57 if (it
!= vertex_attrib_managers_
.end()) {
58 VertexAttribManager
* vertex_attrib_manager
= it
->second
.get();
59 vertex_attrib_manager
->MarkAsDeleted();
60 vertex_attrib_managers_
.erase(it
);
64 void VertexArrayManager::StartTracking(
65 VertexAttribManager
* /* vertex_attrib_manager */) {
66 ++vertex_attrib_manager_count_
;
69 void VertexArrayManager::StopTracking(
70 VertexAttribManager
* /* vertex_attrib_manager */) {
71 --vertex_attrib_manager_count_
;
74 bool VertexArrayManager::GetClientId(
75 GLuint service_id
, GLuint
* client_id
) const {
76 // This doesn't need to be fast. It's only used during slow queries.
77 for (VertexAttribManagerMap::const_iterator it
=
78 vertex_attrib_managers_
.begin();
79 it
!= vertex_attrib_managers_
.end(); ++it
) {
80 if (it
->second
->service_id() == service_id
) {
81 *client_id
= it
->first
;