| Index: ui/gfx/compositor/layer.cc
|
| diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
|
| index c094b1e67bec1481de59eee59bf8bea6e9e7b0eb..1a427547f6f0527d35736702ee98a7d05db74979 100644
|
| --- a/ui/gfx/compositor/layer.cc
|
| +++ b/ui/gfx/compositor/layer.cc
|
| @@ -8,6 +8,9 @@
|
|
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
| #include "ui/base/animation/animation.h"
|
| #include "ui/gfx/compositor/layer_animator.h"
|
| #include "ui/gfx/canvas_skia.h"
|
| @@ -36,6 +39,9 @@ Layer::Layer(Compositor* compositor)
|
| layer_updated_externally_(false),
|
| opacity_(1.0f),
|
| delegate_(NULL) {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + CreateWebLayer();
|
| +#endif
|
| }
|
|
|
| Layer::Layer(Compositor* compositor, LayerType type)
|
| @@ -47,6 +53,9 @@ Layer::Layer(Compositor* compositor, LayerType type)
|
| layer_updated_externally_(false),
|
| opacity_(1.0f),
|
| delegate_(NULL) {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + CreateWebLayer();
|
| +#endif
|
| }
|
|
|
| Layer::~Layer() {
|
| @@ -54,6 +63,9 @@ Layer::~Layer() {
|
| parent_->Remove(this);
|
| for (size_t i = 0; i < children_.size(); ++i)
|
| children_[i]->parent_ = NULL;
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + web_layer_.removeFromParent();
|
| +#endif
|
| }
|
|
|
| Compositor* Layer::GetCompositor() {
|
| @@ -74,6 +86,9 @@ void Layer::Add(Layer* child) {
|
| child->parent_->Remove(child);
|
| child->parent_ = this;
|
| children_.push_back(child);
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + web_layer_.addChild(child->web_layer_);
|
| +#endif
|
|
|
| RecomputeHole();
|
| }
|
| @@ -84,6 +99,9 @@ void Layer::Remove(Layer* child) {
|
| DCHECK(i != children_.end());
|
| children_.erase(i);
|
| child->parent_ = NULL;
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + child->web_layer_.removeFromParent();
|
| +#endif
|
|
|
| RecomputeHole();
|
|
|
| @@ -96,6 +114,10 @@ void Layer::MoveToFront(Layer* child) {
|
| DCHECK(i != children_.end());
|
| children_.erase(i);
|
| children_.push_back(child);
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + child->web_layer_.removeFromParent();
|
| + web_layer_.addChild(child->web_layer_);
|
| +#endif
|
| }
|
|
|
| bool Layer::Contains(const Layer* other) const {
|
| @@ -165,6 +187,10 @@ void Layer::SetVisible(bool visible) {
|
| DropTextures();
|
| if (parent_)
|
| parent_->RecomputeHole();
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + // TODO(piman): Expose a visibility flag on WebLayer.
|
| + web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
|
| +#endif
|
| }
|
|
|
| bool Layer::IsDrawn() const {
|
| @@ -174,7 +200,7 @@ bool Layer::IsDrawn() const {
|
| return layer == NULL;
|
| }
|
|
|
| -bool Layer::ShouldDraw() {
|
| +bool Layer::ShouldDraw() const {
|
| return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f &&
|
| !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size()));
|
| }
|
| @@ -206,6 +232,9 @@ void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
|
|
|
| if (parent())
|
| parent()->RecomputeHole();
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + web_layer_.setOpaque(fills_bounds_opaquely);
|
| +#endif
|
| }
|
|
|
| void Layer::SetExternalTexture(ui::Texture* texture) {
|
| @@ -215,6 +244,9 @@ void Layer::SetExternalTexture(ui::Texture* texture) {
|
| }
|
|
|
| void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + NOTREACHED();
|
| +#else
|
| DCHECK_EQ(type_, LAYER_HAS_TEXTURE);
|
|
|
| if (!texture_.get())
|
| @@ -222,19 +254,32 @@ void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
|
|
|
| texture_->SetCanvas(canvas, origin, bounds_.size());
|
| invalid_rect_ = gfx::Rect();
|
| +#endif
|
| }
|
|
|
| void Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + WebKit::WebFloatRect web_rect(invalid_rect.x(),
|
| + invalid_rect.y(),
|
| + invalid_rect.width(),
|
| + invalid_rect.height());
|
| + web_layer_.invalidateRect(web_rect);
|
| +#else
|
| invalid_rect_ = invalid_rect_.Union(invalid_rect);
|
| ScheduleDraw();
|
| +#endif
|
| }
|
|
|
| void Layer::ScheduleDraw() {
|
| - if (GetCompositor())
|
| - GetCompositor()->ScheduleDraw();
|
| + Compositor* compositor = GetCompositor();
|
| + if (compositor)
|
| + compositor->ScheduleDraw();
|
| }
|
|
|
| void Layer::Draw() {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + NOTREACHED();
|
| +#else
|
| DCHECK(GetCompositor());
|
| if (!ShouldDraw())
|
| return;
|
| @@ -274,15 +319,38 @@ void Layer::Draw() {
|
| if (!regions_to_draw[i].IsEmpty())
|
| texture_->Draw(texture_draw_params, regions_to_draw[i]);
|
| }
|
| +#endif
|
| }
|
|
|
| void Layer::DrawTree() {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + NOTREACHED();
|
| +#else
|
| if (!visible_)
|
| return;
|
|
|
| Draw();
|
| for (size_t i = 0; i < children_.size(); ++i)
|
| children_.at(i)->DrawTree();
|
| +#endif
|
| +}
|
| +
|
| +void Layer::notifyNeedsComposite() {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + ScheduleDraw();
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| +}
|
| +
|
| +void Layer::paintContents(WebKit::WebCanvas* web_canvas,
|
| + const WebKit::WebRect& clip) {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + gfx::CanvasSkia canvas(web_canvas);
|
| + delegate_->OnPaintLayer(&canvas);
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| }
|
|
|
| float Layer::GetCombinedOpacity() const {
|
| @@ -296,6 +364,9 @@ float Layer::GetCombinedOpacity() const {
|
| }
|
|
|
| void Layer::UpdateLayerCanvas() {
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + NOTREACHED();
|
| +#else
|
| // If we have no delegate, that means that whoever constructed the Layer is
|
| // setting its canvas directly with SetCanvas().
|
| if (!delegate_ || layer_updated_externally_)
|
| @@ -312,6 +383,7 @@ void Layer::UpdateLayerCanvas() {
|
| canvas->TranslateInt(-draw_rect.x(), -draw_rect.y());
|
| delegate_->OnPaintLayer(canvas.get());
|
| SetCanvas(*canvas->GetSkCanvas(), draw_rect.origin());
|
| +#endif
|
| }
|
|
|
| void Layer::RecomputeHole() {
|
| @@ -357,6 +429,10 @@ void Layer::RecomputeHole() {
|
| // Free up texture memory if the hole fills bounds of layer.
|
| if (!ShouldDraw() && !layer_updated_externally_)
|
| texture_ = NULL;
|
| +
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + RecomputeDrawsContent();
|
| +#endif
|
| }
|
|
|
| bool Layer::IsCompletelyOpaque() const {
|
| @@ -466,6 +542,11 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
|
|
|
| if (parent())
|
| parent()->RecomputeHole();
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + web_layer_.setBounds(bounds.size());
|
| + RecomputeTransform();
|
| + RecomputeDrawsContent();
|
| +#endif
|
| }
|
|
|
| void Layer::SetTransformImmediately(const ui::Transform& transform) {
|
| @@ -473,6 +554,9 @@ void Layer::SetTransformImmediately(const ui::Transform& transform) {
|
|
|
| if (parent())
|
| parent()->RecomputeHole();
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + RecomputeTransform();
|
| +#endif
|
| }
|
|
|
| void Layer::SetOpacityImmediately(float opacity) {
|
| @@ -495,6 +579,11 @@ void Layer::SetOpacityImmediately(float opacity) {
|
| to_process.push(current->children_.at(i));
|
| }
|
| }
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| + if (visible_)
|
| + web_layer_.setOpacity(opacity);
|
| + RecomputeDrawsContent();
|
| +#endif
|
| }
|
|
|
| void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
|
| @@ -509,4 +598,23 @@ void Layer::SetOpacityFromAnimator(float opacity) {
|
| SetOpacityImmediately(opacity);
|
| }
|
|
|
| +#if defined(USE_WEBKIT_COMPOSITOR)
|
| +void Layer::CreateWebLayer() {
|
| + web_layer_ = WebKit::WebContentLayer::create(this, this);
|
| + web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
|
| + web_layer_.setOpaque(true);
|
| + RecomputeDrawsContent();
|
| +}
|
| +
|
| +void Layer::RecomputeTransform() {
|
| + ui::Transform transform = transform_;
|
| + transform.ConcatTranslate(bounds_.x(), bounds_.y());
|
| + web_layer_.setTransform(transform.matrix());
|
| +}
|
| +
|
| +void Layer::RecomputeDrawsContent() {
|
| + web_layer_.setDrawsContent(ShouldDraw());
|
| +}
|
| +#endif
|
| +
|
| } // namespace ui
|
|
|