1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/renderer_host/backing_store_manager_glx.h"
#include <GL/gl.h>
#include <X11/Xutil.h>
#include "base/scoped_ptr.h"
#include "chrome/common/x11_util.h"
namespace {
// scoped_ptr functor for XFree().
class ScopedPtrXFree {
public:
inline void operator()(void* x) const {
::XFree(x);
}
};
} // namespace
BackingStoreManagerGlx::BackingStoreManagerGlx()
: display_(x11_util::GetXDisplay()),
tried_to_init_(false),
context_(NULL),
previous_window_id_(0) {
}
BackingStoreManagerGlx::~BackingStoreManagerGlx() {
if (context_)
glXDestroyContext(display_, context_);
}
GLXContext BackingStoreManagerGlx::BindContext(XID window_id) {
if (tried_to_init_) {
if (!context_)
return NULL;
if (!previous_window_id_ || previous_window_id_ != window_id)
::glXMakeCurrent(display_, window_id, context_);
previous_window_id_ = window_id;
return context_;
}
tried_to_init_ = true;
int attrib_list[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info(
::glXChooseVisual(display_, 0, attrib_list));
if (!visual_info.get())
return NULL;
context_ = ::glXCreateContext(display_, visual_info.get(), NULL, True);
::glXMakeCurrent(display_, window_id, context_);
return context_;
}
|