| 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> |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 gl_->EglPostSubBufferNV(egl_display_, egl_surface_, | 253 gl_->EglPostSubBufferNV(egl_display_, egl_surface_, |
| 254 damaged_region_.x, | 254 damaged_region_.x, |
| 255 damaged_region_.y, | 255 damaged_region_.y, |
| 256 damaged_region_.width, | 256 damaged_region_.width, |
| 257 damaged_region_.height); | 257 damaged_region_.height); |
| 258 } else { | 258 } else { |
| 259 gl_->EglSwapBuffers(egl_display_, egl_surface_); | 259 gl_->EglSwapBuffers(egl_display_, egl_surface_); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 void OpenGlesDrawVisitor::CreateTextureData( | 263 void OpenGlesDrawVisitor::VisitContainer( |
| 264 RealCompositor::TexturePixmapActor* actor) const { | 264 RealCompositor::ContainerActor* actor) { |
| 265 OpenGlesEglImageData image_data(gl_); | 265 if (!actor->IsVisible()) |
| 266 | |
| 267 if (!image_data.Bind(actor)) | |
| 268 return; | 266 return; |
| 269 | 267 |
| 270 scoped_ptr<OpenGlesTextureData> texture(new OpenGlesTextureData(gl_)); | 268 LOG(INFO) << "Visit container: " << actor->name(); |
| 271 image_data.BindTexture(texture.get(), !actor->pixmap_is_opaque()); | 269 |
| 272 actor->set_texture_data(texture.release()); | 270 const float original_opacity = ancestor_opacity_; |
| 271 ancestor_opacity_ *= actor->opacity(); |
| 272 |
| 273 // Back to front rendering |
| 274 const RealCompositor::ActorVector children = actor->GetChildren(); |
| 275 for (RealCompositor::ActorVector::const_reverse_iterator i = |
| 276 children.rbegin(); i != children.rend(); ++i) { |
| 277 // TODO move this down into the Visit* functions |
| 278 if ((*i)->is_opaque() && (*i)->opacity() * ancestor_opacity_ > 0.999) |
| 279 gl_->Disable(GL_BLEND); |
| 280 else |
| 281 gl_->Enable(GL_BLEND); |
| 282 (*i)->Accept(this); |
| 283 } |
| 284 |
| 285 // Reset opacity. |
| 286 ancestor_opacity_ = original_opacity; |
| 273 } | 287 } |
| 274 | 288 |
| 275 void OpenGlesDrawVisitor::VisitImage(RealCompositor::ImageActor* actor) { | 289 void OpenGlesDrawVisitor::VisitImage(RealCompositor::ImageActor* actor) { |
| 276 VisitQuad(actor); | 290 VisitQuad(actor); |
| 277 } | 291 } |
| 278 | 292 |
| 279 void OpenGlesDrawVisitor::VisitTexturePixmap( | 293 void OpenGlesDrawVisitor::VisitTexturePixmap( |
| 280 RealCompositor::TexturePixmapActor* actor) { | 294 RealCompositor::TexturePixmapActor* actor) { |
| 281 if (!actor->IsVisible()) | 295 if (!actor->IsVisible()) |
| 282 return; | 296 return; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 PopScissorRect(); | 450 PopScissorRect(); |
| 437 } else { | 451 } else { |
| 438 // The quad vertices must start at index zero to line up with the non-VBO | 452 // The quad vertices must start at index zero to line up with the non-VBO |
| 439 // colors array indices. If they're moved, the colors array needs to be | 453 // colors array indices. If they're moved, the colors array needs to be |
| 440 // resized and shifted accordingly. | 454 // resized and shifted accordingly. |
| 441 DCHECK(quad_vertices_index_ == 0); | 455 DCHECK(quad_vertices_index_ == 0); |
| 442 gl_->DrawArrays(GL_TRIANGLE_STRIP, quad_vertices_index_, 4); | 456 gl_->DrawArrays(GL_TRIANGLE_STRIP, quad_vertices_index_, 4); |
| 443 } | 457 } |
| 444 } | 458 } |
| 445 | 459 |
| 460 void OpenGlesDrawVisitor::CreateTextureData( |
| 461 RealCompositor::TexturePixmapActor* actor) const { |
| 462 OpenGlesEglImageData image_data(gl_); |
| 463 |
| 464 if (!image_data.Bind(actor)) |
| 465 return; |
| 466 |
| 467 scoped_ptr<OpenGlesTextureData> texture(new OpenGlesTextureData(gl_)); |
| 468 image_data.BindTexture(texture.get(), !actor->pixmap_is_opaque()); |
| 469 actor->set_texture_data(texture.release()); |
| 470 } |
| 471 |
| 446 void OpenGlesDrawVisitor::PushScissorRect(const Rect& scissor) { | 472 void OpenGlesDrawVisitor::PushScissorRect(const Rect& scissor) { |
| 447 if (scissor_stack_.empty()) { | 473 if (scissor_stack_.empty()) { |
| 448 scissor_stack_.push_back(scissor); | 474 scissor_stack_.push_back(scissor); |
| 449 gl_->Enable(GL_SCISSOR_TEST); | 475 gl_->Enable(GL_SCISSOR_TEST); |
| 450 gl_->Scissor(scissor.x, scissor.y, | 476 gl_->Scissor(scissor.x, scissor.y, |
| 451 scissor.width, scissor.height); | 477 scissor.width, scissor.height); |
| 452 } else { | 478 } else { |
| 453 Rect new_scissor = scissor; | 479 Rect new_scissor = scissor; |
| 454 new_scissor.intersect(scissor_stack_.back()); | 480 new_scissor.intersect(scissor_stack_.back()); |
| 455 scissor_stack_.push_back(new_scissor); | 481 scissor_stack_.push_back(new_scissor); |
| 456 gl_->Scissor(new_scissor.x, new_scissor.y, | 482 gl_->Scissor(new_scissor.x, new_scissor.y, |
| 457 new_scissor.width, new_scissor.height); | 483 new_scissor.width, new_scissor.height); |
| 458 } | 484 } |
| 459 } | 485 } |
| 460 | 486 |
| 461 void OpenGlesDrawVisitor::PopScissorRect() { | 487 void OpenGlesDrawVisitor::PopScissorRect() { |
| 462 DCHECK(!scissor_stack_.empty()); | 488 DCHECK(!scissor_stack_.empty()); |
| 463 scissor_stack_.pop_back(); | 489 scissor_stack_.pop_back(); |
| 464 | 490 |
| 465 if (scissor_stack_.empty()) { | 491 if (scissor_stack_.empty()) { |
| 466 gl_->Disable(GL_SCISSOR_TEST); | 492 gl_->Disable(GL_SCISSOR_TEST); |
| 467 } else { | 493 } else { |
| 468 const Rect& new_scissor = scissor_stack_.back(); | 494 const Rect& new_scissor = scissor_stack_.back(); |
| 469 gl_->Scissor(new_scissor.x, new_scissor.y, | 495 gl_->Scissor(new_scissor.x, new_scissor.y, |
| 470 new_scissor.width, new_scissor.height); | 496 new_scissor.width, new_scissor.height); |
| 471 } | 497 } |
| 472 } | 498 } |
| 473 | 499 |
| 474 void OpenGlesDrawVisitor::VisitContainer( | |
| 475 RealCompositor::ContainerActor* actor) { | |
| 476 if (!actor->IsVisible()) | |
| 477 return; | |
| 478 | |
| 479 LOG(INFO) << "Visit container: " << actor->name(); | |
| 480 | |
| 481 const float original_opacity = ancestor_opacity_; | |
| 482 ancestor_opacity_ *= actor->opacity(); | |
| 483 | |
| 484 // Back to front rendering | |
| 485 const RealCompositor::ActorVector children = actor->GetChildren(); | |
| 486 for (RealCompositor::ActorVector::const_reverse_iterator i = | |
| 487 children.rbegin(); i != children.rend(); ++i) { | |
| 488 // TODO move this down into the Visit* functions | |
| 489 if ((*i)->is_opaque() && (*i)->opacity() * ancestor_opacity_ > 0.999) | |
| 490 gl_->Disable(GL_BLEND); | |
| 491 else | |
| 492 gl_->Enable(GL_BLEND); | |
| 493 (*i)->Accept(this); | |
| 494 } | |
| 495 | |
| 496 // Reset opacity. | |
| 497 ancestor_opacity_ = original_opacity; | |
| 498 } | |
| 499 | |
| 500 OpenGlesTextureData::OpenGlesTextureData(Gles2Interface* gl) | 500 OpenGlesTextureData::OpenGlesTextureData(Gles2Interface* gl) |
| 501 : gl_(gl) {} | 501 : gl_(gl) {} |
| 502 | 502 |
| 503 OpenGlesTextureData::~OpenGlesTextureData() { | 503 OpenGlesTextureData::~OpenGlesTextureData() { |
| 504 gl_->DeleteTextures(1, texture_ptr()); | 504 gl_->DeleteTextures(1, texture_ptr()); |
| 505 } | 505 } |
| 506 | 506 |
| 507 void OpenGlesTextureData::SetTexture(GLuint texture) { | 507 void OpenGlesTextureData::SetTexture(GLuint texture) { |
| 508 gl_->DeleteTextures(1, texture_ptr()); | 508 gl_->DeleteTextures(1, texture_ptr()); |
| 509 set_texture(texture); | 509 set_texture(texture); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 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); |
| 559 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); |
| 560 gl_->EGLImageTargetTexture2DOES(GL_TEXTURE_2D, | 560 gl_->EGLImageTargetTexture2DOES(GL_TEXTURE_2D, |
| 561 static_cast<GLeglImageOES>(egl_image_)); | 561 static_cast<GLeglImageOES>(egl_image_)); |
| 562 | 562 |
| 563 texture_data->SetTexture(texture); | 563 texture_data->SetTexture(texture); |
| 564 texture_data->set_has_alpha(has_alpha); | 564 texture_data->set_has_alpha(has_alpha); |
| 565 } | 565 } |
| 566 | 566 |
| 567 } // namespace window_manager | 567 } // namespace window_manager |
| OLD | NEW |