| OLD | NEW |
| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/numerics/safe_math.h" |
| 6 #include "third_party/mesa/src/include/GL/osmesa.h" | 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
| 7 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
| 8 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
| 9 #include "ui/gl/gl_surface_osmesa.h" | 10 #include "ui/gl/gl_surface_osmesa.h" |
| 10 #include "ui/gl/scoped_make_current.h" | 11 #include "ui/gl/scoped_make_current.h" |
| 11 | 12 |
| 12 namespace gfx { | 13 namespace gfx { |
| 13 | 14 |
| 14 GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format, | 15 GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format, |
| 15 const gfx::Size& size) | 16 const gfx::Size& size) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 43 current_context && current_context->IsCurrent(this); | 44 current_context && current_context->IsCurrent(this); |
| 44 if (was_current) { | 45 if (was_current) { |
| 45 scoped_make_current.reset( | 46 scoped_make_current.reset( |
| 46 new ui::ScopedMakeCurrent(current_context, this)); | 47 new ui::ScopedMakeCurrent(current_context, this)); |
| 47 current_context->ReleaseCurrent(this); | 48 current_context->ReleaseCurrent(this); |
| 48 } | 49 } |
| 49 | 50 |
| 50 // Preserve the old buffer. | 51 // Preserve the old buffer. |
| 51 scoped_ptr<int32[]> old_buffer(buffer_.release()); | 52 scoped_ptr<int32[]> old_buffer(buffer_.release()); |
| 52 | 53 |
| 54 base::CheckedNumeric<int> checked_size = sizeof(buffer_[0]); |
| 55 checked_size *= new_size.width(); |
| 56 checked_size *= new_size.height(); |
| 57 if (!checked_size.IsValid()) |
| 58 return false; |
| 59 |
| 53 // Allocate a new one. | 60 // Allocate a new one. |
| 54 buffer_.reset(new int32[new_size.GetArea()]); | 61 buffer_.reset(new int32[new_size.GetArea()]); |
| 62 if (!buffer_.get()) |
| 63 return false; |
| 64 |
| 55 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0])); | 65 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0])); |
| 56 | 66 |
| 57 // Copy the old back buffer into the new buffer. | 67 // Copy the old back buffer into the new buffer. |
| 58 if (old_buffer.get()) { | 68 if (old_buffer.get()) { |
| 59 int copy_width = std::min(size_.width(), new_size.width()); | 69 int copy_width = std::min(size_.width(), new_size.width()); |
| 60 int copy_height = std::min(size_.height(), new_size.height()); | 70 int copy_height = std::min(size_.height(), new_size.height()); |
| 61 for (int y = 0; y < copy_height; ++y) { | 71 for (int y = 0; y < copy_height; ++y) { |
| 62 for (int x = 0; x < copy_width; ++x) { | 72 for (int x = 0; x < copy_width; ++x) { |
| 63 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; | 73 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; |
| 64 } | 74 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 109 |
| 100 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; } | 110 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; } |
| 101 | 111 |
| 102 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() |
| 103 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { | 113 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { |
| 104 } | 114 } |
| 105 | 115 |
| 106 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
| 107 | 117 |
| 108 } // namespace gfx | 118 } // namespace gfx |
| OLD | NEW |