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

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

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 months 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_gpu_memory_buffer_manager.h ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/test/test_gpu_memory_buffer_manager.h"
6
7 #include "base/logging.h"
8 #include "ui/gfx/gpu_memory_buffer.h"
9
10 namespace cc {
11 namespace {
12
13 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
14 public:
15 GpuMemoryBufferImpl(const gfx::Size& size, Format format)
16 : size_(size),
17 format_(format),
18 pixels_(new uint8[size.GetArea() * BytesPerPixel(format)]),
19 mapped_(false) {}
20
21 // Overridden from gfx::GpuMemoryBuffer:
22 virtual void* Map() override {
23 DCHECK(!mapped_);
24 mapped_ = true;
25 return pixels_.get();
26 }
27 virtual void Unmap() override {
28 DCHECK(mapped_);
29 mapped_ = false;
30 }
31 virtual bool IsMapped() const override { return mapped_; }
32 virtual Format GetFormat() const override { return format_; }
33 virtual uint32 GetStride() const override {
34 return size_.width() * BytesPerPixel(format_);
35 }
36 virtual gfx::GpuMemoryBufferHandle GetHandle() const override {
37 NOTREACHED();
38 return gfx::GpuMemoryBufferHandle();
39 }
40 virtual ClientBuffer AsClientBuffer() override {
41 return reinterpret_cast<ClientBuffer>(this);
42 }
43
44 private:
45 static size_t BytesPerPixel(Format format) {
46 switch (format) {
47 case RGBA_8888:
48 case RGBX_8888:
49 case BGRA_8888:
50 return 4;
51 }
52
53 NOTREACHED();
54 return 0;
55 }
56
57 const gfx::Size size_;
58 gfx::GpuMemoryBuffer::Format format_;
59 scoped_ptr<uint8[]> pixels_;
60 bool mapped_;
61 };
62
63 } // namespace
64
65 TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() {
66 }
67
68 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
69 }
70
71 scoped_ptr<gfx::GpuMemoryBuffer>
72 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
73 const gfx::Size& size,
74 gfx::GpuMemoryBuffer::Format format,
75 gfx::GpuMemoryBuffer::Usage usage) {
76 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
77 new GpuMemoryBufferImpl(size, format));
78 }
79
80 gfx::GpuMemoryBuffer*
81 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
82 ClientBuffer buffer) {
83 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
84 }
85
86 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_gpu_memory_buffer_manager.h ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698