Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: ui/gfx/compositor/layer.cc

Issue 8222028: Use WebKit compositor in ui::Layer (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase,fixes Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/compositor/layer.cc
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 8266bffc684f000fea7878179f3e821b8847f926..46e2734df93f7b1de4f140101344e9057be057a4 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,8 @@ Layer::~Layer() {
parent_->Remove(this);
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->parent_ = NULL;
+ if (!web_layer_.isNull())
Ben Goodger (Google) 2011/10/16 22:39:51 I'd actually rather see #ifdefs in this file... gi
piman 2011/10/19 17:53:23 Done. My initial thought was that we could support
+ web_layer_.removeFromParent();
}
Compositor* Layer::GetCompositor() {
@@ -74,6 +85,10 @@ void Layer::Add(Layer* child) {
child->parent_->Remove(child);
child->parent_ = this;
children_.push_back(child);
+ if (!web_layer_.isNull()) {
+ DCHECK(!child->web_layer_.isNull());
+ web_layer_.addChild(child->web_layer_);
+ }
RecomputeHole();
}
@@ -84,6 +99,8 @@ void Layer::Remove(Layer* child) {
DCHECK(i != children_.end());
children_.erase(i);
child->parent_ = NULL;
+ if (!child->web_layer_.isNull())
+ child->web_layer_.removeFromParent();
RecomputeHole();
@@ -96,6 +113,11 @@ void Layer::MoveToFront(Layer* child) {
DCHECK(i != children_.end());
children_.erase(i);
children_.push_back(child);
+ if (!web_layer_.isNull()) {
+ DCHECK(!child->web_layer_.isNull());
+ child->web_layer_.removeFromParent();
+ web_layer_.addChild(child->web_layer_);
+ }
}
bool Layer::Contains(const Layer* other) const {
@@ -159,6 +181,10 @@ void Layer::SetVisible(bool visible) {
DropTextures();
if (parent_)
parent_->RecomputeHole();
+ if (!web_layer_.isNull()) {
+ // TODO(piman): Expose a visibility flag on WebLayer.
+ web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
+ }
}
bool Layer::IsDrawn() const {
@@ -168,7 +194,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()));
}
@@ -200,6 +226,8 @@ void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
if (parent())
parent()->RecomputeHole();
+ if (!web_layer_.isNull())
+ web_layer_.setOpaque(fills_bounds_opaquely);
}
void Layer::SetExternalTexture(ui::Texture* texture) {
@@ -209,6 +237,7 @@ void Layer::SetExternalTexture(ui::Texture* texture) {
}
void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
+ DCHECK(web_layer_.isNull());
DCHECK_EQ(type_, LAYER_HAS_TEXTURE);
if (!texture_.get())
@@ -219,16 +248,26 @@ void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
}
void Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
- invalid_rect_ = invalid_rect_.Union(invalid_rect);
- ScheduleDraw();
+ if (web_layer_.isNull()) {
+ invalid_rect_ = invalid_rect_.Union(invalid_rect);
+ ScheduleDraw();
+ } else {
+ WebKit::WebFloatRect web_rect(invalid_rect.x(),
+ invalid_rect.y(),
+ invalid_rect.width(),
+ invalid_rect.height());
+ web_layer_.invalidateRect(web_rect);
+ }
}
void Layer::ScheduleDraw() {
- if (GetCompositor())
- GetCompositor()->ScheduleDraw();
+ Compositor* compositor = GetCompositor();
+ if (compositor)
+ compositor->ScheduleDraw();
}
void Layer::Draw() {
+ DCHECK(web_layer_.isNull());
DCHECK(GetCompositor());
if (!ShouldDraw())
return;
@@ -271,6 +310,7 @@ void Layer::Draw() {
}
void Layer::DrawTree() {
+ DCHECK(web_layer_.isNull());
if (!visible_)
return;
@@ -279,6 +319,23 @@ void Layer::DrawTree() {
children_.at(i)->DrawTree();
}
+void Layer::notifyNeedsComposite() {
+ DCHECK(!web_layer_.isNull());
+ ScheduleDraw();
+}
+
+void Layer::RecomputeDrawsContent() {
Ben Goodger (Google) 2011/10/16 22:39:51 order in .cc should match .h
piman 2011/10/19 17:53:23 Done.
+ DCHECK(!web_layer_.isNull());
+ web_layer_.setDrawsContent(ShouldDraw());
+}
+
+void Layer::paintContents(WebKit::WebCanvas* web_canvas,
+ const WebKit::WebRect& clip) {
+ DCHECK(!web_layer_.isNull());
+ gfx::CanvasSkia canvas(web_canvas);
+ delegate_->OnPaintLayer(&canvas);
+}
+
float Layer::GetCombinedOpacity() const {
float opacity = opacity_;
Layer* current = this->parent_;
@@ -290,6 +347,7 @@ float Layer::GetCombinedOpacity() const {
}
void Layer::UpdateLayerCanvas() {
+ DCHECK(web_layer_.isNull());
// If we have no delegate, that means that whoever constructed the Layer is
// setting its canvas directly with SetCanvas().
if (!delegate_ || layer_updated_externally_)
@@ -351,6 +409,9 @@ void Layer::RecomputeHole() {
// Free up texture memory if the hole fills bounds of layer.
if (!ShouldDraw() && !layer_updated_externally_)
texture_ = NULL;
+
+ if (!web_layer_.isNull())
+ RecomputeDrawsContent();
}
bool Layer::IsCompletelyOpaque() const {
@@ -394,6 +455,8 @@ void Layer::PunchHole(const gfx::Rect& rect,
}
void Layer::DropTextures() {
+ if (!web_layer_.isNull())
+ return;
if (!layer_updated_externally_)
texture_ = NULL;
for (size_t i = 0; i < children_.size(); ++i)
@@ -460,6 +523,11 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
if (parent())
parent()->RecomputeHole();
+ if (!web_layer_.isNull()) {
+ web_layer_.setBounds(bounds.size());
+ RecomputeTransform();
+ RecomputeDrawsContent();
+ }
}
void Layer::SetTransformImmediately(const ui::Transform& transform) {
@@ -467,6 +535,15 @@ void Layer::SetTransformImmediately(const ui::Transform& transform) {
if (parent())
parent()->RecomputeHole();
+ if (!web_layer_.isNull())
+ RecomputeTransform();
+}
+
+void Layer::RecomputeTransform() {
+ DCHECK(!web_layer_.isNull());
+ ui::Transform transform = transform_;
+ transform.ConcatTranslate(bounds_.x(), bounds_.y());
+ web_layer_.setTransform(transform.matrix());
}
void Layer::SetOpacityImmediately(float opacity) {
@@ -489,6 +566,11 @@ void Layer::SetOpacityImmediately(float opacity) {
to_process.push(current->children_.at(i));
}
}
+ if (!web_layer_.isNull()) {
+ if (visible_)
+ web_layer_.setOpacity(opacity);
+ RecomputeDrawsContent();
+ }
}
void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
@@ -503,4 +585,11 @@ void Layer::SetOpacityFromAnimator(float opacity) {
SetOpacityImmediately(opacity);
}
+void Layer::CreateWebLayer() {
+ web_layer_ = WebKit::WebContentLayer::create(this, this);
+ web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
+ web_layer_.setOpaque(true);
+ RecomputeDrawsContent();
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698