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/client/buffer_tracker.h"
7 #include "gpu/command_buffer/client/atomicops.h"
8 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
9 #include "gpu/command_buffer/client/mapped_memory.h"
14 BufferTracker::BufferTracker(MappedMemoryManager
* manager
)
15 : mapped_memory_(manager
) {
18 BufferTracker::~BufferTracker() {
19 while (!buffers_
.empty()) {
20 RemoveBuffer(buffers_
.begin()->first
);
24 BufferTracker::Buffer
* BufferTracker::CreateBuffer(
25 GLuint id
, GLsizeiptr size
) {
26 GPU_DCHECK_NE(0u, id
);
27 GPU_DCHECK_LE(0, size
);
29 uint32 shm_offset
= 0;
32 address
= mapped_memory_
->Alloc(size
, &shm_id
, &shm_offset
);
34 Buffer
* buffer
= new Buffer(id
, size
, shm_id
, shm_offset
, address
);
35 std::pair
<BufferMap::iterator
, bool> result
=
36 buffers_
.insert(std::make_pair(id
, buffer
));
37 GPU_DCHECK(result
.second
);
41 BufferTracker::Buffer
* BufferTracker::GetBuffer(GLuint client_id
) {
42 BufferMap::iterator it
= buffers_
.find(client_id
);
43 return it
!= buffers_
.end() ? it
->second
: NULL
;
46 void BufferTracker::RemoveBuffer(GLuint client_id
) {
47 BufferMap::iterator it
= buffers_
.find(client_id
);
48 if (it
!= buffers_
.end()) {
49 Buffer
* buffer
= it
->second
;
52 mapped_memory_
->Free(buffer
->address_
);
57 void BufferTracker::FreePendingToken(Buffer
* buffer
, int32 token
) {
59 mapped_memory_
->FreePendingToken(buffer
->address_
, token
);
62 buffer
->shm_offset_
= 0;
63 buffer
->address_
= NULL
;