Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: cc/test/test_gpu_memory_buffer_manager.cc

Issue 793693003: Tile Compression (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/test_gles2_interface.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/test_gpu_memory_buffer_manager.h" 5 #include "cc/test/test_gpu_memory_buffer_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/gpu_memory_buffer.h" 8 #include "ui/gfx/gpu_memory_buffer.h"
9 9
10 namespace cc { 10 namespace cc {
11 namespace { 11 namespace {
12 12
13 size_t BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { 13 size_t BitsPerPixel(gfx::GpuMemoryBuffer::Format format) {
14 switch (format) { 14 switch (format) {
15 case gfx::GpuMemoryBuffer::RGBA_8888: 15 case gfx::GpuMemoryBuffer::RGBA_8888:
16 case gfx::GpuMemoryBuffer::RGBX_8888: 16 case gfx::GpuMemoryBuffer::RGBX_8888:
17 case gfx::GpuMemoryBuffer::BGRA_8888: 17 case gfx::GpuMemoryBuffer::BGRA_8888:
18 return 32;
19 case gfx::GpuMemoryBuffer::ATCIA:
20 case gfx::GpuMemoryBuffer::DXT5:
21 return 8;
22 case gfx::GpuMemoryBuffer::ATC:
23 case gfx::GpuMemoryBuffer::DXT1:
24 case gfx::GpuMemoryBuffer::ETC1:
18 return 4; 25 return 4;
19 } 26 }
20 27
21 NOTREACHED(); 28 NOTREACHED();
22 return 0; 29 return 0;
23 } 30 }
24 31
25 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 32 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
26 public: 33 public:
27 GpuMemoryBufferImpl(const gfx::Size& size, 34 GpuMemoryBufferImpl(const gfx::Size& size,
28 Format format, 35 Format format,
29 scoped_ptr<base::SharedMemory> shared_memory) 36 scoped_ptr<base::SharedMemory> shared_memory)
30 : size_(size), 37 : size_(size),
31 format_(format), 38 format_(format),
32 shared_memory_(shared_memory.Pass()), 39 shared_memory_(shared_memory.Pass()),
33 mapped_(false) {} 40 mapped_(false) {}
34 41
35 // Overridden from gfx::GpuMemoryBuffer: 42 // Overridden from gfx::GpuMemoryBuffer:
36 void* Map() override { 43 void* Map() override {
37 DCHECK(!mapped_); 44 DCHECK(!mapped_);
38 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_))) 45 if (!shared_memory_->Map(size_.GetArea() * BitsPerPixel(format_) / 8))
39 return NULL; 46 return NULL;
40 mapped_ = true; 47 mapped_ = true;
41 return shared_memory_->memory(); 48 return shared_memory_->memory();
42 } 49 }
43 void Unmap() override { 50 void Unmap() override {
44 DCHECK(mapped_); 51 DCHECK(mapped_);
45 shared_memory_->Unmap(); 52 shared_memory_->Unmap();
46 mapped_ = false; 53 mapped_ = false;
47 } 54 }
48 bool IsMapped() const override { return mapped_; } 55 bool IsMapped() const override { return mapped_; }
49 Format GetFormat() const override { return format_; } 56 Format GetFormat() const override { return format_; }
50 uint32 GetStride() const override { 57 uint32 GetStride() const override {
51 return size_.width() * BytesPerPixel(format_); 58 return size_.width() * BitsPerPixel(format_) / 8;
52 } 59 }
53 gfx::GpuMemoryBufferHandle GetHandle() const override { 60 gfx::GpuMemoryBufferHandle GetHandle() const override {
54 gfx::GpuMemoryBufferHandle handle; 61 gfx::GpuMemoryBufferHandle handle;
55 handle.type = gfx::SHARED_MEMORY_BUFFER; 62 handle.type = gfx::SHARED_MEMORY_BUFFER;
56 handle.handle = shared_memory_->handle(); 63 handle.handle = shared_memory_->handle();
57 return handle; 64 return handle;
58 } 65 }
59 ClientBuffer AsClientBuffer() override { 66 ClientBuffer AsClientBuffer() override {
60 return reinterpret_cast<ClientBuffer>(this); 67 return reinterpret_cast<ClientBuffer>(this);
61 } 68 }
(...skipping 12 matching lines...) Expand all
74 81
75 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() { 82 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
76 } 83 }
77 84
78 scoped_ptr<gfx::GpuMemoryBuffer> 85 scoped_ptr<gfx::GpuMemoryBuffer>
79 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer( 86 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
80 const gfx::Size& size, 87 const gfx::Size& size,
81 gfx::GpuMemoryBuffer::Format format, 88 gfx::GpuMemoryBuffer::Format format,
82 gfx::GpuMemoryBuffer::Usage usage) { 89 gfx::GpuMemoryBuffer::Usage usage) {
83 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); 90 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
84 if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format))) 91 if (!shared_memory->CreateAnonymous(size.GetArea() * BitsPerPixel(format) /
92 8))
85 return nullptr; 93 return nullptr;
86 return make_scoped_ptr<gfx::GpuMemoryBuffer>( 94 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
87 new GpuMemoryBufferImpl(size, format, shared_memory.Pass())); 95 new GpuMemoryBufferImpl(size, format, shared_memory.Pass()));
88 } 96 }
89 97
90 gfx::GpuMemoryBuffer* 98 gfx::GpuMemoryBuffer*
91 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( 99 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
92 ClientBuffer buffer) { 100 ClientBuffer buffer) {
93 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); 101 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
94 } 102 }
95 103
96 void TestGpuMemoryBufferManager::SetDestructionSyncPoint( 104 void TestGpuMemoryBufferManager::SetDestructionSyncPoint(
97 gfx::GpuMemoryBuffer* buffer, 105 gfx::GpuMemoryBuffer* buffer,
98 uint32 sync_point) { 106 uint32 sync_point) {
99 } 107 }
100 108
101 } // namespace cc 109 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_gles2_interface.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698