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

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

Issue 196403008: gl: Move platform-specific EGL code into separate files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
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 // This include must be here so that the includes provided transitively 5 // This include must be here so that the includes provided transitively
6 // by gl_surface_egl.h don't make it impossible to compile this code. 6 // by gl_surface_egl.h don't make it impossible to compile this code.
7 #include "third_party/mesa/src/include/GL/osmesa.h" 7 #include "third_party/mesa/src/include/GL/osmesa.h"
8 8
9 #include "ui/gl/gl_surface_egl.h" 9 #include "ui/gl/gl_surface_egl.h"
10 10
(...skipping 20 matching lines...) Expand all
31 #if defined(USE_X11) 31 #if defined(USE_X11)
32 extern "C" { 32 extern "C" {
33 #include <X11/Xlib.h> 33 #include <X11/Xlib.h>
34 } 34 }
35 #endif 35 #endif
36 36
37 #if defined (USE_OZONE) 37 #if defined (USE_OZONE)
38 #include "ui/gfx/ozone/surface_factory_ozone.h" 38 #include "ui/gfx/ozone/surface_factory_ozone.h"
39 #endif 39 #endif
40 40
41 // From ANGLE's egl/eglext.h.
42 #if !defined(EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE)
43 #define EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE \
44 reinterpret_cast<EGLNativeDisplayType>(-2)
45 #endif
46 #if !defined(EGL_FIXED_SIZE_ANGLE) 41 #if !defined(EGL_FIXED_SIZE_ANGLE)
47 #define EGL_FIXED_SIZE_ANGLE 0x3201 42 #define EGL_FIXED_SIZE_ANGLE 0x3201
48 #endif 43 #endif
49 44
50 using ui::GetLastEGLErrorString; 45 using ui::GetLastEGLErrorString;
51 46
52 namespace gfx { 47 namespace gfx {
53 48
54 namespace { 49 namespace {
55 50
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 LOG(ERROR) << "No suitable EGL configs found."; 110 LOG(ERROR) << "No suitable EGL configs found.";
116 return false; 111 return false;
117 } 112 }
118 return true; 113 return true;
119 } 114 }
120 115
121 } // namespace 116 } // namespace
122 117
123 GLSurfaceEGL::GLSurfaceEGL() {} 118 GLSurfaceEGL::GLSurfaceEGL() {}
124 119
125 bool GLSurfaceEGL::InitializeOneOff() { 120 bool GLSurfaceEGL::InitializeOneOff(EGLNativeDisplayType native_display) {
rjkroege 2014/03/24 15:27:25 I like this transformation of pulling the platform
spang 2014/03/24 18:17:08 Per our discussion, I added GetPlatformDefaultEGLD
126 static bool initialized = false; 121 static bool initialized = false;
127 if (initialized) 122 if (initialized)
128 return true; 123 return true;
129 124
130 #if defined(USE_X11) 125 g_native_display = native_display;
131 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay();
132 #elif defined(OS_WIN)
133 g_native_display = EGL_DEFAULT_DISPLAY;
134 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) &&
135 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableD3D11)) {
136 g_native_display = EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE;
137 }
138 #elif defined(USE_OZONE)
139 gfx::SurfaceFactoryOzone* surface_factory =
140 gfx::SurfaceFactoryOzone::GetInstance();
141 if (surface_factory->InitializeHardware() !=
142 gfx::SurfaceFactoryOzone::INITIALIZED) {
143 LOG(ERROR) << "OZONE failed to initialize hardware";
144 return false;
145 }
146 g_native_display = surface_factory->GetNativeDisplay();
147 #else
148 g_native_display = EGL_DEFAULT_DISPLAY;
149 #endif
150 g_display = eglGetDisplay(g_native_display); 126 g_display = eglGetDisplay(g_native_display);
151 if (!g_display) { 127 if (!g_display) {
152 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); 128 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString();
153 return false; 129 return false;
154 } 130 }
155 131
156 if (!eglInitialize(g_display, NULL, NULL)) { 132 if (!eglInitialize(g_display, NULL, NULL)) {
157 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); 133 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString();
158 return false; 134 return false;
159 } 135 }
(...skipping 25 matching lines...) Expand all
185 EGLint* choose_attributes = config_attribs_8888; 161 EGLint* choose_attributes = config_attribs_8888;
186 162
187 #if defined(OS_ANDROID) 163 #if defined(OS_ANDROID)
188 if (base::android::SysUtils::IsLowEndDevice()) { 164 if (base::android::SysUtils::IsLowEndDevice()) {
189 choose_attributes = config_attribs_565; 165 choose_attributes = config_attribs_565;
190 } 166 }
191 #endif 167 #endif
192 168
193 #if defined(USE_OZONE) 169 #if defined(USE_OZONE)
194 const EGLint* config_attribs = 170 const EGLint* config_attribs =
195 surface_factory->GetEGLSurfaceProperties(choose_attributes); 171 SurfaceFactoryOzone::GetInstance()->GetEGLSurfaceProperties(
172 choose_attributes);
196 #else 173 #else
197 const EGLint* config_attribs = choose_attributes; 174 const EGLint* config_attribs = choose_attributes;
198 #endif 175 #endif
199 176
200 EGLint num_configs; 177 EGLint num_configs;
201 EGLint config_size = 1; 178 EGLint config_size = 1;
202 EGLConfig* config_data = &g_config; 179 EGLConfig* config_data = &g_config;
203 // Validate if there are any configs for given atrribs. 180 // Validate if there are any configs for given atrribs.
204 if (!ValidateEglConfig(g_display, 181 if (!ValidateEglConfig(g_display,
205 config_attribs, 182 config_attribs,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 298 }
322 299
323 bool GLSurfaceEGL::HasEGLExtension(const char* name) { 300 bool GLSurfaceEGL::HasEGLExtension(const char* name) {
324 return ExtensionsContain(GetEGLExtensions(), name); 301 return ExtensionsContain(GetEGLExtensions(), name);
325 } 302 }
326 303
327 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { 304 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() {
328 return g_egl_create_context_robustness_supported; 305 return g_egl_create_context_robustness_supported;
329 } 306 }
330 307
308 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() {
309 return g_egl_surfaceless_context_supported;
310 }
311
331 GLSurfaceEGL::~GLSurfaceEGL() {} 312 GLSurfaceEGL::~GLSurfaceEGL() {}
332 313
333 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) 314 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window)
334 : window_(window), 315 : window_(window),
335 surface_(NULL), 316 surface_(NULL),
336 supports_post_sub_buffer_(false), 317 supports_post_sub_buffer_(false),
337 config_(NULL), 318 config_(NULL),
338 size_(1, 1) { 319 size_(1, 1) {
339 #if defined(OS_ANDROID) 320 #if defined(OS_ANDROID)
340 if (window) 321 if (window)
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 return EGL_NO_SURFACE; 735 return EGL_NO_SURFACE;
755 } 736 }
756 737
757 void* SurfacelessEGL::GetShareHandle() { 738 void* SurfacelessEGL::GetShareHandle() {
758 return NULL; 739 return NULL;
759 } 740 }
760 741
761 SurfacelessEGL::~SurfacelessEGL() { 742 SurfacelessEGL::~SurfacelessEGL() {
762 } 743 }
763 744
764 #if defined(ANDROID) || defined(USE_OZONE)
765
766 // A thin subclass of |GLSurfaceOSMesa| that can be used in place
767 // of a native hardware-provided surface when a native surface
768 // provider is not available.
769 class GLSurfaceOSMesaHeadless : public GLSurfaceOSMesa {
770 public:
771 explicit GLSurfaceOSMesaHeadless();
772
773 virtual bool IsOffscreen() OVERRIDE;
774 virtual bool SwapBuffers() OVERRIDE;
775
776 protected:
777 virtual ~GLSurfaceOSMesaHeadless();
778
779 private:
780
781 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOSMesaHeadless);
782 };
783
784 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; }
785
786 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; }
787
788 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless()
789 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)) {}
790
791 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); }
792
793 // static
794 bool GLSurface::InitializeOneOffInternal() {
795 switch (GetGLImplementation()) {
796 case kGLImplementationEGLGLES2:
797 if (!GLSurfaceEGL::InitializeOneOff()) {
798 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
799 return false;
800 }
801 default:
802 break;
803 }
804 return true;
805 }
806
807 // static
808 scoped_refptr<GLSurface>
809 GLSurface::CreateViewGLSurface(gfx::AcceleratedWidget window) {
810
811 if (GetGLImplementation() == kGLImplementationOSMesaGL) {
812 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless());
813 if (!surface->Initialize())
814 return NULL;
815 return surface;
816 }
817 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
818 if (window != kNullAcceleratedWidget) {
819 EGLNativeWindowType egl_window;
820 scoped_refptr<NativeViewGLSurfaceEGL> surface;
821 scoped_ptr<VSyncProvider> sync_provider;
822 #if defined(USE_OZONE)
823 egl_window =
824 gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget(
825 window);
826 sync_provider =
827 gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider(
828 egl_window);
829 #else
830 egl_window = window;
831 #endif
832 surface = new NativeViewGLSurfaceEGL(egl_window);
833 if(surface->Initialize(sync_provider.Pass()))
834 return surface;
835 } else {
836 scoped_refptr<GLSurface> surface = new GLSurfaceStub();
837 if (surface->Initialize())
838 return surface;
839 }
840 return NULL;
841 }
842
843 // static
844 scoped_refptr<GLSurface>
845 GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) {
846 switch (GetGLImplementation()) {
847 case kGLImplementationOSMesaGL: {
848 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size));
849 if (!surface->Initialize())
850 return NULL;
851
852 return surface;
853 }
854 case kGLImplementationEGLGLES2: {
855 scoped_refptr<GLSurface> surface;
856 if (g_egl_surfaceless_context_supported &&
857 (size.width() == 0 && size.height() == 0)) {
858 surface = new SurfacelessEGL(size);
859 } else
860 surface = new PbufferGLSurfaceEGL(size);
861
862 if (!surface->Initialize())
863 return NULL;
864 return surface;
865 }
866 default:
867 NOTREACHED();
868 return NULL;
869 }
870 }
871
872 #endif
873
874 } // namespace gfx 745 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698