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 "ui/gl/gl_surface_osmesa.h" | 5 #include "ui/gl/gl_surface_osmesa.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 GLContext* current_context = GLContext::GetCurrent(); | 47 GLContext* current_context = GLContext::GetCurrent(); |
48 bool was_current = | 48 bool was_current = |
49 current_context && current_context->IsCurrent(this); | 49 current_context && current_context->IsCurrent(this); |
50 if (was_current) { | 50 if (was_current) { |
51 scoped_make_current.reset( | 51 scoped_make_current.reset( |
52 new ui::ScopedMakeCurrent(current_context, this)); | 52 new ui::ScopedMakeCurrent(current_context, this)); |
53 current_context->ReleaseCurrent(this); | 53 current_context->ReleaseCurrent(this); |
54 } | 54 } |
55 | 55 |
56 // Preserve the old buffer. | 56 // Preserve the old buffer. |
57 scoped_ptr<int32[]> old_buffer(buffer_.release()); | 57 scoped_ptr<int32_t[]> old_buffer(buffer_.release()); |
58 | 58 |
59 base::CheckedNumeric<int> checked_size = sizeof(buffer_[0]); | 59 base::CheckedNumeric<int> checked_size = sizeof(buffer_[0]); |
60 checked_size *= new_size.width(); | 60 checked_size *= new_size.width(); |
61 checked_size *= new_size.height(); | 61 checked_size *= new_size.height(); |
62 if (!checked_size.IsValid()) | 62 if (!checked_size.IsValid()) |
63 return false; | 63 return false; |
64 | 64 |
65 // Allocate a new one. | 65 // Allocate a new one. |
66 buffer_.reset(new int32[new_size.GetArea()]); | 66 buffer_.reset(new int32_t[new_size.GetArea()]); |
67 if (!buffer_.get()) | 67 if (!buffer_.get()) |
68 return false; | 68 return false; |
69 | 69 |
70 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0])); | 70 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0])); |
71 | 71 |
72 // Copy the old back buffer into the new buffer. | 72 // Copy the old back buffer into the new buffer. |
73 if (old_buffer.get()) { | 73 if (old_buffer.get()) { |
74 int copy_width = std::min(size_.width(), new_size.width()); | 74 int copy_width = std::min(size_.width(), new_size.width()); |
75 int copy_height = std::min(size_.height(), new_size.height()); | 75 int copy_height = std::min(size_.height(), new_size.height()); |
76 for (int y = 0; y < copy_height; ++y) { | 76 for (int y = 0; y < copy_height; ++y) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return gfx::SwapResult::SWAP_ACK; | 116 return gfx::SwapResult::SWAP_ACK; |
117 } | 117 } |
118 | 118 |
119 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 119 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() |
120 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { | 120 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { |
121 } | 121 } |
122 | 122 |
123 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 123 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
124 | 124 |
125 } // namespace gfx | 125 } // namespace gfx |
OLD | NEW |