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

Side by Side Diff: ui/gl/init/gl_factory_ozone.cc

Issue 2156503003: Have Ozone X11 directly create GLSurfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_ozone_gl
Patch Set: Rebase. Created 4 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
« no previous file with comments | « ui/gl/init/OWNERS ('k') | ui/ozone/platform/x11/BUILD.gn » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/init/gl_factory.h" 5 #include "ui/gl/init/gl_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "ui/gl/gl_context.h" 9 #include "ui/gl/gl_context.h"
10 #include "ui/gl/gl_context_egl.h" 10 #include "ui/gl/gl_context_egl.h"
11 #include "ui/gl/gl_context_osmesa.h" 11 #include "ui/gl/gl_context_osmesa.h"
12 #include "ui/gl/gl_context_stub.h" 12 #include "ui/gl/gl_context_stub.h"
13 #include "ui/gl/gl_implementation.h" 13 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_share_group.h" 14 #include "ui/gl/gl_share_group.h"
15 #include "ui/gl/gl_surface.h" 15 #include "ui/gl/gl_surface.h"
16 #include "ui/gl/gl_surface_egl.h" 16 #include "ui/gl/gl_surface_egl.h"
17 #include "ui/gl/gl_surface_osmesa.h" 17 #include "ui/gl/gl_surface_osmesa.h"
18 #include "ui/gl/gl_surface_stub.h" 18 #include "ui/gl/gl_surface_stub.h"
19 #include "ui/gl/init/gl_surface_ozone.h" 19 #include "ui/gl/init/gl_surface_ozone.h"
20 #include "ui/ozone/public/ozone_platform.h" 20 #include "ui/ozone/public/ozone_platform.h"
21 #include "ui/ozone/public/surface_factory_ozone.h" 21 #include "ui/ozone/public/surface_factory_ozone.h"
22 #include "ui/ozone/public/surface_ozone_egl.h" 22 #include "ui/ozone/public/surface_ozone_egl.h"
23 23
24 namespace gl { 24 namespace gl {
25 namespace init { 25 namespace init {
26 26
27 namespace {
28
29 ui::SurfaceFactoryOzone* GetSurfaceFactory() {
30 return ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
31 }
32
33 bool HasDefaultImplementation(GLImplementation impl) {
34 return impl == kGLImplementationOSMesaGL || impl == kGLImplementationMockGL;
35 }
36
37 scoped_refptr<GLSurface> CreateDefaultViewGLSurface(
38 gfx::AcceleratedWidget window) {
39 switch (GetGLImplementation()) {
40 case kGLImplementationOSMesaGL:
41 return InitializeGLSurface(new GLSurfaceOSMesaHeadless());
42 case kGLImplementationMockGL:
43 return InitializeGLSurface(new GLSurfaceStub());
44 default:
45 NOTREACHED();
46 }
47 return nullptr;
48 }
49
50 scoped_refptr<GLSurface> CreateDefaultOffscreenGLSurface(
51 const gfx::Size& size) {
52 switch (GetGLImplementation()) {
53 case kGLImplementationOSMesaGL:
54 return InitializeGLSurface(
55 new GLSurfaceOSMesa(GLSurface::SURFACE_OSMESA_BGRA, size));
56 case kGLImplementationMockGL:
57 return InitializeGLSurface(new GLSurfaceStub);
58 default:
59 NOTREACHED();
60 }
61 return nullptr;
62 }
63
64 // TODO(kylechar): Remove when all implementations are switched over.
65 scoped_refptr<GLSurface> CreateViewGLSurfaceOld(gfx::AcceleratedWidget window) {
66 switch (GetGLImplementation()) {
67 case kGLImplementationEGLGLES2: {
68 DCHECK_NE(window, gfx::kNullAcceleratedWidget);
69 scoped_refptr<GLSurface> surface;
70 if (!surface && GLSurfaceEGL::IsEGLSurfacelessContextSupported())
71 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window);
72 if (!surface)
73 surface = CreateViewGLSurfaceOzone(window);
74 return surface;
75 }
76 default:
77 NOTREACHED();
78 return nullptr;
79 }
80 }
81
82 // TODO(kylechar): Remove when all implementations are switched over.
83 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceOld(const gfx::Size& size) {
84 switch (GetGLImplementation()) {
85 case kGLImplementationEGLGLES2:
86 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
87 (size.width() == 0 && size.height() == 0)) {
88 return InitializeGLSurface(new SurfacelessEGL(size));
89 } else {
90 return InitializeGLSurface(new PbufferGLSurfaceEGL(size));
91 }
92 default:
93 NOTREACHED();
94 }
95 return nullptr;
96 }
97
98 } // namespace
99
27 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, 100 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group,
28 GLSurface* compatible_surface, 101 GLSurface* compatible_surface,
29 GpuPreference gpu_preference) { 102 GpuPreference gpu_preference) {
30 TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); 103 TRACE_EVENT0("gpu", "gl::init::CreateGLContext");
31 switch (GetGLImplementation()) { 104 switch (GetGLImplementation()) {
32 case kGLImplementationMockGL: 105 case kGLImplementationMockGL:
33 return scoped_refptr<GLContext>(new GLContextStub(share_group)); 106 return scoped_refptr<GLContext>(new GLContextStub(share_group));
34 case kGLImplementationOSMesaGL: 107 case kGLImplementationOSMesaGL:
35 return InitializeGLContext(new GLContextOSMesa(share_group), 108 return InitializeGLContext(new GLContextOSMesa(share_group),
36 compatible_surface, gpu_preference); 109 compatible_surface, gpu_preference);
37 case kGLImplementationEGLGLES2: 110 case kGLImplementationEGLGLES2:
38 return InitializeGLContext(new GLContextEGL(share_group), 111 return InitializeGLContext(new GLContextEGL(share_group),
39 compatible_surface, gpu_preference); 112 compatible_surface, gpu_preference);
40 113
41 default: 114 default:
42 NOTREACHED(); 115 NOTREACHED();
43 return nullptr; 116 return nullptr;
44 } 117 }
45 } 118 }
46 119
47 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { 120 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) {
48 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); 121 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface");
49 switch (GetGLImplementation()) { 122
50 case kGLImplementationOSMesaGL: 123 if (HasDefaultImplementation(GetGLImplementation()))
51 return InitializeGLSurface(new GLSurfaceOSMesaHeadless()); 124 return CreateDefaultViewGLSurface(window);
52 case kGLImplementationEGLGLES2: { 125
53 DCHECK_NE(window, gfx::kNullAcceleratedWidget); 126 // TODO(kylechar): This is deprecated, remove when possible.
54 scoped_refptr<GLSurface> surface; 127 if (!GetSurfaceFactory()->UseNewSurfaceAPI())
55 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) 128 return CreateViewGLSurfaceOld(window);
56 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); 129
57 if (!surface) 130 return GetSurfaceFactory()->CreateViewGLSurface(GetGLImplementation(),
58 surface = CreateViewGLSurfaceOzone(window); 131 window);
59 return surface;
60 }
61 case kGLImplementationMockGL:
62 return InitializeGLSurface(new GLSurfaceStub());
63 default:
64 NOTREACHED();
65 return nullptr;
66 }
67 } 132 }
68 133
134 // TODO(kylechar): Update to use new API.
69 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( 135 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface(
70 gfx::AcceleratedWidget window) { 136 gfx::AcceleratedWidget window) {
71 TRACE_EVENT0("gpu", "gl::init::CreateSurfacelessViewGLSurface"); 137 TRACE_EVENT0("gpu", "gl::init::CreateSurfacelessViewGLSurface");
72 if (GetGLImplementation() == kGLImplementationEGLGLES2 && 138 if (GetGLImplementation() == kGLImplementationEGLGLES2 &&
73 window != gfx::kNullAcceleratedWidget && 139 window != gfx::kNullAcceleratedWidget &&
74 GLSurfaceEGL::IsEGLSurfacelessContextSupported()) { 140 GLSurfaceEGL::IsEGLSurfacelessContextSupported()) {
75 return CreateViewGLSurfaceOzoneSurfaceless(window); 141 return CreateViewGLSurfaceOzoneSurfaceless(window);
76 } 142 }
77 return nullptr; 143 return nullptr;
78 } 144 }
79 145
80 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { 146 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) {
81 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); 147 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface");
82 switch (GetGLImplementation()) { 148
83 case kGLImplementationOSMesaGL: 149 if (HasDefaultImplementation(GetGLImplementation()))
84 return InitializeGLSurface( 150 return CreateDefaultOffscreenGLSurface(size);
85 new GLSurfaceOSMesa(GLSurface::SURFACE_OSMESA_BGRA, size)); 151
86 case kGLImplementationEGLGLES2: 152 // TODO(kylechar): This is deprecated, remove when possible.
87 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && 153 if (!GetSurfaceFactory()->UseNewSurfaceAPI())
88 (size.width() == 0 && size.height() == 0)) { 154 return CreateOffscreenGLSurfaceOld(size);
89 return InitializeGLSurface(new SurfacelessEGL(size)); 155
90 } else { 156 return GetSurfaceFactory()->CreateOffscreenGLSurface(GetGLImplementation(),
91 return InitializeGLSurface(new PbufferGLSurfaceEGL(size)); 157 size);
92 }
93 case kGLImplementationMockGL:
94 return new GLSurfaceStub;
95 default:
96 NOTREACHED();
97 return nullptr;
98 }
99 } 158 }
100 159
101 } // namespace init 160 } // namespace init
102 } // namespace gl 161 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/init/OWNERS ('k') | ui/ozone/platform/x11/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698