| 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 #include "ui/gfx/gl/gl_context.h" |
| 8 | 9 |
| 9 namespace gfx { | 10 namespace gfx { |
| 10 | 11 |
| 11 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size) | 12 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size) |
| 12 : format_(format), | 13 : format_(format), |
| 13 size_(size) { | 14 size_(size) { |
| 14 } | 15 } |
| 15 | 16 |
| 16 GLSurfaceOSMesa::~GLSurfaceOSMesa() { | 17 GLSurfaceOSMesa::~GLSurfaceOSMesa() { |
| 17 Destroy(); | 18 Destroy(); |
| 18 } | 19 } |
| 19 | 20 |
| 20 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { | 21 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
| 21 if (new_size == size_) | 22 if (new_size == size_) |
| 22 return true; | 23 return true; |
| 23 | 24 |
| 25 GLContext* current_context = GLContext::GetCurrent(); |
| 26 bool was_current = current_context && current_context->IsCurrent(this); |
| 27 if (was_current) |
| 28 current_context->ReleaseCurrent(this); |
| 29 |
| 24 // Preserve the old buffer. | 30 // Preserve the old buffer. |
| 25 scoped_array<int32> old_buffer(buffer_.release()); | 31 scoped_array<int32> old_buffer(buffer_.release()); |
| 26 | 32 |
| 27 // Allocate a new one. | 33 // Allocate a new one. |
| 28 AllocateBuffer(new_size); | 34 AllocateBuffer(new_size); |
| 29 | 35 |
| 30 // Copy the old back buffer into the new buffer. | 36 // Copy the old back buffer into the new buffer. |
| 31 int copy_width = std::min(size_.width(), new_size.width()); | 37 int copy_width = std::min(size_.width(), new_size.width()); |
| 32 int copy_height = std::min(size_.height(), new_size.height()); | 38 int copy_height = std::min(size_.height(), new_size.height()); |
| 33 for (int y = 0; y < copy_height; ++y) { | 39 for (int y = 0; y < copy_height; ++y) { |
| 34 for (int x = 0; x < copy_width; ++x) { | 40 for (int x = 0; x < copy_width; ++x) { |
| 35 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; | 41 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; |
| 36 } | 42 } |
| 37 } | 43 } |
| 38 | 44 |
| 39 size_ = new_size; | 45 size_ = new_size; |
| 46 |
| 47 if (was_current) |
| 48 return current_context->MakeCurrent(this); |
| 49 |
| 40 return true; | 50 return true; |
| 41 } | 51 } |
| 42 | 52 |
| 43 bool GLSurfaceOSMesa::Initialize() { | 53 bool GLSurfaceOSMesa::Initialize() { |
| 44 AllocateBuffer(size_); | 54 AllocateBuffer(size_); |
| 45 return true; | 55 return true; |
| 46 } | 56 } |
| 47 | 57 |
| 48 void GLSurfaceOSMesa::Destroy() { | 58 void GLSurfaceOSMesa::Destroy() { |
| 49 buffer_.reset(); | 59 buffer_.reset(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 unsigned GLSurfaceOSMesa::GetFormat() { | 79 unsigned GLSurfaceOSMesa::GetFormat() { |
| 70 return format_; | 80 return format_; |
| 71 } | 81 } |
| 72 | 82 |
| 73 void GLSurfaceOSMesa::AllocateBuffer(const Size& size) { | 83 void GLSurfaceOSMesa::AllocateBuffer(const Size& size) { |
| 74 buffer_.reset(new int32[size.GetArea()]); | 84 buffer_.reset(new int32[size.GetArea()]); |
| 75 memset(buffer_.get(), 0, size.GetArea() * sizeof(buffer_[0])); | 85 memset(buffer_.get(), 0, size.GetArea() * sizeof(buffer_[0])); |
| 76 } | 86 } |
| 77 | 87 |
| 78 } // namespace gfx | 88 } // namespace gfx |
| OLD | NEW |