Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / command_buffer / client / buffer_tracker.cc
blob63adba713bba6c3f8ce63dff804f320f2901717c
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 <utility>
8 #include "gpu/command_buffer/client/mapped_memory.h"
10 namespace gpu {
11 namespace gles2 {
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) {
25 DCHECK_NE(0u, id);
26 DCHECK_LE(0, size);
27 int32 shm_id = -1;
28 uint32 shm_offset = 0;
29 void* address = NULL;
30 if (size)
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);
37 return buffer;
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;
49 buffers_.erase(it);
50 if (buffer->address_)
51 mapped_memory_->Free(buffer->address_);
52 delete buffer;
56 void BufferTracker::FreePendingToken(Buffer* buffer, int32 token) {
57 if (buffer->address_)
58 mapped_memory_->FreePendingToken(buffer->address_, token);
59 buffer->size_ = 0;
60 buffer->shm_id_ = 0;
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) {
68 buffer->size_ = 0;
69 buffer->shm_id_ = 0;
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) {
77 if (buffer->address_)
78 mapped_memory_->Free(buffer->address_);
80 buffer->size_ = 0;
81 buffer->shm_id_ = 0;
82 buffer->shm_offset_ = 0;
83 buffer->address_ = NULL;
84 buffer->last_usage_token_ = 0;
85 buffer->last_async_upload_token_ = 0;
88 } // namespace gles2
89 } // namespace gpu