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

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: Adding missing WaylandDisplay include Created 9 years, 4 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_surface_egl.cc ('k') | ui/gfx/gtk_util.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) 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 <wayland-egl.h>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/gfx/gl/egl_util.h"
12 #include "ui/gfx/gl/gl_bindings.h"
13 #include "ui/gfx/gl/gl_implementation.h"
14 #include "ui/gfx/gl/gl_surface_egl.h"
15 #include "ui/wayland/wayland_display.h"
16
17 namespace {
18
19 // Encapsulates a pixmap EGL surface.
20 class PixmapGLSurfaceEGL : public gfx::GLSurfaceEGL {
21 public:
22 explicit PixmapGLSurfaceEGL(bool software, const gfx::Size& size);
23 virtual ~PixmapGLSurfaceEGL();
24
25 // Implement GLSurface.
26 virtual bool Initialize();
27 virtual void Destroy();
28 virtual bool IsOffscreen();
29 virtual bool SwapBuffers();
30 virtual gfx::Size GetSize();
31 virtual EGLSurface GetHandle();
32
33 private:
34 gfx::Size size_;
35 EGLSurface surface_;
36 EGLNativePixmapType pixmap_;
37
38 DISALLOW_COPY_AND_ASSIGN(PixmapGLSurfaceEGL);
39 };
40
41 PixmapGLSurfaceEGL::PixmapGLSurfaceEGL(bool software, const gfx::Size& size)
42 : size_(size),
43 surface_(NULL),
44 pixmap_(NULL) {
45 software_ = software;
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 ui::WaylandDisplay::GetDisplay(
60 GLSurfaceEGL::GetNativeDisplay())->visual(),
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 static const GLImplementation kAllowedGLImplementations[] = {
117 kGLImplementationEGLGLES2
118 };
119
120 if (!InitializeRequestedGLBindings(
121 kAllowedGLImplementations,
122 kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
123 kGLImplementationEGLGLES2)) {
124 LOG(ERROR) << "InitializeRequestedGLBindings failed.";
125 return false;
126 }
127
128 if (!GLSurfaceEGL::InitializeOneOff()) {
129 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
130 return false;
131 }
132
133 initialized = true;
134 return true;
135 }
136
137 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
138 bool software,
139 gfx::PluginWindowHandle window) {
140
141 if (software)
142 return NULL;
143
144 scoped_refptr<GLSurface> surface(
145 new NativeViewGLSurfaceEGL(software, window));
146 if (!surface->Initialize())
147 return NULL;
148
149 return surface;
150 }
151
152 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
153 bool software,
154 const gfx::Size& size) {
155 if (software)
156 return NULL;
157
158 scoped_refptr<GLSurface> surface(new PixmapGLSurfaceEGL(software, size));
159 if (!surface->Initialize())
160 return NULL;
161
162 return surface;
163 }
164
165 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_surface_egl.cc ('k') | ui/gfx/gtk_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698