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

Side by Side Diff: gpu/command_buffer/tests/gl_manager.cc

Issue 806653006: Update GPU memory buffers to use StrideInBytes internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 5 years, 11 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 | « content/common/gpu/gpu_memory_buffer_factory_shared_memory.cc ('k') | ui/gl/gl_image_memory.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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "gpu/command_buffer/tests/gl_manager.h" 5 #include "gpu/command_buffer/tests/gl_manager.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h> 9 #include <GLES2/gl2extchromium.h>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/gpu_memory_buffer.h" 31 #include "ui/gfx/gpu_memory_buffer.h"
32 #include "ui/gl/gl_context.h" 32 #include "ui/gl/gl_context.h"
33 #include "ui/gl/gl_image_ref_counted_memory.h" 33 #include "ui/gl/gl_image_ref_counted_memory.h"
34 #include "ui/gl/gl_share_group.h" 34 #include "ui/gl/gl_share_group.h"
35 #include "ui/gl/gl_surface.h" 35 #include "ui/gl/gl_surface.h"
36 36
37 namespace gpu { 37 namespace gpu {
38 namespace { 38 namespace {
39 39
40 size_t BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { 40 size_t StrideInBytes(size_t width, gfx::GpuMemoryBuffer::Format format) {
41 switch (format) { 41 switch (format) {
42 case gfx::GpuMemoryBuffer::RGBA_8888: 42 case gfx::GpuMemoryBuffer::RGBA_8888:
43 case gfx::GpuMemoryBuffer::BGRA_8888: 43 case gfx::GpuMemoryBuffer::BGRA_8888:
44 return 4; 44 return width * 4;
45 case gfx::GpuMemoryBuffer::RGBX_8888: 45 case gfx::GpuMemoryBuffer::RGBX_8888:
46 NOTREACHED(); 46 NOTREACHED();
47 return 0; 47 return 0;
48 } 48 }
49 49
50 NOTREACHED(); 50 NOTREACHED();
51 return 0; 51 return 0;
52 } 52 }
53 53
54 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 54 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
55 public: 55 public:
56 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, 56 GpuMemoryBufferImpl(base::RefCountedBytes* bytes,
57 const gfx::Size& size, 57 const gfx::Size& size,
58 gfx::GpuMemoryBuffer::Format format) 58 gfx::GpuMemoryBuffer::Format format)
59 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} 59 : bytes_(bytes), size_(size), format_(format), mapped_(false) {}
60 60
61 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { 61 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) {
62 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 62 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
63 } 63 }
64 64
65 // Overridden from gfx::GpuMemoryBuffer: 65 // Overridden from gfx::GpuMemoryBuffer:
66 void* Map() override { 66 void* Map() override {
67 mapped_ = true; 67 mapped_ = true;
68 return &bytes_->data().front(); 68 return &bytes_->data().front();
69 } 69 }
70 void Unmap() override { mapped_ = false; } 70 void Unmap() override { mapped_ = false; }
71 bool IsMapped() const override { return mapped_; } 71 bool IsMapped() const override { return mapped_; }
72 Format GetFormat() const override { return format_; } 72 Format GetFormat() const override { return format_; }
73 uint32 GetStride() const override { 73 uint32 GetStride() const override {
74 return size_.width() * BytesPerPixel(format_); 74 return StrideInBytes(size_.width(), format_);
75 } 75 }
76 gfx::GpuMemoryBufferHandle GetHandle() const override { 76 gfx::GpuMemoryBufferHandle GetHandle() const override {
77 NOTREACHED(); 77 NOTREACHED();
78 return gfx::GpuMemoryBufferHandle(); 78 return gfx::GpuMemoryBufferHandle();
79 } 79 }
80 ClientBuffer AsClientBuffer() override { 80 ClientBuffer AsClientBuffer() override {
81 return reinterpret_cast<ClientBuffer>(this); 81 return reinterpret_cast<ClientBuffer>(this);
82 } 82 }
83 83
84 base::RefCountedBytes* bytes() { return bytes_.get(); } 84 base::RefCountedBytes* bytes() { return bytes_.get(); }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 delete base_context_; 126 delete base_context_;
127 base_context_ = NULL; 127 base_context_ = NULL;
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 // static 132 // static
133 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( 133 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer(
134 const gfx::Size& size, 134 const gfx::Size& size,
135 gfx::GpuMemoryBuffer::Format format) { 135 gfx::GpuMemoryBuffer::Format format) {
136 std::vector<unsigned char> data(size.GetArea() * BytesPerPixel(format), 0); 136 std::vector<unsigned char> data(
137 StrideInBytes(size.width(), format) * size.height(), 0);
137 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); 138 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data));
138 return make_scoped_ptr<gfx::GpuMemoryBuffer>( 139 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
139 new GpuMemoryBufferImpl(bytes.get(), size, format)); 140 new GpuMemoryBufferImpl(bytes.get(), size, format));
140 } 141 }
141 142
142 void GLManager::Initialize(const GLManager::Options& options) { 143 void GLManager::Initialize(const GLManager::Options& options) {
143 InitializeWithCommandLine(options, nullptr); 144 InitializeWithCommandLine(options, nullptr);
144 } 145 }
145 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, 146 void GLManager::InitializeWithCommandLine(const GLManager::Options& options,
146 base::CommandLine* command_line) { 147 base::CommandLine* command_line) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 void GLManager::SetSurfaceVisible(bool visible) { 421 void GLManager::SetSurfaceVisible(bool visible) {
421 NOTIMPLEMENTED(); 422 NOTIMPLEMENTED();
422 } 423 }
423 424
424 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { 425 uint32 GLManager::CreateStreamTexture(uint32 texture_id) {
425 NOTIMPLEMENTED(); 426 NOTIMPLEMENTED();
426 return 0; 427 return 0;
427 } 428 }
428 429
429 } // namespace gpu 430 } // namespace gpu
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_memory_buffer_factory_shared_memory.cc ('k') | ui/gl/gl_image_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698