Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: ui/gl/gl_surface_osmesa.cc

Issue 15928002: GPU: Keep track of the last real context and real surface made current. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix unnecessary changes. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_surface_egl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gl/gl_bindings.h" 6 #include "ui/gl/gl_bindings.h"
7 #include "ui/gl/gl_context.h" 7 #include "ui/gl/gl_context.h"
8 #include "ui/gl/gl_surface_osmesa.h" 8 #include "ui/gl/gl_surface_osmesa.h"
9 #include "ui/gl/scoped_make_current.h"
9 10
10 namespace gfx { 11 namespace gfx {
11 12
12 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size) 13 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size)
13 : format_(format), 14 : format_(format),
14 size_(size) { 15 size_(size) {
15 } 16 }
16 17
17 bool GLSurfaceOSMesa::Initialize() { 18 bool GLSurfaceOSMesa::Initialize() {
18 return Resize(size_); 19 return Resize(size_);
19 } 20 }
20 21
21 void GLSurfaceOSMesa::Destroy() { 22 void GLSurfaceOSMesa::Destroy() {
22 buffer_.reset(); 23 buffer_.reset();
23 } 24 }
24 25
25 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { 26 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
27 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
26 GLContext* current_context = GLContext::GetCurrent(); 28 GLContext* current_context = GLContext::GetCurrent();
27 bool was_current = current_context && current_context->IsCurrent(this); 29 bool was_current =
28 if (was_current) 30 current_context && current_context->IsCurrent(this);
31 if (was_current) {
32 scoped_make_current.reset(
33 new ui::ScopedMakeCurrent(current_context, this));
29 current_context->ReleaseCurrent(this); 34 current_context->ReleaseCurrent(this);
35 }
30 36
31 // Preserve the old buffer. 37 // Preserve the old buffer.
32 scoped_ptr<int32[]> old_buffer(buffer_.release()); 38 scoped_ptr<int32[]> old_buffer(buffer_.release());
33 39
34 // Allocate a new one. 40 // Allocate a new one.
35 buffer_.reset(new int32[new_size.GetArea()]); 41 buffer_.reset(new int32[new_size.GetArea()]);
36 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0])); 42 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0]));
37 43
38 // Copy the old back buffer into the new buffer. 44 // Copy the old back buffer into the new buffer.
39 if (old_buffer.get()) { 45 if (old_buffer.get()) {
40 int copy_width = std::min(size_.width(), new_size.width()); 46 int copy_width = std::min(size_.width(), new_size.width());
41 int copy_height = std::min(size_.height(), new_size.height()); 47 int copy_height = std::min(size_.height(), new_size.height());
42 for (int y = 0; y < copy_height; ++y) { 48 for (int y = 0; y < copy_height; ++y) {
43 for (int x = 0; x < copy_width; ++x) { 49 for (int x = 0; x < copy_width; ++x) {
44 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x]; 50 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x];
45 } 51 }
46 } 52 }
47 } 53 }
48 54
49 size_ = new_size; 55 size_ = new_size;
50 56
51 if (was_current)
52 return current_context->MakeCurrent(this);
53
54 return true; 57 return true;
55 } 58 }
56 59
57 bool GLSurfaceOSMesa::IsOffscreen() { 60 bool GLSurfaceOSMesa::IsOffscreen() {
58 return true; 61 return true;
59 } 62 }
60 63
61 bool GLSurfaceOSMesa::SwapBuffers() { 64 bool GLSurfaceOSMesa::SwapBuffers() {
62 NOTREACHED() << "Should not call SwapBuffers on an GLSurfaceOSMesa."; 65 NOTREACHED() << "Should not call SwapBuffers on an GLSurfaceOSMesa.";
63 return false; 66 return false;
64 } 67 }
65 68
66 gfx::Size GLSurfaceOSMesa::GetSize() { 69 gfx::Size GLSurfaceOSMesa::GetSize() {
67 return size_; 70 return size_;
68 } 71 }
69 72
70 void* GLSurfaceOSMesa::GetHandle() { 73 void* GLSurfaceOSMesa::GetHandle() {
71 return buffer_.get(); 74 return buffer_.get();
72 } 75 }
73 76
74 unsigned GLSurfaceOSMesa::GetFormat() { 77 unsigned GLSurfaceOSMesa::GetFormat() {
75 return format_; 78 return format_;
76 } 79 }
77 80
78 GLSurfaceOSMesa::~GLSurfaceOSMesa() { 81 GLSurfaceOSMesa::~GLSurfaceOSMesa() {
79 Destroy(); 82 Destroy();
80 } 83 }
81 84
82 } // namespace gfx 85 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_egl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698