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"
8 #include "gpu/command_buffer/client/mapped_memory.h"
13 BufferTracker::BufferTracker(MappedMemoryManager
* manager
)
14 : mapped_memory_(manager
) {
17 BufferTracker::~BufferTracker() {
18 while (!buffers_
.empty()) {
19 RemoveBuffer(buffers_
.begin()->first
);
23 BufferTracker::Buffer
* BufferTracker::CreateBuffer(
24 GLuint id
, GLsizeiptr size
) {
28 uint32 shm_offset
= 0;
31 address
= mapped_memory_
->Alloc(size
, &shm_id
, &shm_offset
);
33 Buffer
* buffer
= new Buffer(id
, size
, shm_id
, shm_offset
, address
);
34 std::pair
<BufferMap::iterator
, bool> result
=
35 buffers_
.insert(std::make_pair(id
, buffer
));
36 DCHECK(result
.second
);
40 BufferTracker::Buffer
* BufferTracker::GetBuffer(GLuint client_id
) {
41 BufferMap::iterator it
= buffers_
.find(client_id
);
42 return it
!= buffers_
.end() ? it
->second
: NULL
;
45 void BufferTracker::RemoveBuffer(GLuint client_id
) {
46 BufferMap::iterator it
= buffers_
.find(client_id
);
47 if (it
!= buffers_
.end()) {
48 Buffer
* buffer
= it
->second
;
51 mapped_memory_
->Free(buffer
->address_
);
56 void BufferTracker::FreePendingToken(Buffer
* buffer
, int32 token
) {
58 mapped_memory_
->FreePendingToken(buffer
->address_
, token
);
61 buffer
->shm_offset_
= 0;
62 buffer
->address_
= NULL
;
63 buffer
->last_usage_token_
= 0;
64 buffer
->last_async_upload_token_
= 0;
67 void BufferTracker::Unmanage(Buffer
* buffer
) {
70 buffer
->shm_offset_
= 0;
71 buffer
->address_
= NULL
;
72 buffer
->last_usage_token_
= 0;
73 buffer
->last_async_upload_token_
= 0;
76 void BufferTracker::Free(Buffer
* buffer
) {
78 mapped_memory_
->Free(buffer
->address_
);
82 buffer
->shm_offset_
= 0;
83 buffer
->address_
= NULL
;
84 buffer
->last_usage_token_
= 0;
85 buffer
->last_async_upload_token_
= 0;