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

Side by Side Diff: ui/gl/gl_surface_egl.cc

Issue 13886018: Add a factory and defines for native Linux surfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 7 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/gl/gl_surface_egl.h ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_surface_egl.h" 5 #include "ui/gl/gl_surface_egl.h"
6 6
7 #if defined(OS_ANDROID) 7 #if defined(OS_ANDROID)
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #endif 9 #endif
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "ui/gl/egl_util.h" 15 #include "ui/gl/egl_util.h"
16 #include "ui/gl/gl_context.h" 16 #include "ui/gl/gl_context.h"
17 #include "ui/gl/gl_implementation.h"
18 #include "ui/gl/gl_surface_stub.h"
17 19
18 #if defined(USE_X11) 20 #if defined(USE_X11)
19 extern "C" { 21 extern "C" {
20 #include <X11/Xlib.h> 22 #include <X11/Xlib.h>
21 } 23 }
22 #endif 24 #endif
23 25
26 #if defined (USE_OZONE)
27 #include "ui/base/ozone/surface_factory_ozone.h"
28 #endif
29
24 using ui::GetLastEGLErrorString; 30 using ui::GetLastEGLErrorString;
25 31
26 namespace gfx { 32 namespace gfx {
27 33
28 namespace { 34 namespace {
29 35
30 EGLConfig g_config; 36 EGLConfig g_config;
31 EGLDisplay g_display; 37 EGLDisplay g_display;
32 EGLNativeDisplayType g_native_display; 38 EGLNativeDisplayType g_native_display;
33 EGLConfig g_software_config; 39 EGLConfig g_software_config;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 82
77 } // namespace 83 } // namespace
78 84
79 GLSurfaceEGL::GLSurfaceEGL() : software_(false) {} 85 GLSurfaceEGL::GLSurfaceEGL() : software_(false) {}
80 86
81 bool GLSurfaceEGL::InitializeOneOff() { 87 bool GLSurfaceEGL::InitializeOneOff() {
82 static bool initialized = false; 88 static bool initialized = false;
83 if (initialized) 89 if (initialized)
84 return true; 90 return true;
85 91
92 #if defined (USE_OZONE)
93 ui::SurfaceFactoryOzone::GetInstance()->InitializeHardware();
94 #endif
95
86 #if defined(USE_X11) 96 #if defined(USE_X11)
87 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay(); 97 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay();
88 #else 98 #else
89 g_native_display = EGL_DEFAULT_DISPLAY; 99 g_native_display = EGL_DEFAULT_DISPLAY;
90 #endif 100 #endif
91 g_display = eglGetDisplay(g_native_display); 101 g_display = eglGetDisplay(g_native_display);
92 if (!g_display) { 102 if (!g_display) {
93 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); 103 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString();
94 return false; 104 return false;
95 } 105 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 149 }
140 150
141 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); 151 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS);
142 g_egl_create_context_robustness_supported = 152 g_egl_create_context_robustness_supported =
143 HasEGLExtension("EGL_EXT_create_context_robustness"); 153 HasEGLExtension("EGL_EXT_create_context_robustness");
144 g_egl_sync_control_supported = 154 g_egl_sync_control_supported =
145 HasEGLExtension("EGL_CHROMIUM_sync_control"); 155 HasEGLExtension("EGL_CHROMIUM_sync_control");
146 156
147 initialized = true; 157 initialized = true;
148 158
149 #if defined(USE_X11) || defined(OS_ANDROID) 159 #if defined(USE_X11) || defined(OS_ANDROID) \
160 || defined(USE_OZONE)
150 return true; 161 return true;
151 #else 162 #else
152 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; 163 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE;
153 #endif 164 #endif
154 g_software_display = eglGetDisplay(g_software_native_display); 165 g_software_display = eglGetDisplay(g_software_native_display);
155 if (!g_software_display) { 166 if (!g_software_display) {
156 return true; 167 return true;
157 } 168 }
158 169
159 if (!eglInitialize(g_software_display, NULL, NULL)) { 170 if (!eglInitialize(g_software_display, NULL, NULL)) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 supports_post_sub_buffer_(false), 234 supports_post_sub_buffer_(false),
224 config_(NULL) { 235 config_(NULL) {
225 software_ = software; 236 software_ = software;
226 #if defined(OS_ANDROID) 237 #if defined(OS_ANDROID)
227 if (window) 238 if (window)
228 ANativeWindow_acquire(window); 239 ANativeWindow_acquire(window);
229 #endif 240 #endif
230 } 241 }
231 242
232 bool NativeViewGLSurfaceEGL::Initialize() { 243 bool NativeViewGLSurfaceEGL::Initialize() {
244 return Initialize(NULL);
245 }
246
247 bool NativeViewGLSurfaceEGL::Initialize(VSyncProvider* sync_provider) {
233 DCHECK(!surface_); 248 DCHECK(!surface_);
234 249
235 if (window_ == kNullAcceleratedWidget) { 250 if (window_ == kNullAcceleratedWidget) {
236 LOG(ERROR) << "Trying to create surface without window."; 251 LOG(ERROR) << "Trying to create surface without window.";
237 return false; 252 return false;
238 } 253 }
239 254
240 if (!GetDisplay()) { 255 if (!GetDisplay()) {
241 LOG(ERROR) << "Trying to create surface with invalid display."; 256 LOG(ERROR) << "Trying to create surface with invalid display.";
242 return false; 257 return false;
(...skipping 20 matching lines...) Expand all
263 return false; 278 return false;
264 } 279 }
265 280
266 EGLint surfaceVal; 281 EGLint surfaceVal;
267 EGLBoolean retVal = eglQuerySurface(GetDisplay(), 282 EGLBoolean retVal = eglQuerySurface(GetDisplay(),
268 surface_, 283 surface_,
269 EGL_POST_SUB_BUFFER_SUPPORTED_NV, 284 EGL_POST_SUB_BUFFER_SUPPORTED_NV,
270 &surfaceVal); 285 &surfaceVal);
271 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; 286 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE;
272 287
273 if (g_egl_sync_control_supported) 288 if (sync_provider)
289 vsync_provider_.reset(sync_provider);
290 else if (g_egl_sync_control_supported)
274 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_)); 291 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_));
275
276 return true; 292 return true;
277 } 293 }
278 294
279 void NativeViewGLSurfaceEGL::Destroy() { 295 void NativeViewGLSurfaceEGL::Destroy() {
280 if (surface_) { 296 if (surface_) {
281 if (!eglDestroySurface(GetDisplay(), surface_)) { 297 if (!eglDestroySurface(GetDisplay(), surface_)) {
282 LOG(ERROR) << "eglDestroySurface failed with error " 298 LOG(ERROR) << "eglDestroySurface failed with error "
283 << GetLastEGLErrorString(); 299 << GetLastEGLErrorString();
284 } 300 }
285 surface_ = NULL; 301 surface_ = NULL;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 594 }
579 595
580 return handle; 596 return handle;
581 #endif 597 #endif
582 } 598 }
583 599
584 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { 600 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
585 Destroy(); 601 Destroy();
586 } 602 }
587 603
604 #if defined(ANDROID) || defined(USE_OZONE)
605
606 // static
607 bool GLSurface::InitializeOneOffInternal() {
608 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
609
610 if (!GLSurfaceEGL::InitializeOneOff()) {
611 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
612 return false;
613 }
614 return true;
615 }
616
617 // static
618 scoped_refptr<GLSurface>
619 GLSurface::CreateViewGLSurface(bool software, gfx::AcceleratedWidget window) {
620 if (software)
621 return NULL;
622
623 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
624 if (window) {
625 scoped_refptr<NativeViewGLSurfaceEGL> surface;
626 VSyncProvider* sync_provider = NULL;
627 #if defined(USE_OZONE)
628 window = ui::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget(
629 window));
630 sync_provider =
631 ui::SurfaceFactoryOzone::GetInstance()->GetVSyncProvider(window);
632 #endif
633 surface = new NativeViewGLSurfaceEGL(false, window);
634 if(surface->Initialize(sync_provider))
635 return surface;
636 } else {
637 scoped_refptr<GLSurface> surface = new GLSurfaceStub();
638 if (surface->Initialize())
639 return surface;
640 }
641 return NULL;
642 }
643
644 // static
645 scoped_refptr<GLSurface>
646 GLSurface::CreateOffscreenGLSurface(bool software, const gfx::Size& size) {
647 if (software)
648 return NULL;
649
650 switch (GetGLImplementation()) {
651 case kGLImplementationEGLGLES2: {
652 scoped_refptr<PbufferGLSurfaceEGL> surface(
653 new PbufferGLSurfaceEGL(false, size));
654 if (!surface->Initialize())
655 return NULL;
656 return surface;
657 }
658 default:
659 NOTREACHED();
660 return NULL;
661 }
662 }
663
664 #endif
665
588 } // namespace gfx 666 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698