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

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

Issue 10392068: ui: Move gl/ directory out of gfx/, up to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac_rel Created 8 years, 7 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/gfx/gl/gl_surface_osmesa.h ('k') | ui/gfx/gl/gl_surface_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/gl/gl_surface_osmesa.h"
6 #include "base/logging.h"
7 #include "ui/gfx/gl/gl_bindings.h"
8 #include "ui/gfx/gl/gl_context.h"
9
10 namespace gfx {
11
12 GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size)
13 : format_(format),
14 size_(size) {
15 }
16
17 bool GLSurfaceOSMesa::Initialize() {
18 return Resize(size_);
19 }
20
21 void GLSurfaceOSMesa::Destroy() {
22 buffer_.reset();
23 }
24
25 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
26 GLContext* current_context = GLContext::GetCurrent();
27 bool was_current = current_context && current_context->IsCurrent(this);
28 if (was_current)
29 current_context->ReleaseCurrent(this);
30
31 // Preserve the old buffer.
32 scoped_array<int32> old_buffer(buffer_.release());
33
34 // Allocate a new one.
35 buffer_.reset(new int32[new_size.GetArea()]);
36 memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0]));
37
38 // Copy the old back buffer into the new buffer.
39 if (old_buffer.get()) {
40 int copy_width = std::min(size_.width(), new_size.width());
41 int copy_height = std::min(size_.height(), new_size.height());
42 for (int y = 0; y < copy_height; ++y) {
43 for (int x = 0; x < copy_width; ++x) {
44 buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x];
45 }
46 }
47 }
48
49 size_ = new_size;
50
51 if (was_current)
52 return current_context->MakeCurrent(this);
53
54 return true;
55 }
56
57 bool GLSurfaceOSMesa::IsOffscreen() {
58 return true;
59 }
60
61 bool GLSurfaceOSMesa::SwapBuffers() {
62 NOTREACHED() << "Should not call SwapBuffers on an GLSurfaceOSMesa.";
63 return false;
64 }
65
66 gfx::Size GLSurfaceOSMesa::GetSize() {
67 return size_;
68 }
69
70 void* GLSurfaceOSMesa::GetHandle() {
71 return buffer_.get();
72 }
73
74 unsigned GLSurfaceOSMesa::GetFormat() {
75 return format_;
76 }
77
78 GLSurfaceOSMesa::~GLSurfaceOSMesa() {
79 Destroy();
80 }
81
82 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_surface_osmesa.h ('k') | ui/gfx/gl/gl_surface_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698