OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "../client/buffer_tracker.h" |
| 6 |
| 7 #include "../client/atomicops.h" |
| 8 #include "../client/cmd_buffer_helper.h" |
| 9 #include "../client/mapped_memory.h" |
| 10 |
| 11 namespace gpu { |
| 12 namespace gles2 { |
| 13 |
| 14 BufferTracker::BufferTracker(MappedMemoryManager* manager) |
| 15 : mapped_memory_(manager) { |
| 16 } |
| 17 |
| 18 BufferTracker::~BufferTracker() { |
| 19 while (!buffers_.empty()) { |
| 20 RemoveBuffer(buffers_.begin()->first); |
| 21 } |
| 22 } |
| 23 |
| 24 BufferTracker::Buffer* BufferTracker::CreateBuffer( |
| 25 GLuint id, GLsizeiptr size) { |
| 26 GPU_DCHECK_NE(0u, id); |
| 27 GPU_DCHECK_LT(0, size); |
| 28 int32 shm_id; |
| 29 uint32 shm_offset; |
| 30 void* address = mapped_memory_->Alloc(size, &shm_id, &shm_offset); |
| 31 if (!address) { |
| 32 return NULL; |
| 33 } |
| 34 |
| 35 Buffer* buffer = new Buffer(id, size, shm_id, shm_offset, address); |
| 36 std::pair<BufferMap::iterator, bool> result = |
| 37 buffers_.insert(std::make_pair(id, buffer)); |
| 38 GPU_DCHECK(result.second); |
| 39 return buffer; |
| 40 } |
| 41 |
| 42 BufferTracker::Buffer* BufferTracker::GetBuffer(GLuint client_id) { |
| 43 BufferMap::iterator it = buffers_.find(client_id); |
| 44 return it != buffers_.end() ? it->second : NULL; |
| 45 } |
| 46 |
| 47 void BufferTracker::RemoveBuffer(GLuint client_id) { |
| 48 BufferMap::iterator it = buffers_.find(client_id); |
| 49 if (it != buffers_.end()) { |
| 50 Buffer* buffer = it->second; |
| 51 buffers_.erase(it); |
| 52 if (buffer->address_) |
| 53 mapped_memory_->Free(buffer->address_); |
| 54 delete buffer; |
| 55 } |
| 56 } |
| 57 |
| 58 void BufferTracker::FreePendingToken(Buffer* buffer, int32 token) { |
| 59 GPU_DCHECK(buffer->address_); |
| 60 mapped_memory_->FreePendingToken(buffer->address_, token); |
| 61 buffer->size_ = 0; |
| 62 buffer->shm_id_ = 0; |
| 63 buffer->shm_offset_ = 0; |
| 64 buffer->address_ = NULL; |
| 65 } |
| 66 |
| 67 |
| 68 } // namespace gles2 |
| 69 } // namespace gpu |
OLD | NEW |