| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "window_manager/compositor/gles/opengles_visitor.h" | 5 #include "window_manager/compositor/gles/opengles_visitor.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <xcb/damage.h> | 8 #include <xcb/damage.h> |
| 9 | 9 |
| 10 #include <EGL/egl.h> | 10 #include <EGL/egl.h> |
| 11 #include <EGL/eglext.h> | 11 #include <EGL/eglext.h> |
| 12 #include <GLES2/gl2.h> | 12 #include <GLES2/gl2.h> |
| 13 #include <GLES2/gl2ext.h> | 13 #include <GLES2/gl2ext.h> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "window_manager/compositor/gles/gles2_interface.h" | 16 #include "window_manager/compositor/gles/gles2_interface.h" |
| 17 #include "window_manager/compositor/gles/shaders.h" | 17 #include "window_manager/compositor/gles/shaders.h" |
| 18 #include "window_manager/image_container.h" | 18 #include "window_manager/image_container.h" |
| 19 | 19 |
| 20 #ifndef COMPOSITOR_OPENGLES | 20 #ifndef COMPOSITOR_OPENGLES |
| 21 #error Need COMPOSITOR_OPENGLES defined to compile this file | 21 #error Need COMPOSITOR_OPENGLES defined to compile this file |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace window_manager { | 24 namespace window_manager { |
| 25 | 25 |
| 26 OpenGlesDrawVisitor::OpenGlesDrawVisitor(Gles2Interface* gl, | 26 OpenGlesDrawVisitor::OpenGlesDrawVisitor(Gles2Interface* gl, |
| 27 RealCompositor* compositor, | 27 RealCompositor* compositor, |
| 28 Compositor::StageActor* stage) | 28 Compositor::StageActor* stage) |
| 29 : gl_(gl), | 29 : gl_(gl), |
| 30 compositor_(compositor), | 30 compositor_(compositor), |
| 31 stage_(stage), | 31 stage_(stage), |
| 32 x_connection_(compositor_->x_conn()), | 32 x_connection_(compositor_->x_conn()), |
| 33 egl_surface_is_capable_of_partial_updates_(false), | 33 egl_surface_is_capable_of_partial_updates_(false), |
| 34 has_fullscreen_actor_(false), | 34 has_fullscreen_actor_(false), |
| 35 using_passthrough_projection_(false) { | 35 using_passthrough_projection_(false) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 egl_context_attributes); | 88 egl_context_attributes); |
| 89 CHECK(egl_context_ != EGL_NO_CONTEXT) << "Failed to create EGL context."; | 89 CHECK(egl_context_ != EGL_NO_CONTEXT) << "Failed to create EGL context."; |
| 90 | 90 |
| 91 CHECK(gl_->EglMakeCurrent(egl_display_, egl_surface_, egl_surface_, | 91 CHECK(gl_->EglMakeCurrent(egl_display_, egl_surface_, egl_surface_, |
| 92 egl_context_)) | 92 egl_context_)) |
| 93 << "eglMakeCurrent() failed: " << eglGetError(); | 93 << "eglMakeCurrent() failed: " << eglGetError(); |
| 94 | 94 |
| 95 CHECK(gl_->InitGLExtensions()) << "Failed to load GL-ES extensions."; | 95 CHECK(gl_->InitGLExtensions()) << "Failed to load GL-ES extensions."; |
| 96 | 96 |
| 97 // Allocate shaders | 97 // Allocate shaders |
| 98 tex_color_shader_ = new TexColorShader(); | 98 tex_color_shader_.reset(new TexColorShader()); |
| 99 tex_shade_shader_ = new TexShadeShader(); | 99 tex_shade_shader_.reset(new TexShadeShader()); |
| 100 no_alpha_color_shader_ = new NoAlphaColorShader(); | 100 no_alpha_color_shader_.reset(new NoAlphaColorShader()); |
| 101 no_alpha_shade_shader_ = new NoAlphaShadeShader(); | 101 no_alpha_shade_shader_.reset(new NoAlphaShadeShader()); |
| 102 gl_->ReleaseShaderCompiler(); | 102 gl_->ReleaseShaderCompiler(); |
| 103 | 103 |
| 104 // TODO: Move away from one global Vertex Buffer Object | 104 // TODO: Move away from one global Vertex Buffer Object |
| 105 gl_->GenBuffers(1, &vertex_buffer_object_); | 105 gl_->GenBuffers(1, &vertex_buffer_object_); |
| 106 CHECK(vertex_buffer_object_ > 0) << "VBO allocation failed."; | 106 CHECK(vertex_buffer_object_ > 0) << "VBO allocation failed."; |
| 107 gl_->BindBuffer(GL_ARRAY_BUFFER, vertex_buffer_object_); | 107 gl_->BindBuffer(GL_ARRAY_BUFFER, vertex_buffer_object_); |
| 108 static float kTriAndQuad[] = { | 108 static float kTriAndQuad[] = { |
| 109 // Triangle-strip quad. | 109 // Triangle-strip quad. |
| 110 0.f, 0.f, | 110 0.f, 0.f, |
| 111 0.f, 1.f, | 111 0.f, 1.f, |
| 112 1.f, 0.f, | 112 1.f, 0.f, |
| 113 1.f, 1.f, | 113 1.f, 1.f, |
| 114 | 114 |
| 115 // Large Triangle | 115 // Large Triangle |
| 116 0.f, 0.f, | 116 0.f, 0.f, |
| 117 0.f, 2.f, | 117 0.f, 2.f, |
| 118 2.f, 0.f, | 118 2.f, 0.f, |
| 119 }; | 119 }; |
| 120 gl_->BufferData(GL_ARRAY_BUFFER, | 120 gl_->BufferData(GL_ARRAY_BUFFER, |
| 121 sizeof(kTriAndQuad), kTriAndQuad, | 121 sizeof(kTriAndQuad), kTriAndQuad, |
| 122 GL_STATIC_DRAW); | 122 GL_STATIC_DRAW); |
| 123 quad_vertices_index_ = 0; | 123 quad_vertices_index_ = 0; |
| 124 tri_vertices_index_ = 4; | 124 tri_vertices_index_ = 4; |
| 125 | 125 |
| 126 // Unchanging state | 126 // Unchanging state |
| 127 gl_->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 127 gl_->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 128 } | 128 } |
| 129 | 129 |
| 130 OpenGlesDrawVisitor::~OpenGlesDrawVisitor() { | 130 OpenGlesDrawVisitor::~OpenGlesDrawVisitor() { |
| 131 delete tex_color_shader_; | |
| 132 delete tex_shade_shader_; | |
| 133 delete no_alpha_color_shader_; | |
| 134 delete no_alpha_shade_shader_; | |
| 135 | |
| 136 gl_->DeleteBuffers(1, &vertex_buffer_object_); | 131 gl_->DeleteBuffers(1, &vertex_buffer_object_); |
| 137 | 132 |
| 138 LOG_IF(ERROR, gl_->EglMakeCurrent(egl_display_, EGL_NO_SURFACE, | 133 LOG_IF(ERROR, gl_->EglMakeCurrent(egl_display_, |
| 134 EGL_NO_SURFACE, |
| 139 EGL_NO_SURFACE, | 135 EGL_NO_SURFACE, |
| 140 EGL_NO_CONTEXT) != EGL_TRUE) | 136 EGL_NO_CONTEXT) != EGL_TRUE) |
| 141 << "eglMakeCurrent() failed: " << eglGetError(); | 137 << "eglMakeCurrent() failed: " << eglGetError(); |
| 142 LOG_IF(ERROR, gl_->EglDestroySurface(egl_display_, egl_surface_) != EGL_TRUE) | 138 LOG_IF(ERROR, gl_->EglDestroySurface(egl_display_, egl_surface_) != EGL_TRUE) |
| 143 << "eglDestroySurface() failed: " << eglGetError(); | 139 << "eglDestroySurface() failed: " << eglGetError(); |
| 144 LOG_IF(ERROR, gl_->EglDestroyContext(egl_display_, egl_context_) != EGL_TRUE) | 140 LOG_IF(ERROR, gl_->EglDestroyContext(egl_display_, egl_context_) != EGL_TRUE) |
| 145 << "eglDestroyCotnext() failed: " << eglGetError(); | 141 << "eglDestroyCotnext() failed: " << eglGetError(); |
| 146 } | 142 } |
| 147 | 143 |
| 148 void OpenGlesDrawVisitor::BindImage(const ImageContainer* container, | 144 void OpenGlesDrawVisitor::BindImage(const ImageContainer* container, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 177 CHECK(texture > 0) << "Failed to allocated texture."; | 173 CHECK(texture > 0) << "Failed to allocated texture."; |
| 178 gl_->BindTexture(GL_TEXTURE_2D, texture); | 174 gl_->BindTexture(GL_TEXTURE_2D, texture); |
| 179 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 175 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 180 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 176 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 181 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 177 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 182 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 178 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 183 gl_->TexImage2D(GL_TEXTURE_2D, 0, gl_format, | 179 gl_->TexImage2D(GL_TEXTURE_2D, 0, gl_format, |
| 184 container->width(), container->height(), | 180 container->width(), container->height(), |
| 185 0, gl_format, gl_type, container->data()); | 181 0, gl_format, gl_type, container->data()); |
| 186 | 182 |
| 187 OpenGlesTextureData* data = new OpenGlesTextureData(gl_); | 183 scoped_ptr<OpenGlesTextureData> data(new OpenGlesTextureData(gl_)); |
| 188 data->SetTexture(texture); | 184 data->SetTexture(texture); |
| 189 data->set_has_alpha(ImageFormatUsesAlpha(container->format())); | 185 data->set_has_alpha(ImageFormatUsesAlpha(container->format())); |
| 190 actor->set_texture_data(data); | 186 actor->set_texture_data(data.release()); |
| 191 } | 187 } |
| 192 | 188 |
| 193 void OpenGlesDrawVisitor::VisitStage(RealCompositor::StageActor* actor) { | 189 void OpenGlesDrawVisitor::VisitStage(RealCompositor::StageActor* actor) { |
| 194 if (!actor->IsVisible()) | 190 if (!actor->IsVisible()) |
| 195 return; | 191 return; |
| 196 | 192 |
| 197 if (actor->stage_color_changed()) { | 193 if (actor->stage_color_changed()) { |
| 198 const Compositor::Color& color = actor->stage_color(); | 194 const Compositor::Color& color = actor->stage_color(); |
| 199 gl_->ClearColor(color.red, color.green, color.blue, 1.f); | 195 gl_->ClearColor(color.red, color.green, color.blue, 1.f); |
| 200 actor->unset_stage_color_changed(); | 196 actor->unset_stage_color_changed(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 260 } |
| 265 } | 261 } |
| 266 | 262 |
| 267 void OpenGlesDrawVisitor::CreateTextureData( | 263 void OpenGlesDrawVisitor::CreateTextureData( |
| 268 RealCompositor::TexturePixmapActor* actor) const { | 264 RealCompositor::TexturePixmapActor* actor) const { |
| 269 OpenGlesEglImageData image_data(gl_); | 265 OpenGlesEglImageData image_data(gl_); |
| 270 | 266 |
| 271 if (!image_data.Bind(actor)) | 267 if (!image_data.Bind(actor)) |
| 272 return; | 268 return; |
| 273 | 269 |
| 274 OpenGlesTextureData* texture = new OpenGlesTextureData(gl_); | 270 scoped_ptr<OpenGlesTextureData> texture(new OpenGlesTextureData(gl_)); |
| 275 image_data.BindTexture(texture, !actor->pixmap_is_opaque()); | 271 image_data.BindTexture(texture.get(), !actor->pixmap_is_opaque()); |
| 276 actor->set_texture_data(texture); | 272 actor->set_texture_data(texture.release()); |
| 277 } | 273 } |
| 278 | 274 |
| 279 void OpenGlesDrawVisitor::VisitImage(RealCompositor::ImageActor* actor) { | 275 void OpenGlesDrawVisitor::VisitImage(RealCompositor::ImageActor* actor) { |
| 280 VisitQuad(actor); | 276 VisitQuad(actor); |
| 281 } | 277 } |
| 282 | 278 |
| 283 void OpenGlesDrawVisitor::VisitTexturePixmap( | 279 void OpenGlesDrawVisitor::VisitTexturePixmap( |
| 284 RealCompositor::TexturePixmapActor* actor) { | 280 RealCompositor::TexturePixmapActor* actor) { |
| 285 if (!actor->IsVisible()) | 281 if (!actor->IsVisible()) |
| 286 return; | 282 return; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 558 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 563 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 559 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 564 gl_->EGLImageTargetTexture2DOES(GL_TEXTURE_2D, | 560 gl_->EGLImageTargetTexture2DOES(GL_TEXTURE_2D, |
| 565 static_cast<GLeglImageOES>(egl_image_)); | 561 static_cast<GLeglImageOES>(egl_image_)); |
| 566 | 562 |
| 567 texture_data->SetTexture(texture); | 563 texture_data->SetTexture(texture); |
| 568 texture_data->set_has_alpha(has_alpha); | 564 texture_data->set_has_alpha(has_alpha); |
| 569 } | 565 } |
| 570 | 566 |
| 571 } // namespace window_manager | 567 } // namespace window_manager |
| OLD | NEW |