1 // Copyright 2014 Samsung Electronics. 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.
5 #include "ui/gl/gl_shared_context_efl.h"
8 #include <Ecore_Evas.h>
11 #include "base/threading/thread_restrictions.h"
12 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
13 #include "ui/gl/gl_context.h"
14 #include "ui/gl/gl_share_group.h"
15 #include "ui/gl/gpu_timing.h"
16 #if defined(TIZEN_DISABLE_GPU_THREAD)
17 #include "base/command_line.h"
20 // Defined in gl_current_context_efl.cc because of conflict in chromium
21 // and efl gl includes.
22 extern void* GLGetCurentContext();
24 #if defined(TIZEN_DISABLE_GPU_THREAD)
25 class GLSharedContextEflPrivate
26 : public gfx::GLContext,
27 public gfx::GLCustomApi {
30 struct GLSharedContextEflPrivate : public gfx::GLContext {
32 GLSharedContextEflPrivate(Evas_Object* object)
33 : GLContext(GLSharedContextEfl::GetShareGroup()) {
34 Evas* evas = evas_object_evas_get(object);
35 evas_gl_config_ = evas_gl_config_new();
36 evas_gl_config_->options_bits = EVAS_GL_OPTIONS_NONE;
37 evas_gl_config_->color_format = EVAS_GL_RGBA_8888;
38 evas_gl_config_->depth_bits = EVAS_GL_DEPTH_BIT_24;
39 evas_gl_config_->stencil_bits = EVAS_GL_STENCIL_BIT_8;
41 evas_gl_ = evas_gl_new(evas);
42 evas_gl_context_ = evas_gl_context_create(evas_gl_, 0);
43 if (!evas_gl_context_)
44 LOG(FATAL) << "GLSharedContextEflPrivate(): Create evas gl context Fail";
46 evas_gl_surface_ = evas_gl_surface_create(
47 evas_gl_, evas_gl_config_, 1, 1);
48 if (!evas_gl_surface_)
49 LOG(FATAL) << "GLSharedContextEflPrivate(): Create evas gl Surface Fail";
51 evas_gl_make_current(evas_gl_, evas_gl_surface_, evas_gl_context_);
52 handle_ = GLGetCurentContext();
53 CHECK(handle_ != EGL_NO_CONTEXT);
54 evas_gl_make_current(evas_gl_, 0, 0);
56 #if defined(TIZEN_DISABLE_GPU_THREAD)
58 base::CommandLine::ForCurrentProcess()->HasSwitch("disable-gpu-thread");
60 if (use_native_surface_) {
61 evas_gl_api_ = evas_gl_api_get(evas_gl_);
62 GLSharedContextEfl::GetShareGroup()->SetSharedContext(this);
69 gfx::GLSurface*, gfx::GpuPreference) override {
70 #if defined(TIZEN_DISABLE_GPU_THREAD)
71 return use_native_surface_;
78 #if defined(TIZEN_DISABLE_GPU_THREAD)
79 bool MakeCurrent(gfx::GLSurface* surface) override {
80 if (use_native_surface_) {
82 delegate_->MakeCurrent();
85 GLContext::SetCurrent(surface);
91 void GetIntegerv(GLenum pname, GLint* params) override {
92 evas_gl_api_->glGetIntegerv(pname, params);
95 void Clear(GLbitfield mask) override {
96 evas_gl_api_->glClear(mask);
100 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) override {
101 evas_gl_api_->glClearColor(red, green, blue, alpha);
104 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) override {
105 evas_gl_api_->glViewport(x, y, width, height);
108 void BindFramebufferEXT(GLenum target, GLuint framebuffer) override {
109 evas_gl_api_->glBindFramebuffer(target, framebuffer);
112 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height) override {
113 evas_gl_api_->glScissor(x, y, width, height);
116 void Disable(GLenum cap) {
117 evas_gl_api_->glDisable(cap);
120 void Enable(GLenum cap) {
121 evas_gl_api_->glEnable(cap);
124 bool MakeCurrent(gfx::GLSurface*) override {
130 void ReleaseCurrent(gfx::GLSurface*) override {
134 bool IsCurrent(gfx::GLSurface*) override {
139 void* GetHandle() override {
143 virtual scoped_refptr<gfx::GPUTimingClient> CreateGPUTimingClient() override {
147 virtual void OnSetSwapInterval(int interval) override {
152 friend struct GLSharedContextEfl;
154 ~GLSharedContextEflPrivate() override {
155 evas_gl_surface_destroy(evas_gl_, evas_gl_surface_);
156 evas_gl_context_destroy(evas_gl_, evas_gl_context_);
157 evas_gl_config_free(evas_gl_config_);
158 evas_gl_free(evas_gl_);
163 Evas_GL_Context* evas_gl_context_;
164 Evas_GL_Surface* evas_gl_surface_;
165 Evas_GL_Config* evas_gl_config_;
166 #if defined(TIZEN_DISABLE_GPU_THREAD)
167 Evas_GL_API* evas_gl_api_;
168 bool use_native_surface_;
169 GLSharedContextDelegate* delegate_;
174 static GLSharedContextEflPrivate* g_private_part = NULL;
178 void GLSharedContextEfl::Initialize(Evas_Object* object) {
179 if (!g_private_part) {
180 base::ThreadRestrictions::ScopedAllowIO allow_io;
181 g_private_part = new GLSharedContextEflPrivate(object);
186 gfx::GLContext* GLSharedContextEfl::GetInstance() {
187 return g_private_part;
191 Evas_GL_Context* GLSharedContextEfl::GetEvasGLContext() {
192 return g_private_part->evas_gl_context_;
196 gfx::GLShareGroup* GLSharedContextEfl::GetShareGroup() {
197 static scoped_refptr<gfx::GLShareGroup> share_group_ =
198 new gfx::GLShareGroup();
199 return share_group_.get();
202 #if defined(TIZEN_DISABLE_GPU_THREAD)
203 void GLSharedContextEfl::SetDelegate(GLSharedContextDelegate* delegate) {
204 g_private_part->delegate_ = delegate;