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 3 // found in the LICENSE file. 4 5 #ifndef UI_GL_GL_CONTEXT_CGL_H_ 6 #define UI_GL_GL_CONTEXT_CGL_H_ 7 8 #include <OpenGL/CGLTypes.h> 9 10 #include <memory> 11 12 #include "base/macros.h" 13 #include "ui/gfx/color_space.h" 14 #include "ui/gl/gl_context.h" 15 #include "ui/gl/gl_export.h" 16 17 namespace gl { 18 19 class GLSurface; 20 21 // Encapsulates a CGL OpenGL context. 22 class GL_EXPORT GLContextCGL : public GLContextReal { 23 public: 24 explicit GLContextCGL(GLShareGroup* share_group, int core_profile_number = 0); 25 26 // Implement GLContext. 27 bool Initialize(GLSurface* compatible_surface, 28 const GLContextAttribs& attribs) override; 29 bool MakeCurrent(GLSurface* surface) override; 30 void ReleaseCurrent(GLSurface* surface) override; 31 bool IsCurrent(GLSurface* surface) override; 32 void* GetHandle() override; 33 void SetSafeToForceGpuSwitch() override; 34 bool ForceGpuSwitchIfNeeded() override; 35 YUVToRGBConverter* GetYUVToRGBConverter( 36 const gfx::ColorSpace& color_space) override; 37 void SetVisibility(bool visibility) override; 38 39 protected: 40 ~GLContextCGL() override; 41 42 private: 43 void Destroy(); 44 GpuPreference GetGpuPreference(); 45 46 void* context_ = nullptr; 47 GpuPreference gpu_preference_ = GpuPreference::kLowPower; 48 std::map<gfx::ColorSpace, std::unique_ptr<YUVToRGBConverter>> 49 yuv_to_rgb_converters_; 50 51 int screen_ = -1; 52 int renderer_id_ = -1; 53 bool safe_to_force_gpu_switch_ = true; 54 bool is_high_performance_context_ = false; 55 56 // Debugging for https://crbug.com/863817 57 bool has_switched_gpus_ = false; 58 59 int core_profile_number_ = 0; 60 61 DISALLOW_COPY_AND_ASSIGN(GLContextCGL); 62 }; 63 64 } // namespace gl 65 66 #endif // UI_GL_GL_CONTEXT_CGL_H_ 67