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

Unified Diff: webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc

Issue 12326022: Efficiently handle image layer scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add black-box tests Created 7 years, 10 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: webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc
diff --git a/webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc b/webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c1ed4fbd067a9ea6edba9b810d78453e8ebe008
--- /dev/null
+++ b/webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc
@@ -0,0 +1,147 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h"
+
+#include "cc/layer.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMatrix.h"
+#include "third_party/skia/include/utils/SkMatrix44.h"
+#include "webkit/compositor_bindings/web_transformation_matrix_util.h"
+
+using cc::Layer;
+using webkit::WebTransformationMatrixUtil;
+
+namespace WebKit {
+
+WebLayerImplFixedBounds::WebLayerImplFixedBounds()
+{
+}
+
+WebLayerImplFixedBounds::WebLayerImplFixedBounds(scoped_refptr<Layer> layer)
+ : WebLayerImpl(layer)
+{
+}
+
+
+WebLayerImplFixedBounds::~WebLayerImplFixedBounds()
+{
+}
+
+void WebLayerImplFixedBounds::invalidateRect(const WebFloatRect& rect)
+{
+ // Partial invalidations seldom occur for such layers.
+ // Simply invalidate the whole layer to avoid transformation of coordinates.
+ invalidate();
+}
+
+void WebLayerImplFixedBounds::setAnchorPoint(const WebFloatPoint& anchorPoint)
+{
+ if (anchorPoint != this->anchorPoint()) {
+ m_layer->setAnchorPoint(anchorPoint);
+ updateLayerBoundsAndTransform();
+ }
+}
+
+void WebLayerImplFixedBounds::setBounds(const WebSize& bounds)
+{
+ if (m_originalBounds != gfx::Size(bounds)) {
+ m_originalBounds = bounds;
+ updateLayerBoundsAndTransform();
+ }
+}
+
+WebSize WebLayerImplFixedBounds::bounds() const
+{
+ return m_originalBounds;
+}
+
+void WebLayerImplFixedBounds::setSublayerTransform(const SkMatrix44& matrix)
+{
+ gfx::Transform transform;
+ transform.matrix() = matrix;
+ setSublayerTransformInternal(transform);
+}
+
+void WebLayerImplFixedBounds::setSublayerTransform(const WebTransformationMatrix& matrix)
+{
+ setSublayerTransformInternal(WebTransformationMatrixUtil::ToTransform(matrix));
+}
+
+SkMatrix44 WebLayerImplFixedBounds::sublayerTransform() const
+{
+ return m_originalSublayerTransform.matrix();
+}
+
+void WebLayerImplFixedBounds::setTransform(const SkMatrix44& matrix)
+{
+ gfx::Transform transform;
+ transform.matrix() = matrix;
+ setTransformInternal(transform);
+}
+
+void WebLayerImplFixedBounds::setTransform(const WebTransformationMatrix& matrix)
+{
+ setTransformInternal(WebTransformationMatrixUtil::ToTransform(matrix));
+}
+
+SkMatrix44 WebLayerImplFixedBounds::transform() const
+{
+ return m_originalTransform.matrix();
+}
+
+void WebLayerImplFixedBounds::setFixedBounds(const gfx::Size& fixedBounds)
+{
+ if (m_fixedBounds != fixedBounds) {
+ m_fixedBounds = fixedBounds;
+ updateLayerBoundsAndTransform();
+ }
+}
+
+void WebLayerImplFixedBounds::setSublayerTransformInternal(const gfx::Transform& transform)
+{
+ if (m_originalSublayerTransform != transform) {
+ m_originalSublayerTransform = transform;
+ updateLayerBoundsAndTransform();
+ }
+}
+
+void WebLayerImplFixedBounds::setTransformInternal(const gfx::Transform& transform)
+{
+ if (m_originalTransform != transform) {
+ m_originalTransform = transform;
+ updateLayerBoundsAndTransform();
+ }
+}
+
+void WebLayerImplFixedBounds::updateLayerBoundsAndTransform()
+{
+ if (m_fixedBounds.IsEmpty() || m_originalBounds.IsEmpty() || m_fixedBounds == m_originalBounds
+ // Fall back to non-fixed bounds for non-zero anchor point.
enne (OOO) 2013/02/22 23:53:32 Can you make this a TODO, so that it's clear that
Xianzhu 2013/02/23 00:56:19 Done.
+ || anchorPoint().x || anchorPoint().y) {
+ m_layer->setBounds(m_originalBounds);
+ m_layer->setTransform(m_originalTransform);
+ m_layer->setSublayerTransform(m_originalSublayerTransform);
+ return;
+ }
+
+ m_layer->setBounds(m_fixedBounds);
+
+ // Apply bounds scale (bounds/fixedBounds) over original transform.
+ gfx::Transform transformWithBoundsScale(m_originalTransform);
+ float boundsScaleX = static_cast<float>(m_originalBounds.width()) / m_fixedBounds.width();
+ float boundsScaleY = static_cast<float>(m_originalBounds.height()) / m_fixedBounds.height();
+ transformWithBoundsScale.Scale(boundsScaleX, boundsScaleY);
+ m_layer->setTransform(transformWithBoundsScale);
+
+ // As we apply extra scale transform on this layer which will propagate to the sublayers,
+ // here undo the scale on sublayers.
+ gfx::Transform sublayerTransformWithInverseBoundsScale;
+ sublayerTransformWithInverseBoundsScale.Scale(1.f / boundsScaleX, 1.f / boundsScaleY);
+ sublayerTransformWithInverseBoundsScale.PreconcatTransform(m_originalSublayerTransform);
+ m_layer->setSublayerTransform(sublayerTransformWithInverseBoundsScale);
+}
+
+} // namespace WebKit

Powered by Google App Engine
This is Rietveld 408576698