-
Notifications
You must be signed in to change notification settings - Fork 8
/
egl_surface_factory.cc
216 lines (175 loc) · 5.17 KB
/
egl_surface_factory.cc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright 2014 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/ozone/platform/egl/egl_surface_factory.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/ozone/public/surface_ozone_egl.h"
#include "ui/ozone/public/surface_ozone_canvas.h"
#include "ui/ozone/public/surface_factory_ozone.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/vsync_provider.h"
#include "base/logging.h"
#include "egl_wrapper.h"
#ifndef GL_BGRA_EXT
#define GL_BGRA_EXT 0x80E1
#endif
#include <fcntl.h> /* For O_RDWR */
#include <unistd.h> /* For open(), creat() */
#include <linux/fb.h>
#include <sys/ioctl.h>
#define OZONE_EGL_WINDOW_WIDTH 1024
#define OZONE_EGL_WINDOW_HEIGTH 768
namespace ui {
class EglOzoneCanvas: public ui::SurfaceOzoneCanvas {
public:
EglOzoneCanvas();
virtual ~EglOzoneCanvas();
// SurfaceOzoneCanvas overrides:
virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE;
virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE {
return skia::SharePtr<SkCanvas>(surface_->getCanvas());
}
virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE;
virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
return scoped_ptr<gfx::VSyncProvider>();
}
private:
skia::RefPtr<SkSurface> surface_;
ozone_egl_UserData userDate_;
};
EglOzoneCanvas::EglOzoneCanvas()
{
memset(&userDate_,0,sizeof(userDate_));
}
EglOzoneCanvas::~EglOzoneCanvas()
{
ozone_egl_textureShutDown (&userDate_);
}
void EglOzoneCanvas::ResizeCanvas(const gfx::Size& viewport_size)
{
if(userDate_.width == viewport_size.width() && userDate_.height==viewport_size.height())
{
return;
}
else if(userDate_.width != 0 && userDate_.height !=0)
{
ozone_egl_textureShutDown (&userDate_);
}
surface_ = skia::AdoptRef(SkSurface::NewRaster(
SkImageInfo::Make(viewport_size.width(),
viewport_size.height(),
kPMColor_SkColorType,
kPremul_SkAlphaType)));
userDate_.width = viewport_size.width();
userDate_.height = viewport_size.height();
userDate_.colorType = GL_BGRA_EXT;
ozone_egl_textureInit ( &userDate_);
}
void EglOzoneCanvas::PresentCanvas(const gfx::Rect& damage)
{
SkImageInfo info;
size_t row_bytes;
userDate_.data = (char *) surface_->peekPixels(&info, &row_bytes);
ozone_egl_textureDraw(&userDate_);
ozone_egl_swap();
}
class OzoneEgl : public ui::SurfaceOzoneEGL {
public:
OzoneEgl(gfx::AcceleratedWidget window_id){
native_window_ = window_id;
}
virtual ~OzoneEgl() {
native_window_=0;
}
virtual intptr_t GetNativeWindow() OVERRIDE
{
return native_window_;
}
virtual bool OnSwapBuffers() OVERRIDE
{
return true;
}
virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE {
return true;
}
virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
return scoped_ptr<gfx::VSyncProvider>();
}
private:
intptr_t native_window_;
};
SurfaceFactoryEgl::SurfaceFactoryEgl():init_(false)
{
}
SurfaceFactoryEgl::~SurfaceFactoryEgl()
{
DestroySingleWindow();
}
EGLint g_width;
EGLint g_height;
bool SurfaceFactoryEgl::CreateSingleWindow()
{
struct fb_var_screeninfo fb_var;
int fb_fd = open("/dev/fb0", O_RDWR);
if(init_)
{
return true;
}
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_var)) {
LOG(FATAL) << "failed to get fb var info errno: " << errno;
g_width = 640;
g_height = 480;
} else {
g_width = fb_var.xres;
g_height = fb_var.yres;
}
close(fb_fd);
if(!ozone_egl_setup(0, 0, g_width, g_height))
{
LOG(FATAL) << "CreateSingleWindow";
return false;
}
init_ = true;
return true;
}
void SurfaceFactoryEgl::DestroySingleWindow() {
ozone_egl_destroy();
init_ = false;
}
SurfaceFactoryEgl::HardwareState
SurfaceFactoryEgl::InitializeHardware() {
return INITIALIZED;
}
void SurfaceFactoryEgl::ShutdownHardware() {
}
intptr_t SurfaceFactoryEgl::GetNativeDisplay() {
return (intptr_t)ozone_egl_getNativedisp();
}
gfx::AcceleratedWidget SurfaceFactoryEgl::GetAcceleratedWidget() {
if (!CreateSingleWindow())
LOG(FATAL) << "failed to create window";
return (gfx::AcceleratedWidget)GetNativeDisplay();
}
scoped_ptr<ui::SurfaceOzoneEGL>
SurfaceFactoryEgl::CreateEGLSurfaceForWidget(
gfx::AcceleratedWidget widget) {
return make_scoped_ptr<ui::SurfaceOzoneEGL>(
new OzoneEgl(widget));
}
bool SurfaceFactoryEgl::LoadEGLGLES2Bindings(
AddGLLibraryCallback add_gl_library,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
return false;
}
const int32* SurfaceFactoryEgl::GetEGLSurfaceProperties(
const int32* desired_list) {
return ozone_egl_getConfigAttribs();
}
scoped_ptr<ui::SurfaceOzoneCanvas> SurfaceFactoryEgl::CreateCanvasForWidget(
gfx::AcceleratedWidget widget){
scoped_ptr<EglOzoneCanvas> canvas(new EglOzoneCanvas());
return canvas.PassAs<ui::SurfaceOzoneCanvas>();
}
} // namespace ui