| OLD | NEW |
| 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.h" | 5 #include "ui/gl/gl_surface.h" |
| 6 | 6 |
| 7 #include <OpenGL/CGLRenderers.h> | |
| 8 | |
| 9 #include <memory> | 7 #include <memory> |
| 10 | 8 |
| 11 #include "base/logging.h" | 9 #include "base/logging.h" |
| 12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 13 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 14 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
| 15 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 16 #include "ui/gl/gl_export.h" | 14 #include "ui/gl/gl_export.h" |
| 17 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
| 18 #include "ui/gl/gl_surface_osmesa.h" | 16 #include "ui/gl/gl_surface_osmesa.h" |
| 19 #include "ui/gl/gl_surface_stub.h" | 17 #include "ui/gl/gl_surface_stub.h" |
| 20 #include "ui/gl/gpu_switching_manager.h" | |
| 21 | 18 |
| 22 namespace gl { | 19 namespace gl { |
| 23 namespace { | 20 namespace { |
| 24 | 21 |
| 25 // A "no-op" surface. It is not required that a CGLContextObj have an | 22 // A "no-op" surface. It is not required that a CGLContextObj have an |
| 26 // associated drawable (pbuffer or fullscreen context) in order to be | 23 // associated drawable (pbuffer or fullscreen context) in order to be |
| 27 // made current. Everywhere this surface type is used, we allocate an | 24 // made current. Everywhere this surface type is used, we allocate an |
| 28 // FBO at the user level as the drawable of the associated context. | 25 // FBO at the user level as the drawable of the associated context. |
| 29 class GL_EXPORT NoOpGLSurface : public GLSurface { | 26 class GL_EXPORT NoOpGLSurface : public GLSurface { |
| 30 public: | 27 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 | 42 |
| 46 protected: | 43 protected: |
| 47 ~NoOpGLSurface() override {} | 44 ~NoOpGLSurface() override {} |
| 48 | 45 |
| 49 private: | 46 private: |
| 50 gfx::Size size_; | 47 gfx::Size size_; |
| 51 | 48 |
| 52 DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface); | 49 DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface); |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 // static | |
| 56 bool InitializeOneOffForSandbox() { | |
| 57 static bool initialized = false; | |
| 58 if (initialized) | |
| 59 return true; | |
| 60 | |
| 61 // This is called from the sandbox warmup code on Mac OS X. | |
| 62 // GPU-related stuff is very slow without this, probably because | |
| 63 // the sandbox prevents loading graphics drivers or some such. | |
| 64 std::vector<CGLPixelFormatAttribute> attribs; | |
| 65 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { | |
| 66 // Avoid switching to the discrete GPU just for this pixel | |
| 67 // format selection. | |
| 68 attribs.push_back(kCGLPFAAllowOfflineRenderers); | |
| 69 } | |
| 70 if (GetGLImplementation() == kGLImplementationAppleGL) { | |
| 71 attribs.push_back(kCGLPFARendererID); | |
| 72 attribs.push_back(static_cast<CGLPixelFormatAttribute>( | |
| 73 kCGLRendererGenericFloatID)); | |
| 74 } | |
| 75 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); | |
| 76 | |
| 77 CGLPixelFormatObj format; | |
| 78 GLint num_pixel_formats; | |
| 79 if (CGLChoosePixelFormat(&attribs.front(), | |
| 80 &format, | |
| 81 &num_pixel_formats) != kCGLNoError) { | |
| 82 LOG(ERROR) << "Error choosing pixel format."; | |
| 83 return false; | |
| 84 } | |
| 85 if (!format) { | |
| 86 LOG(ERROR) << "format == 0."; | |
| 87 return false; | |
| 88 } | |
| 89 CGLReleasePixelFormat(format); | |
| 90 DCHECK_NE(num_pixel_formats, 0); | |
| 91 initialized = true; | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 } // namespace | 52 } // namespace |
| 96 | 53 |
| 97 bool GLSurface::InitializeOneOffInternal() { | |
| 98 switch (GetGLImplementation()) { | |
| 99 case kGLImplementationDesktopGL: | |
| 100 case kGLImplementationDesktopGLCoreProfile: | |
| 101 case kGLImplementationAppleGL: | |
| 102 if (!InitializeOneOffForSandbox()) { | |
| 103 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | |
| 104 return false; | |
| 105 } | |
| 106 break; | |
| 107 default: | |
| 108 break; | |
| 109 } | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 113 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 54 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 114 gfx::AcceleratedWidget window) { | 55 gfx::AcceleratedWidget window) { |
| 115 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 56 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
| 116 switch (GetGLImplementation()) { | 57 switch (GetGLImplementation()) { |
| 117 case kGLImplementationDesktopGL: | 58 case kGLImplementationDesktopGL: |
| 118 case kGLImplementationDesktopGLCoreProfile: | 59 case kGLImplementationDesktopGLCoreProfile: |
| 119 case kGLImplementationAppleGL: { | 60 case kGLImplementationAppleGL: { |
| 120 NOTIMPLEMENTED() << "No onscreen support on Mac."; | 61 NOTIMPLEMENTED() << "No onscreen support on Mac."; |
| 121 return NULL; | 62 return NULL; |
| 122 } | 63 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 98 } |
| 158 case kGLImplementationMockGL: | 99 case kGLImplementationMockGL: |
| 159 return new GLSurfaceStub; | 100 return new GLSurfaceStub; |
| 160 default: | 101 default: |
| 161 NOTREACHED(); | 102 NOTREACHED(); |
| 162 return NULL; | 103 return NULL; |
| 163 } | 104 } |
| 164 } | 105 } |
| 165 | 106 |
| 166 } // namespace gl | 107 } // namespace gl |
| OLD | NEW |