cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / gpu / command_buffer / client / buffer_tracker.cc
blobf5ead5af08c6c98bee2a9c9e664ed046ce2f0a8b
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"
11 namespace gpu {
12 namespace gles2 {
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);
28 int32 shm_id = -1;
29 uint32 shm_offset = 0;
30 void* address = NULL;
31 if (size)
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);
38 return buffer;
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;
50 buffers_.erase(it);
51 if (buffer->address_)
52 mapped_memory_->Free(buffer->address_);
53 delete buffer;
57 void BufferTracker::FreePendingToken(Buffer* buffer, int32 token) {
58 if (buffer->address_)
59 mapped_memory_->FreePendingToken(buffer->address_, token);
60 buffer->size_ = 0;
61 buffer->shm_id_ = 0;
62 buffer->shm_offset_ = 0;
63 buffer->address_ = NULL;
67 } // namespace gles2
68 } // namespace gpu