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

Side by Side Diff: ui/gfx/gl/gl_context_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_context_osmesa.h ('k') | ui/gfx/gl/gl_context_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 <GL/osmesa.h>
6
7 #include "ui/gfx/gl/gl_context_osmesa.h"
8
9 #include "base/logging.h"
10 #include "ui/gfx/gl/gl_bindings.h"
11 #include "ui/gfx/gl/gl_surface.h"
12 #include "ui/gfx/size.h"
13
14 namespace gfx {
15
16 GLContextOSMesa::GLContextOSMesa(GLShareGroup* share_group)
17 : GLContext(share_group),
18 context_(NULL) {
19 }
20
21 bool GLContextOSMesa::Initialize(GLSurface* compatible_surface,
22 GpuPreference gpu_preference) {
23 DCHECK(!context_);
24
25 OSMesaContext share_handle = static_cast<OSMesaContext>(
26 share_group() ? share_group()->GetHandle() : NULL);
27
28 GLuint format = compatible_surface->GetFormat();
29 DCHECK_NE(format, (unsigned)0);
30 context_ = OSMesaCreateContextExt(format,
31 0, // depth bits
32 0, // stencil bits
33 0, // accum bits
34 share_handle);
35 if (!context_) {
36 LOG(ERROR) << "OSMesaCreateContextExt failed.";
37 return false;
38 }
39
40 return true;
41 }
42
43 void GLContextOSMesa::Destroy() {
44 if (context_) {
45 OSMesaDestroyContext(static_cast<OSMesaContext>(context_));
46 context_ = NULL;
47 }
48 }
49
50 bool GLContextOSMesa::MakeCurrent(GLSurface* surface) {
51 DCHECK(context_);
52
53 gfx::Size size = surface->GetSize();
54
55 if (!OSMesaMakeCurrent(context_,
56 surface->GetHandle(),
57 GL_UNSIGNED_BYTE,
58 size.width(),
59 size.height())) {
60 LOG(ERROR) << "OSMesaMakeCurrent failed.";
61 Destroy();
62 return false;
63 }
64
65 // Row 0 is at the top.
66 OSMesaPixelStore(OSMESA_Y_UP, 0);
67
68 SetCurrent(this, surface);
69 if (!InitializeExtensionBindings()) {
70 ReleaseCurrent(surface);
71 return false;
72 }
73
74 if (!surface->OnMakeCurrent(this)) {
75 LOG(ERROR) << "Could not make current.";
76 return false;
77 }
78
79 return true;
80 }
81
82 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) {
83 if (!IsCurrent(surface))
84 return;
85
86 SetCurrent(NULL, NULL);
87 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0);
88 }
89
90 bool GLContextOSMesa::IsCurrent(GLSurface* surface) {
91 DCHECK(context_);
92
93 bool native_context_is_current =
94 context_ == OSMesaGetCurrentContext();
95
96 // If our context is current then our notion of which GLContext is
97 // current must be correct. On the other hand, third-party code
98 // using OpenGL might change the current context.
99 DCHECK(!native_context_is_current || (GetCurrent() == this));
100
101 if (!native_context_is_current)
102 return false;
103
104 if (surface) {
105 GLint width;
106 GLint height;
107 GLint format;
108 void* buffer = NULL;
109 OSMesaGetColorBuffer(context_, &width, &height, &format, &buffer);
110 if (buffer != surface->GetHandle())
111 return false;
112 }
113
114 return true;
115 }
116
117 void* GLContextOSMesa::GetHandle() {
118 return context_;
119 }
120
121 void GLContextOSMesa::SetSwapInterval(int interval) {
122 DCHECK(IsCurrent(NULL));
123 LOG(WARNING) << "GLContextOSMesa::SetSwapInterval is ignored.";
124 }
125
126 GLContextOSMesa::~GLContextOSMesa() {
127 Destroy();
128 }
129
130 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_context_osmesa.h ('k') | ui/gfx/gl/gl_context_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698