OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/gl/gl_surface_osmesa.h" | 5 #include "ui/gfx/gl/gl_surface_osmesa.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "ui/gfx/gl/gl_bindings.h" | 7 #include "ui/gfx/gl/gl_bindings.h" |
8 | 8 |
9 namespace gfx { | 9 namespace gfx { |
10 | 10 |
11 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size) | 11 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size) |
12 : format_(format), | 12 : format_(format), |
13 size_(size) { | 13 size_(size) { |
14 } | 14 } |
15 | 15 |
16 GLSurfaceOSMesa::~GLSurfaceOSMesa() { | 16 GLSurfaceOSMesa::~GLSurfaceOSMesa() { |
17 Destroy(); | 17 Destroy(); |
18 } | 18 } |
19 | 19 |
20 void GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { | 20 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
21 if (new_size == size_) | 21 if (new_size == size_) |
22 return; | 22 return true; |
23 | 23 |
24 // Preserve the old buffer. | 24 // Preserve the old buffer. |
25 scoped_array<int32> old_buffer(buffer_.release()); | 25 scoped_array<int32> old_buffer(buffer_.release()); |
26 | 26 |
27 // Allocate a new one. | 27 // Allocate a new one. |
28 AllocateBuffer(new_size); | 28 AllocateBuffer(new_size); |
29 | 29 |
30 // Copy the old back buffer into the new buffer. | 30 // Copy the old back buffer into the new buffer. |
31 int copy_width = std::min(size_.width(), new_size.width()); | 31 int copy_width = std::min(size_.width(), new_size.width()); |
32 int copy_height = std::min(size_.height(), new_size.height()); | 32 int copy_height = std::min(size_.height(), new_size.height()); |
33 for (int y = 0; y < copy_height; ++y) { | 33 for (int y = 0; y < copy_height; ++y) { |
34 for (int x = 0; x < copy_width; ++x) { | 34 for (int x = 0; x < copy_width; ++x) { |
35 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; | 35 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 size_ = new_size; | 39 size_ = new_size; |
| 40 return true; |
40 } | 41 } |
41 | 42 |
42 bool GLSurfaceOSMesa::Initialize() { | 43 bool GLSurfaceOSMesa::Initialize() { |
43 AllocateBuffer(size_); | 44 AllocateBuffer(size_); |
44 return true; | 45 return true; |
45 } | 46 } |
46 | 47 |
47 void GLSurfaceOSMesa::Destroy() { | 48 void GLSurfaceOSMesa::Destroy() { |
48 buffer_.reset(); | 49 buffer_.reset(); |
49 } | 50 } |
(...skipping 18 matching lines...) Expand all Loading... |
68 unsigned GLSurfaceOSMesa::GetFormat() { | 69 unsigned GLSurfaceOSMesa::GetFormat() { |
69 return format_; | 70 return format_; |
70 } | 71 } |
71 | 72 |
72 void GLSurfaceOSMesa::AllocateBuffer(const Size& size) { | 73 void GLSurfaceOSMesa::AllocateBuffer(const Size& size) { |
73 buffer_.reset(new int32[size.GetArea()]); | 74 buffer_.reset(new int32[size.GetArea()]); |
74 memset(buffer_.get(), 0, size.GetArea() * sizeof(buffer_[0])); | 75 memset(buffer_.get(), 0, size.GetArea() * sizeof(buffer_[0])); |
75 } | 76 } |
76 | 77 |
77 } // namespace gfx | 78 } // namespace gfx |
OLD | NEW |