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 18 matching lines...) Expand all Loading... |
29 return Resize(size_, 1.f, true); | 29 return Resize(size_, 1.f, true); |
30 } | 30 } |
31 | 31 |
32 void GLSurfaceOSMesa::Destroy() { | 32 void GLSurfaceOSMesa::Destroy() { |
33 buffer_.reset(); | 33 buffer_.reset(); |
34 } | 34 } |
35 | 35 |
36 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size, | 36 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size, |
37 float scale_factor, | 37 float scale_factor, |
38 bool has_alpha) { | 38 bool has_alpha) { |
39 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 39 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
40 GLContext* current_context = GLContext::GetCurrent(); | 40 GLContext* current_context = GLContext::GetCurrent(); |
41 bool was_current = | 41 bool was_current = |
42 current_context && current_context->IsCurrent(this); | 42 current_context && current_context->IsCurrent(this); |
43 if (was_current) { | 43 if (was_current) { |
44 scoped_make_current.reset( | 44 scoped_make_current.reset( |
45 new ui::ScopedMakeCurrent(current_context, this)); | 45 new ui::ScopedMakeCurrent(current_context, this)); |
46 current_context->ReleaseCurrent(this); | 46 current_context->ReleaseCurrent(this); |
47 } | 47 } |
48 | 48 |
49 // Preserve the old buffer. | 49 // Preserve the old buffer. |
50 scoped_ptr<int32_t[]> old_buffer(buffer_.release()); | 50 std::unique_ptr<int32_t[]> old_buffer(buffer_.release()); |
51 | 51 |
52 base::CheckedNumeric<int> checked_size = sizeof(buffer_[0]); | 52 base::CheckedNumeric<int> checked_size = sizeof(buffer_[0]); |
53 checked_size *= new_size.width(); | 53 checked_size *= new_size.width(); |
54 checked_size *= new_size.height(); | 54 checked_size *= new_size.height(); |
55 if (!checked_size.IsValid()) | 55 if (!checked_size.IsValid()) |
56 return false; | 56 return false; |
57 | 57 |
58 // Allocate a new one. | 58 // Allocate a new one. |
59 buffer_.reset(new int32_t[new_size.GetArea()]); | 59 buffer_.reset(new int32_t[new_size.GetArea()]); |
60 if (!buffer_.get()) | 60 if (!buffer_.get()) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return gfx::SwapResult::SWAP_ACK; | 109 return gfx::SwapResult::SWAP_ACK; |
110 } | 110 } |
111 | 111 |
112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() |
113 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)) { | 113 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)) { |
114 } | 114 } |
115 | 115 |
116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
117 | 117 |
118 } // namespace gfx | 118 } // namespace gfx |
OLD | NEW |