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

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

Issue 7467007: Adding Wayland support for ui/gfx (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Replaced the way WaylandDisplay is being retrieved Created 9 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/gfx/gl/egl_util.h"
10 #include "ui/gfx/gl/gl_bindings.h"
11 #include "ui/gfx/gl/gl_implementation.h"
12 #include "ui/gfx/gl/gl_surface_egl.h"
13
14 #include "ui/wayland/wayland_display.h"
15
16 #include <wayland-egl.h>
17
18 namespace {
19
20 // Encapsulates a pixmap EGL surface.
21 class PixmapGLSurfaceEGL : public gfx::GLSurfaceEGL {
22 public:
23 explicit PixmapGLSurfaceEGL(const gfx::Size& size);
24 virtual ~PixmapGLSurfaceEGL();
25
26 // Implement GLSurface.
27 virtual bool Initialize();
28 virtual void Destroy();
29 virtual bool IsOffscreen();
30 virtual bool SwapBuffers();
31 virtual gfx::Size GetSize();
32 virtual EGLSurface GetHandle();
33
34 private:
35 gfx::Size size_;
36 EGLSurface surface_;
37 EGLNativePixmapType pixmap_;
38
39 DISALLOW_COPY_AND_ASSIGN(PixmapGLSurfaceEGL);
40 };
41
42 PixmapGLSurfaceEGL::PixmapGLSurfaceEGL(const gfx::Size& size)
43 : size_(size),
44 surface_(NULL),
45 pixmap_(NULL) {
46 }
47
48 PixmapGLSurfaceEGL::~PixmapGLSurfaceEGL() {
49 Destroy();
50 }
51
52 bool PixmapGLSurfaceEGL::Initialize() {
53 DCHECK(!surface_);
54 DCHECK(!pixmap_);
55
56 pixmap_ = wl_egl_pixmap_create(
57 size_.width(),
58 size_.height(),
59 WaylandDisplay::GetDisplay(
60 GLSurfaceEGL::GetNativeDisplay())->GetVisual(),
61 0);
62 surface_ = eglCreatePixmapSurface(gfx::GLSurfaceEGL::GetDisplay(),
63 gfx::GLSurfaceEGL::GetConfig(),
64 pixmap_,
65 NULL);
66 if (!surface_) {
67 LOG(ERROR) << "eglCreatePixmapSurface failed with error "
68 << gfx::GetLastEGLErrorString();
69 Destroy();
70 return false;
71 }
72
73 return true;
74 }
75
76 void PixmapGLSurfaceEGL::Destroy() {
77 if (surface_) {
78 if (!eglDestroySurface(gfx::GLSurfaceEGL::GetDisplay(), surface_)) {
79 LOG(ERROR) << "eglDestroySurface failed with error "
80 << gfx::GetLastEGLErrorString();
81 }
82 surface_ = NULL;
83 }
84 if (pixmap_) {
85 wl_egl_pixmap_destroy(pixmap_);
86 pixmap_ = NULL;
87 }
88 }
89
90 bool PixmapGLSurfaceEGL::IsOffscreen() {
91 return true;
92 }
93
94 bool PixmapGLSurfaceEGL::SwapBuffers() {
95 NOTREACHED() << "Attempted to call SwapBuffers on a PixmapGLSurfaceEGL.";
96 return false;
97 }
98
99 gfx::Size PixmapGLSurfaceEGL::GetSize() {
100 return size_;
101 }
102
103 EGLSurface PixmapGLSurfaceEGL::GetHandle() {
104 return surface_;
105 }
106
107 }
108
109 namespace gfx {
110
111 bool GLSurface::InitializeOneOff() {
112 static bool initialized = false;
113 if (initialized) {
114 return true;
115 }
116
117 static const GLImplementation kAllowedGLImplementations[] = {
118 kGLImplementationEGLGLES2
119 };
120
121 if (!InitializeRequestedGLBindings(
122 kAllowedGLImplementations,
123 kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
124 kGLImplementationEGLGLES2)) {
125 LOG(ERROR) << "InitializeRequestedGLBindings failed.";
126 return false;
127 }
128
129 if (!GLSurfaceEGL::InitializeOneOff()) {
130 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
131 return false;
132 }
133
134 initialized = true;
135 return true;
136 }
137
138 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
139 gfx::PluginWindowHandle window) {
140
141 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL(window));
142 if (!surface->Initialize()) {
143 return NULL;
144 }
145
146 return surface;
147 }
148
149 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
150 const gfx::Size& size) {
151 scoped_refptr<GLSurface> surface(new PixmapGLSurfaceEGL(size));
152 if (!surface->Initialize()) {
153 return NULL;
154 }
155
156 return surface;
157 }
158
159 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698