blob: 7b6b89c2401b85939d533170f75762b56e81df8c (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright (c) 2011 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 "ui/gfx/gl/gl_surface_cgl.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "ui/gfx/gl/gl_bindings.h"
namespace gfx {
namespace {
CGLPixelFormatObj g_pixel_format;
}
GLSurfaceCGL::GLSurfaceCGL() {
}
GLSurfaceCGL::~GLSurfaceCGL() {
}
bool GLSurfaceCGL::InitializeOneOff() {
static bool initialized = false;
if (initialized)
return true;
static const CGLPixelFormatAttribute attribs[] = {
(CGLPixelFormatAttribute) kCGLPFAPBuffer,
(CGLPixelFormatAttribute) 0
};
CGLPixelFormatObj pixel_format;
GLint num_pixel_formats;
if (CGLChoosePixelFormat(attribs,
&g_pixel_format,
&num_pixel_formats) != kCGLNoError) {
LOG(ERROR) << "Error choosing pixel format.";
return false;
}
if (num_pixel_formats == 0) {
LOG(ERROR) << "num_pixel_formats == 0.";
return false;
}
if (!g_pixel_format) {
LOG(ERROR) << "pixel_format == 0.";
return false;
}
initialized = true;
return true;
}
void* GLSurfaceCGL::GetPixelFormat() {
return g_pixel_format;
}
PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size)
: size_(size),
pbuffer_(NULL) {
}
PbufferGLSurfaceCGL::~PbufferGLSurfaceCGL() {
Destroy();
}
bool PbufferGLSurfaceCGL::Initialize() {
if (CGLCreatePBuffer(size_.width(),
size_.height(),
GL_TEXTURE_2D,
GL_RGBA,
0,
reinterpret_cast<CGLPBufferObj*>(&pbuffer_))
!= kCGLNoError) {
LOG(ERROR) << "Error creating pbuffer.";
Destroy();
return false;
}
return true;
}
void PbufferGLSurfaceCGL::Destroy() {
if (pbuffer_) {
CGLDestroyPBuffer(static_cast<CGLPBufferObj>(pbuffer_));
pbuffer_ = NULL;
}
}
bool PbufferGLSurfaceCGL::IsOffscreen() {
return true;
}
bool PbufferGLSurfaceCGL::SwapBuffers() {
NOTREACHED() << "Cannot call SwapBuffers on a PbufferGLSurfaceCGL.";
return false;
}
gfx::Size PbufferGLSurfaceCGL::GetSize() {
return size_;
}
void* PbufferGLSurfaceCGL::GetHandle() {
return pbuffer_;
}
} // namespace gfx
|