| OLD | NEW |
| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/gl/vsync_provider_win.h" | 24 #include "ui/gl/vsync_provider_win.h" |
| 25 | 25 |
| 26 namespace gl { | 26 namespace gl { |
| 27 namespace init { | 27 namespace init { |
| 28 | 28 |
| 29 std::vector<GLImplementation> GetAllowedGLImplementations() { | 29 std::vector<GLImplementation> GetAllowedGLImplementations() { |
| 30 std::vector<GLImplementation> impls; | 30 std::vector<GLImplementation> impls; |
| 31 impls.push_back(kGLImplementationEGLGLES2); | 31 impls.push_back(kGLImplementationEGLGLES2); |
| 32 impls.push_back(kGLImplementationDesktopGL); | 32 impls.push_back(kGLImplementationDesktopGL); |
| 33 impls.push_back(kGLImplementationOSMesaGL); | 33 impls.push_back(kGLImplementationOSMesaGL); |
| 34 impls.push_back(kGLImplementationSwiftShaderGL); |
| 34 return impls; | 35 return impls; |
| 35 } | 36 } |
| 36 | 37 |
| 37 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 38 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 38 switch (GetGLImplementation()) { | 39 switch (GetGLImplementation()) { |
| 39 case kGLImplementationDesktopGL: | 40 case kGLImplementationDesktopGL: |
| 40 return GetGLWindowSystemBindingInfoWGL(info); | 41 return GetGLWindowSystemBindingInfoWGL(info); |
| 41 case kGLImplementationEGLGLES2: | 42 case kGLImplementationEGLGLES2: |
| 42 return GetGLWindowSystemBindingInfoEGL(info); | 43 return GetGLWindowSystemBindingInfoEGL(info); |
| 43 default: | 44 default: |
| 44 return false; | 45 return false; |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, | 49 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, |
| 49 GLSurface* compatible_surface, | 50 GLSurface* compatible_surface, |
| 50 const GLContextAttribs& attribs) { | 51 const GLContextAttribs& attribs) { |
| 51 TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); | 52 TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); |
| 52 switch (GetGLImplementation()) { | 53 switch (GetGLImplementation()) { |
| 53 case kGLImplementationOSMesaGL: | 54 case kGLImplementationOSMesaGL: |
| 54 return InitializeGLContext(new GLContextOSMesa(share_group), | 55 return InitializeGLContext(new GLContextOSMesa(share_group), |
| 55 compatible_surface, attribs); | 56 compatible_surface, attribs); |
| 57 case kGLImplementationSwiftShaderGL: |
| 56 case kGLImplementationEGLGLES2: | 58 case kGLImplementationEGLGLES2: |
| 57 return InitializeGLContext(new GLContextEGL(share_group), | 59 return InitializeGLContext(new GLContextEGL(share_group), |
| 58 compatible_surface, attribs); | 60 compatible_surface, attribs); |
| 59 case kGLImplementationDesktopGL: | 61 case kGLImplementationDesktopGL: |
| 60 return InitializeGLContext(new GLContextWGL(share_group), | 62 return InitializeGLContext(new GLContextWGL(share_group), |
| 61 compatible_surface, attribs); | 63 compatible_surface, attribs); |
| 62 case kGLImplementationMockGL: | 64 case kGLImplementationMockGL: |
| 63 return new GLContextStub(share_group); | 65 return new GLContextStub(share_group); |
| 64 case kGLImplementationStubGL: { | 66 case kGLImplementationStubGL: { |
| 65 scoped_refptr<GLContextStub> stub_context = | 67 scoped_refptr<GLContextStub> stub_context = |
| 66 new GLContextStub(share_group); | 68 new GLContextStub(share_group); |
| 67 stub_context->SetUseStubApi(true); | 69 stub_context->SetUseStubApi(true); |
| 68 return stub_context; | 70 return stub_context; |
| 69 } | 71 } |
| 70 default: | 72 default: |
| 71 NOTREACHED(); | 73 NOTREACHED(); |
| 72 return nullptr; | 74 return nullptr; |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 76 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { | 78 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
| 77 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); | 79 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); |
| 78 switch (GetGLImplementation()) { | 80 switch (GetGLImplementation()) { |
| 79 case kGLImplementationOSMesaGL: | 81 case kGLImplementationOSMesaGL: |
| 80 return InitializeGLSurface(new GLSurfaceOSMesaWin(window)); | 82 return InitializeGLSurface(new GLSurfaceOSMesaWin(window)); |
| 83 case kGLImplementationSwiftShaderGL: |
| 81 case kGLImplementationEGLGLES2: { | 84 case kGLImplementationEGLGLES2: { |
| 82 DCHECK(window != gfx::kNullAcceleratedWidget); | 85 DCHECK(window != gfx::kNullAcceleratedWidget); |
| 83 scoped_refptr<NativeViewGLSurfaceEGL> surface( | 86 scoped_refptr<NativeViewGLSurfaceEGL> surface( |
| 84 new NativeViewGLSurfaceEGL(window)); | 87 new NativeViewGLSurfaceEGL(window)); |
| 85 std::unique_ptr<gfx::VSyncProvider> sync_provider; | 88 std::unique_ptr<gfx::VSyncProvider> sync_provider; |
| 86 sync_provider.reset(new VSyncProviderWin(window)); | 89 sync_provider.reset(new VSyncProviderWin(window)); |
| 87 if (!surface->Initialize(std::move(sync_provider))) | 90 if (!surface->Initialize(std::move(sync_provider))) |
| 88 return nullptr; | 91 return nullptr; |
| 89 | 92 |
| 90 return surface; | 93 return surface; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 101 } | 104 } |
| 102 | 105 |
| 103 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( | 106 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( |
| 104 const gfx::Size& size, GLSurfaceFormat format) { | 107 const gfx::Size& size, GLSurfaceFormat format) { |
| 105 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); | 108 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); |
| 106 switch (GetGLImplementation()) { | 109 switch (GetGLImplementation()) { |
| 107 case kGLImplementationOSMesaGL: | 110 case kGLImplementationOSMesaGL: |
| 108 format.SetDefaultPixelLayout(GLSurfaceFormat::PIXEL_LAYOUT_RGBA); | 111 format.SetDefaultPixelLayout(GLSurfaceFormat::PIXEL_LAYOUT_RGBA); |
| 109 return InitializeGLSurfaceWithFormat( | 112 return InitializeGLSurfaceWithFormat( |
| 110 new GLSurfaceOSMesa(format, size), format); | 113 new GLSurfaceOSMesa(format, size), format); |
| 114 case kGLImplementationSwiftShaderGL: |
| 111 case kGLImplementationEGLGLES2: | 115 case kGLImplementationEGLGLES2: |
| 112 return InitializeGLSurfaceWithFormat( | 116 return InitializeGLSurfaceWithFormat( |
| 113 new PbufferGLSurfaceEGL(size), format); | 117 new PbufferGLSurfaceEGL(size), format); |
| 114 case kGLImplementationDesktopGL: | 118 case kGLImplementationDesktopGL: |
| 115 return InitializeGLSurfaceWithFormat( | 119 return InitializeGLSurfaceWithFormat( |
| 116 new PbufferGLSurfaceWGL(size), format); | 120 new PbufferGLSurfaceWGL(size), format); |
| 117 case kGLImplementationMockGL: | 121 case kGLImplementationMockGL: |
| 118 case kGLImplementationStubGL: | 122 case kGLImplementationStubGL: |
| 119 return new GLSurfaceStub; | 123 return new GLSurfaceStub; |
| 120 default: | 124 default: |
| 121 NOTREACHED(); | 125 NOTREACHED(); |
| 122 return nullptr; | 126 return nullptr; |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 | 129 |
| 126 } // namespace init | 130 } // namespace init |
| 127 } // namespace gl | 131 } // namespace gl |
| OLD | NEW |