diff options
author | amogh.bihani@samsung.com <amogh.bihani@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 08:35:43 +0000 |
---|---|---|
committer | amogh.bihani@samsung.com <amogh.bihani@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 08:35:43 +0000 |
commit | e1c52950314e00723f2d1b8200106b5c496a4459 (patch) | |
tree | 9b92b1df5a949b1136dd301da8353076a470a10b /content/renderer | |
parent | 293d43aafabb686cbe4c8dad9fded83c32a74dd8 (diff) | |
download | chromium_src-e1c52950314e00723f2d1b8200106b5c496a4459.zip chromium_src-e1c52950314e00723f2d1b8200106b5c496a4459.tar.gz chromium_src-e1c52950314e00723f2d1b8200106b5c496a4459.tar.bz2 |
Moving compositor_bindings from webkit to content
- All files from webkit/renderer/compositor_bindings have been moved to content/renderer/compositor_bindings
- Webkit_compositor_support is moved in content_renderer
- Webkit_compositor_bindings_unittests is moved in content_unittests
- A dummy target has been left for webkit_compositor_bindings_unittests so as to not break the build.
TBR=nduca
BUG=265753
Review URL: https://codereview.chromium.org/317163002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277988 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
59 files changed, 3668 insertions, 46 deletions
diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn index 9179ad7..d675a1e 100644 --- a/content/renderer/BUILD.gn +++ b/content/renderer/BUILD.gn @@ -51,8 +51,6 @@ source_set("renderer") { #'../third_party/WebKit/public/blink.gyp:blink', #'../third_party/libjingle/libjingle.gyp:libjingle', #'../third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h', - #'../webkit/renderer/compositor_bindings/compositor_bindings.gyp:webkit_compositor_bindings', - #'../webkit/renderer/compositor_bindings/compositor_bindings.gyp:webkit_compositor_support', ] if (!enable_notifications) { diff --git a/content/renderer/child_frame_compositing_helper.cc b/content/renderer/child_frame_compositing_helper.cc index 0a651db5..fee5ab7 100644 --- a/content/renderer/child_frame_compositing_helper.cc +++ b/content/renderer/child_frame_compositing_helper.cc @@ -18,6 +18,7 @@ #include "content/common/gpu/client/context_provider_command_buffer.h" #include "content/renderer/browser_plugin/browser_plugin.h" #include "content/renderer/browser_plugin/browser_plugin_manager.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_thread_impl.h" #include "skia/ext/image_operations.h" @@ -27,7 +28,6 @@ #include "third_party/khronos/GLES2/gl2.h" #include "ui/gfx/size_conversions.h" #include "ui/gfx/skia_util.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" namespace content { @@ -186,7 +186,7 @@ void ChildFrameCompositingHelper::EnableCompositing(bool enable) { background_layer_->SetMasksToBounds(true); background_layer_->SetBackgroundColor( SkColorSetARGBInline(255, 255, 255, 255)); - web_layer_.reset(new webkit::WebLayerImpl(background_layer_)); + web_layer_.reset(new WebLayerImpl(background_layer_)); } if (GetContainer()) { diff --git a/content/renderer/compositor_bindings/OWNERS b/content/renderer/compositor_bindings/OWNERS new file mode 100644 index 0000000..d42bb39 --- /dev/null +++ b/content/renderer/compositor_bindings/OWNERS @@ -0,0 +1,2 @@ +enne@chromium.org +nduca@chromium.org diff --git a/content/renderer/compositor_bindings/PRESUBMIT.py b/content/renderer/compositor_bindings/PRESUBMIT.py new file mode 100644 index 0000000..8e4e571 --- /dev/null +++ b/content/renderer/compositor_bindings/PRESUBMIT.py @@ -0,0 +1,33 @@ +# Copyright 2014 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. + +""" +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for +details on the presubmit API built into gcl. +""" + +SOURCE_FILES = (r'^.*\.(cc|h)$') + +def CheckChangeLintsClean(input_api, output_api): + input_api.cpplint._cpplint_state.ResetErrorCounts() # reset global state + source_filter = lambda x: input_api.FilterSourceFile( + x, white_list=SOURCE_FILES, black_list=None) + files = [f.AbsoluteLocalPath() for f in + input_api.AffectedSourceFiles(source_filter)] + level = 1 # strict, but just warn + + for file_name in files: + input_api.cpplint.ProcessFile(file_name, level) + + if not input_api.cpplint._cpplint_state.error_count: + return [] + + return [output_api.PresubmitPromptWarning( + 'Changelist failed cpplint.py check.')] + + +def CheckChangeOnUpload(input_api, output_api): + results = [] + results += CheckChangeLintsClean(input_api, output_api) + return results diff --git a/content/renderer/compositor_bindings/scrollbar_impl.cc b/content/renderer/compositor_bindings/scrollbar_impl.cc new file mode 100644 index 0000000..6ee82d4 --- /dev/null +++ b/content/renderer/compositor_bindings/scrollbar_impl.cc @@ -0,0 +1,109 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/scrollbar_impl.h" + +#include "base/logging.h" +#include "third_party/WebKit/public/platform/WebScrollbar.h" +#include "third_party/WebKit/public/platform/WebScrollbarThemeGeometry.h" + +using blink::WebScrollbar; + +namespace content { + +ScrollbarImpl::ScrollbarImpl( + scoped_ptr<WebScrollbar> scrollbar, + blink::WebScrollbarThemePainter painter, + scoped_ptr<blink::WebScrollbarThemeGeometry> geometry) + : scrollbar_(scrollbar.Pass()), + painter_(painter), + geometry_(geometry.Pass()) { +} + +ScrollbarImpl::~ScrollbarImpl() { +} + +cc::ScrollbarOrientation ScrollbarImpl::Orientation() const { + if (scrollbar_->orientation() == WebScrollbar::Horizontal) + return cc::HORIZONTAL; + return cc::VERTICAL; +} + +bool ScrollbarImpl::IsLeftSideVerticalScrollbar() const { + return scrollbar_->isLeftSideVerticalScrollbar(); +} + +bool ScrollbarImpl::HasThumb() const { + return geometry_->hasThumb(scrollbar_.get()); +} + +bool ScrollbarImpl::IsOverlay() const { + return scrollbar_->isOverlay(); +} + +gfx::Point ScrollbarImpl::Location() const { + return scrollbar_->location(); +} + +int ScrollbarImpl::ThumbThickness() const { + gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get()); + if (scrollbar_->orientation() == WebScrollbar::Horizontal) + return thumb_rect.height(); + return thumb_rect.width(); +} + +int ScrollbarImpl::ThumbLength() const { + gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get()); + if (scrollbar_->orientation() == WebScrollbar::Horizontal) + return thumb_rect.width(); + return thumb_rect.height(); +} + +gfx::Rect ScrollbarImpl::TrackRect() const { + return geometry_->trackRect(scrollbar_.get()); +} + +void ScrollbarImpl::PaintPart(SkCanvas* canvas, + cc::ScrollbarPart part, + const gfx::Rect& content_rect) { + if (part == cc::THUMB) { + painter_.paintThumb(canvas, content_rect); + return; + } + + // The following is a simplification of ScrollbarThemeComposite::paint. + painter_.paintScrollbarBackground(canvas, content_rect); + + if (geometry_->hasButtons(scrollbar_.get())) { + gfx::Rect back_button_start_paint_rect = + geometry_->backButtonStartRect(scrollbar_.get()); + painter_.paintBackButtonStart(canvas, back_button_start_paint_rect); + + gfx::Rect back_button_end_paint_rect = + geometry_->backButtonEndRect(scrollbar_.get()); + painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect); + + gfx::Rect forward_button_start_paint_rect = + geometry_->forwardButtonStartRect(scrollbar_.get()); + painter_.paintForwardButtonStart(canvas, forward_button_start_paint_rect); + + gfx::Rect forward_button_end_paint_rect = + geometry_->forwardButtonEndRect(scrollbar_.get()); + painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect); + } + + gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get()); + painter_.paintTrackBackground(canvas, track_paint_rect); + + bool thumb_present = geometry_->hasThumb(scrollbar_.get()); + if (thumb_present) { + painter_.paintForwardTrackPart(canvas, track_paint_rect); + painter_.paintBackTrackPart(canvas, track_paint_rect); + } + + painter_.paintTickmarks(canvas, track_paint_rect); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/scrollbar_impl.h b/content/renderer/compositor_bindings/scrollbar_impl.h new file mode 100644 index 0000000..9159d0a --- /dev/null +++ b/content/renderer/compositor_bindings/scrollbar_impl.h @@ -0,0 +1,51 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_SCROLLBAR_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_SCROLLBAR_IMPL_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "cc/input/scrollbar.h" +#include "third_party/WebKit/public/platform/WebScrollbarThemePainter.h" + +namespace blink { +class WebScrollbar; +class WebScrollbarThemeGeometry; +} + +namespace content { + +class ScrollbarImpl : public cc::Scrollbar { + public: + ScrollbarImpl(scoped_ptr<blink::WebScrollbar> scrollbar, + blink::WebScrollbarThemePainter painter, + scoped_ptr<blink::WebScrollbarThemeGeometry> geometry); + virtual ~ScrollbarImpl(); + + // cc::Scrollbar implementation. + virtual cc::ScrollbarOrientation Orientation() const OVERRIDE; + virtual bool IsLeftSideVerticalScrollbar() const OVERRIDE; + virtual bool HasThumb() const OVERRIDE; + virtual bool IsOverlay() const OVERRIDE; + virtual gfx::Point Location() const OVERRIDE; + virtual int ThumbThickness() const OVERRIDE; + virtual int ThumbLength() const OVERRIDE; + virtual gfx::Rect TrackRect() const OVERRIDE; + virtual void PaintPart(SkCanvas* canvas, + cc::ScrollbarPart part, + const gfx::Rect& content_rect) OVERRIDE; + + private: + scoped_ptr<blink::WebScrollbar> scrollbar_; + blink::WebScrollbarThemePainter painter_; + scoped_ptr<blink::WebScrollbarThemeGeometry> geometry_; + + DISALLOW_COPY_AND_ASSIGN(ScrollbarImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_SCROLLBAR_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_animation_curve_common.cc b/content/renderer/compositor_bindings/web_animation_curve_common.cc new file mode 100644 index 0000000..c5bb36d --- /dev/null +++ b/content/renderer/compositor_bindings/web_animation_curve_common.cc @@ -0,0 +1,29 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_animation_curve_common.h" + +#include "cc/animation/timing_function.h" + +namespace content { + +scoped_ptr<cc::TimingFunction> CreateTimingFunction( + blink::WebAnimationCurve::TimingFunctionType type) { + switch (type) { + case blink::WebAnimationCurve::TimingFunctionTypeEase: + return cc::EaseTimingFunction::Create(); + case blink::WebAnimationCurve::TimingFunctionTypeEaseIn: + return cc::EaseInTimingFunction::Create(); + case blink::WebAnimationCurve::TimingFunctionTypeEaseOut: + return cc::EaseOutTimingFunction::Create(); + case blink::WebAnimationCurve::TimingFunctionTypeEaseInOut: + return cc::EaseInOutTimingFunction::Create(); + case blink::WebAnimationCurve::TimingFunctionTypeLinear: + return scoped_ptr<cc::TimingFunction>(); + } + return scoped_ptr<cc::TimingFunction>(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_animation_curve_common.h b/content/renderer/compositor_bindings/web_animation_curve_common.h new file mode 100644 index 0000000..e0fd7c8 --- /dev/null +++ b/content/renderer/compositor_bindings/web_animation_curve_common.h @@ -0,0 +1,21 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_CURVE_COMMON_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_CURVE_COMMON_H_ + +#include "base/memory/scoped_ptr.h" +#include "third_party/WebKit/public/platform/WebAnimationCurve.h" + +namespace cc { +class TimingFunction; +} + +namespace content { +scoped_ptr<cc::TimingFunction> CreateTimingFunction( + blink::WebAnimationCurve::TimingFunctionType); +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_CURVE_COMMON_H_ + diff --git a/content/renderer/compositor_bindings/web_animation_impl.cc b/content/renderer/compositor_bindings/web_animation_impl.cc new file mode 100644 index 0000000..832aa6e --- /dev/null +++ b/content/renderer/compositor_bindings/web_animation_impl.cc @@ -0,0 +1,160 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_animation_impl.h" + +#include "cc/animation/animation.h" +#include "cc/animation/animation_curve.h" +#include "cc/animation/animation_id_provider.h" +#include "content/renderer/compositor_bindings/web_filter_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_transform_animation_curve_impl.h" +#include "third_party/WebKit/public/platform/WebAnimation.h" +#include "third_party/WebKit/public/platform/WebAnimationCurve.h" + +using cc::Animation; +using cc::AnimationIdProvider; + +using blink::WebAnimation; +using blink::WebAnimationCurve; + +namespace content { + +WebAnimationImpl::WebAnimationImpl(const WebAnimationCurve& web_curve, + TargetProperty target_property, + int animation_id, + int group_id) { + if (!animation_id) + animation_id = AnimationIdProvider::NextAnimationId(); + if (!group_id) + group_id = AnimationIdProvider::NextGroupId(); + + WebAnimationCurve::AnimationCurveType curve_type = web_curve.type(); + scoped_ptr<cc::AnimationCurve> curve; + switch (curve_type) { + case WebAnimationCurve::AnimationCurveTypeFloat: { + const WebFloatAnimationCurveImpl* float_curve_impl = + static_cast<const WebFloatAnimationCurveImpl*>(&web_curve); + curve = float_curve_impl->CloneToAnimationCurve(); + break; + } + case WebAnimationCurve::AnimationCurveTypeTransform: { + const WebTransformAnimationCurveImpl* transform_curve_impl = + static_cast<const WebTransformAnimationCurveImpl*>(&web_curve); + curve = transform_curve_impl->CloneToAnimationCurve(); + break; + } + case WebAnimationCurve::AnimationCurveTypeFilter: { + const WebFilterAnimationCurveImpl* filter_curve_impl = + static_cast<const WebFilterAnimationCurveImpl*>(&web_curve); + curve = filter_curve_impl->CloneToAnimationCurve(); + break; + } +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + case WebAnimationCurve::AnimationCurveTypeScrollOffset: { + const WebScrollOffsetAnimationCurveImpl* scroll_curve_impl = + static_cast<const WebScrollOffsetAnimationCurveImpl*>(&web_curve); + curve = scroll_curve_impl->CloneToAnimationCurve(); + break; + } +#endif + } + animation_ = Animation::Create( + curve.Pass(), + animation_id, + group_id, + static_cast<cc::Animation::TargetProperty>(target_property)); +} + +WebAnimationImpl::~WebAnimationImpl() { +} + +int WebAnimationImpl::id() { + return animation_->id(); +} + +blink::WebAnimation::TargetProperty WebAnimationImpl::targetProperty() const { + return static_cast<WebAnimationImpl::TargetProperty>( + animation_->target_property()); +} + +int WebAnimationImpl::iterations() const { + return animation_->iterations(); +} + +void WebAnimationImpl::setIterations(int n) { + animation_->set_iterations(n); +} + +double WebAnimationImpl::startTime() const { + return (animation_->start_time() - base::TimeTicks()).InSecondsF(); +} + +void WebAnimationImpl::setStartTime(double monotonic_time) { + animation_->set_start_time(base::TimeTicks::FromInternalValue( + monotonic_time * base::Time::kMicrosecondsPerSecond)); +} + +double WebAnimationImpl::timeOffset() const { + return animation_->time_offset().InSecondsF(); +} + +void WebAnimationImpl::setTimeOffset(double monotonic_time) { + animation_->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time)); +} + +#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION +blink::WebAnimation::Direction WebAnimationImpl::direction() const { + switch (animation_->direction()) { + case cc::Animation::Normal: + return DirectionNormal; + case cc::Animation::Reverse: + return DirectionReverse; + case cc::Animation::Alternate: + return DirectionAlternate; + case cc::Animation::AlternateReverse: + return DirectionAlternateReverse; + default: + NOTREACHED(); + } + return DirectionNormal; +} + +void WebAnimationImpl::setDirection(Direction direction) { + switch (direction) { + case DirectionNormal: + animation_->set_direction(cc::Animation::Normal); + break; + case DirectionReverse: + animation_->set_direction(cc::Animation::Reverse); + break; + case DirectionAlternate: + animation_->set_direction(cc::Animation::Alternate); + break; + case DirectionAlternateReverse: + animation_->set_direction(cc::Animation::AlternateReverse); + break; + } +} +#else +bool WebAnimationImpl::alternatesDirection() const { + return animation_->direction() == cc::Animation::Alternate; +} + +void WebAnimationImpl::setAlternatesDirection(bool alternates) { + if (alternates) + animation_->set_direction(cc::Animation::Alternate); + else + animation_->set_direction(cc::Animation::Normal); +} +#endif + +scoped_ptr<cc::Animation> WebAnimationImpl::PassAnimation() { + animation_->set_needs_synchronized_start_time(true); + return animation_.Pass(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_animation_impl.h b/content/renderer/compositor_bindings/web_animation_impl.h new file mode 100644 index 0000000..a706358 --- /dev/null +++ b/content/renderer/compositor_bindings/web_animation_impl.h @@ -0,0 +1,59 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebAnimation.h" + +namespace cc { +class Animation; +} + +namespace blink { +class WebAnimationCurve; +} + +namespace content { + +class WebAnimationImpl : public blink::WebAnimation { + public: + CONTENT_EXPORT WebAnimationImpl( + const blink::WebAnimationCurve& curve, + TargetProperty target, + int animation_id, + int group_id); + virtual ~WebAnimationImpl(); + + // blink::WebAnimation implementation + virtual int id(); + virtual TargetProperty targetProperty() const; + virtual int iterations() const; + virtual void setIterations(int iterations); + virtual double startTime() const; + virtual void setStartTime(double monotonic_time); + virtual double timeOffset() const; + virtual void setTimeOffset(double monotonic_time); +#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION + virtual Direction direction() const; + virtual void setDirection(Direction); +#else + virtual bool alternatesDirection() const; + virtual void setAlternatesDirection(bool alternates); +#endif + + scoped_ptr<cc::Animation> PassAnimation(); + + private: + scoped_ptr<cc::Animation> animation_; + + DISALLOW_COPY_AND_ASSIGN(WebAnimationImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_ANIMATION_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_animation_unittest.cc b/content/renderer/compositor_bindings/web_animation_unittest.cc new file mode 100644 index 0000000..b529c018 --- /dev/null +++ b/content/renderer/compositor_bindings/web_animation_unittest.cc @@ -0,0 +1,60 @@ +// Copyright 2014 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 "base/memory/scoped_ptr.h" +#include "content/renderer/compositor_bindings/web_animation_impl.h" +#include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h" +#include "testing/gtest/include/gtest/gtest.h" + +using blink::WebAnimation; +using blink::WebAnimationCurve; +using blink::WebFloatAnimationCurve; + +namespace content { +namespace { + +TEST(WebAnimationTest, DefaultSettings) { + scoped_ptr<WebAnimationCurve> curve(new WebFloatAnimationCurveImpl()); + scoped_ptr<WebAnimation> animation( + new WebAnimationImpl(*curve, WebAnimation::TargetPropertyOpacity, 1, 0)); + + // Ensure that the defaults are correct. + EXPECT_EQ(1, animation->iterations()); + EXPECT_EQ(0, animation->startTime()); + EXPECT_EQ(0, animation->timeOffset()); +#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION + EXPECT_EQ(WebAnimation::DirectionNormal, animation->direction()); +#else + EXPECT_FALSE(animation->alternatesDirection()); +#endif +} + +TEST(WebAnimationTest, ModifiedSettings) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl()); + scoped_ptr<WebAnimation> animation( + new WebAnimationImpl(*curve, WebAnimation::TargetPropertyOpacity, 1, 0)); + animation->setIterations(2); + animation->setStartTime(2); + animation->setTimeOffset(2); +#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION + animation->setDirection(WebAnimation::DirectionReverse); +#else + animation->setAlternatesDirection(true); +#endif + + EXPECT_EQ(2, animation->iterations()); + EXPECT_EQ(2, animation->startTime()); + EXPECT_EQ(2, animation->timeOffset()); +#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION + EXPECT_EQ(WebAnimation::DirectionReverse, animation->direction()); +#else + EXPECT_TRUE(animation->alternatesDirection()); + animation->setAlternatesDirection(false); + EXPECT_FALSE(animation->alternatesDirection()); +#endif +} + +} // namespace +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_blend_mode.h b/content/renderer/compositor_bindings/web_blend_mode.h new file mode 100644 index 0000000..6ab6ade --- /dev/null +++ b/content/renderer/compositor_bindings/web_blend_mode.h @@ -0,0 +1,107 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_BLEND_MODE_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_BLEND_MODE_H_ + +#include "third_party/WebKit/public/platform/WebBlendMode.h" + +namespace content { + +inline SkXfermode::Mode BlendModeToSkia(blink::WebBlendMode blend_mode) { + switch (blend_mode) { + case blink::WebBlendModeNormal: + return SkXfermode::kSrcOver_Mode; + case blink::WebBlendModeMultiply: + return SkXfermode::kMultiply_Mode; + case blink::WebBlendModeScreen: + return SkXfermode::kScreen_Mode; + case blink::WebBlendModeOverlay: + return SkXfermode::kOverlay_Mode; + case blink::WebBlendModeDarken: + return SkXfermode::kDarken_Mode; + case blink::WebBlendModeLighten: + return SkXfermode::kLighten_Mode; + case blink::WebBlendModeColorDodge: + return SkXfermode::kColorDodge_Mode; + case blink::WebBlendModeColorBurn: + return SkXfermode::kColorBurn_Mode; + case blink::WebBlendModeHardLight: + return SkXfermode::kHardLight_Mode; + case blink::WebBlendModeSoftLight: + return SkXfermode::kSoftLight_Mode; + case blink::WebBlendModeDifference: + return SkXfermode::kDifference_Mode; + case blink::WebBlendModeExclusion: + return SkXfermode::kExclusion_Mode; + case blink::WebBlendModeHue: + return SkXfermode::kHue_Mode; + case blink::WebBlendModeSaturation: + return SkXfermode::kSaturation_Mode; + case blink::WebBlendModeColor: + return SkXfermode::kColor_Mode; + case blink::WebBlendModeLuminosity: + return SkXfermode::kLuminosity_Mode; + } + return SkXfermode::kSrcOver_Mode; +} + +inline blink::WebBlendMode BlendModeFromSkia(SkXfermode::Mode blend_mode) { + switch (blend_mode) { + case SkXfermode::kSrcOver_Mode: + return blink::WebBlendModeNormal; + case SkXfermode::kMultiply_Mode: + return blink::WebBlendModeMultiply; + case SkXfermode::kScreen_Mode: + return blink::WebBlendModeScreen; + case SkXfermode::kOverlay_Mode: + return blink::WebBlendModeOverlay; + case SkXfermode::kDarken_Mode: + return blink::WebBlendModeDarken; + case SkXfermode::kLighten_Mode: + return blink::WebBlendModeLighten; + case SkXfermode::kColorDodge_Mode: + return blink::WebBlendModeColorDodge; + case SkXfermode::kColorBurn_Mode: + return blink::WebBlendModeColorBurn; + case SkXfermode::kHardLight_Mode: + return blink::WebBlendModeHardLight; + case SkXfermode::kSoftLight_Mode: + return blink::WebBlendModeSoftLight; + case SkXfermode::kDifference_Mode: + return blink::WebBlendModeDifference; + case SkXfermode::kExclusion_Mode: + return blink::WebBlendModeExclusion; + case SkXfermode::kHue_Mode: + return blink::WebBlendModeHue; + case SkXfermode::kSaturation_Mode: + return blink::WebBlendModeSaturation; + case SkXfermode::kColor_Mode: + return blink::WebBlendModeColor; + case SkXfermode::kLuminosity_Mode: + return blink::WebBlendModeLuminosity; + + // these value are SkXfermodes, but no blend modes. + case SkXfermode::kClear_Mode: + case SkXfermode::kSrc_Mode: + case SkXfermode::kDst_Mode: + case SkXfermode::kDstOver_Mode: + case SkXfermode::kSrcIn_Mode: + case SkXfermode::kDstIn_Mode: + case SkXfermode::kSrcOut_Mode: + case SkXfermode::kDstOut_Mode: + case SkXfermode::kSrcATop_Mode: + case SkXfermode::kDstATop_Mode: + case SkXfermode::kXor_Mode: + case SkXfermode::kPlus_Mode: + case SkXfermode::kModulate_Mode: + NOTREACHED(); + } + return blink::WebBlendModeNormal; +} + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_BLEND_MODE_H_ + diff --git a/content/renderer/compositor_bindings/web_compositor_support_impl.cc b/content/renderer/compositor_bindings/web_compositor_support_impl.cc new file mode 100644 index 0000000..0e4e6fa --- /dev/null +++ b/content/renderer/compositor_bindings/web_compositor_support_impl.cc @@ -0,0 +1,141 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_compositor_support_impl.h" + +#include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop_proxy.h" +#include "cc/animation/transform_operations.h" +#include "cc/output/output_surface.h" +#include "cc/output/software_output_device.h" +#include "content/renderer/compositor_bindings/web_animation_impl.h" +#include "content/renderer/compositor_bindings/web_content_layer_impl.h" +#include "content/renderer/compositor_bindings/web_external_texture_layer_impl.h" +#include "content/renderer/compositor_bindings/web_filter_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_filter_operations_impl.h" +#include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_image_layer_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "content/renderer/compositor_bindings/web_nine_patch_layer_impl.h" +#include "content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_scrollbar_layer_impl.h" +#include "content/renderer/compositor_bindings/web_solid_color_layer_impl.h" +#include "content/renderer/compositor_bindings/web_transform_animation_curve_impl.h" +#include "content/renderer/compositor_bindings/web_transform_operations_impl.h" + +using blink::WebAnimation; +using blink::WebAnimationCurve; +using blink::WebContentLayer; +using blink::WebContentLayerClient; +using blink::WebExternalTextureLayer; +using blink::WebExternalTextureLayerClient; +using blink::WebFilterAnimationCurve; +using blink::WebFilterOperations; +using blink::WebFloatAnimationCurve; +using blink::WebImageLayer; +using blink::WebNinePatchLayer; +using blink::WebLayer; +using blink::WebScrollbar; +using blink::WebScrollbarLayer; +using blink::WebScrollbarThemeGeometry; +using blink::WebScrollbarThemePainter; +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED +using blink::WebScrollOffsetAnimationCurve; +#endif +using blink::WebSolidColorLayer; +using blink::WebTransformAnimationCurve; +using blink::WebTransformOperations; + +namespace content { + +WebCompositorSupportImpl::WebCompositorSupportImpl() { +} + +WebCompositorSupportImpl::~WebCompositorSupportImpl() { +} + +WebLayer* WebCompositorSupportImpl::createLayer() { + return new WebLayerImpl(); +} + +WebContentLayer* WebCompositorSupportImpl::createContentLayer( + WebContentLayerClient* client) { + return new WebContentLayerImpl(client); +} + +WebExternalTextureLayer* WebCompositorSupportImpl::createExternalTextureLayer( + WebExternalTextureLayerClient* client) { + return new WebExternalTextureLayerImpl(client); +} + +blink::WebImageLayer* WebCompositorSupportImpl::createImageLayer() { + return new WebImageLayerImpl(); +} + +blink::WebNinePatchLayer* WebCompositorSupportImpl::createNinePatchLayer() { + return new WebNinePatchLayerImpl(); +} + +WebSolidColorLayer* WebCompositorSupportImpl::createSolidColorLayer() { + return new WebSolidColorLayerImpl(); +} + +WebScrollbarLayer* WebCompositorSupportImpl::createScrollbarLayer( + WebScrollbar* scrollbar, + WebScrollbarThemePainter painter, + WebScrollbarThemeGeometry* geometry) { + return new WebScrollbarLayerImpl(scrollbar, painter, geometry); +} + +WebScrollbarLayer* WebCompositorSupportImpl::createSolidColorScrollbarLayer( + WebScrollbar::Orientation orientation, + int thumb_thickness, + int track_start, + bool is_left_side_vertical_scrollbar) { + return new WebScrollbarLayerImpl(orientation, + thumb_thickness, + track_start, + is_left_side_vertical_scrollbar); +} + +WebAnimation* WebCompositorSupportImpl::createAnimation( + const blink::WebAnimationCurve& curve, + blink::WebAnimation::TargetProperty target, + int animation_id) { + return new WebAnimationImpl(curve, target, animation_id, 0); +} + +WebFilterAnimationCurve* +WebCompositorSupportImpl::createFilterAnimationCurve() { + return new WebFilterAnimationCurveImpl(); +} + +WebFloatAnimationCurve* WebCompositorSupportImpl::createFloatAnimationCurve() { + return new WebFloatAnimationCurveImpl(); +} + +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED +WebScrollOffsetAnimationCurve* +WebCompositorSupportImpl::createScrollOffsetAnimationCurve( + blink::WebFloatPoint target_value, + blink::WebAnimationCurve::TimingFunctionType timing_function) { + return new WebScrollOffsetAnimationCurveImpl(target_value, timing_function); +} +#endif + +WebTransformAnimationCurve* +WebCompositorSupportImpl::createTransformAnimationCurve() { + return new WebTransformAnimationCurveImpl(); +} + +WebTransformOperations* WebCompositorSupportImpl::createTransformOperations() { + return new WebTransformOperationsImpl(); +} + +WebFilterOperations* WebCompositorSupportImpl::createFilterOperations() { + return new WebFilterOperationsImpl(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_compositor_support_impl.h b/content/renderer/compositor_bindings/web_compositor_support_impl.h new file mode 100644 index 0000000..c7d5385 --- /dev/null +++ b/content/renderer/compositor_bindings/web_compositor_support_impl.h @@ -0,0 +1,68 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_COMPOSITOR_SUPPORT_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_COMPOSITOR_SUPPORT_IMPL_H_ + +#include "base/memory/ref_counted.h" +#include "base/message_loop/message_loop_proxy.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebAnimationCurve.h" +#include "third_party/WebKit/public/platform/WebCompositorSupport.h" +#include "third_party/WebKit/public/platform/WebLayer.h" +#include "third_party/WebKit/public/platform/WebTransformOperations.h" + +namespace blink { +class WebGraphicsContext3D; +} + +namespace content { + +class CONTENT_EXPORT WebCompositorSupportImpl + : public NON_EXPORTED_BASE(blink::WebCompositorSupport) { + public: + WebCompositorSupportImpl(); + virtual ~WebCompositorSupportImpl(); + + virtual blink::WebLayer* createLayer(); + virtual blink::WebContentLayer* createContentLayer( + blink::WebContentLayerClient* client); + virtual blink::WebExternalTextureLayer* createExternalTextureLayer( + blink::WebExternalTextureLayerClient* client); + virtual blink::WebImageLayer* createImageLayer(); + virtual blink::WebNinePatchLayer* createNinePatchLayer(); + virtual blink::WebSolidColorLayer* createSolidColorLayer(); + virtual blink::WebScrollbarLayer* createScrollbarLayer( + blink::WebScrollbar* scrollbar, + blink::WebScrollbarThemePainter painter, + blink::WebScrollbarThemeGeometry*); + virtual blink::WebScrollbarLayer* createSolidColorScrollbarLayer( + blink::WebScrollbar::Orientation orientation, + int thumb_thickness, + int track_start, + bool is_left_side_vertical_scrollbar); + virtual blink::WebAnimation* createAnimation( + const blink::WebAnimationCurve& curve, + blink::WebAnimation::TargetProperty target, + int animation_id); + virtual blink::WebFilterAnimationCurve* createFilterAnimationCurve(); + virtual blink::WebFloatAnimationCurve* createFloatAnimationCurve(); +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + virtual blink::WebScrollOffsetAnimationCurve* + createScrollOffsetAnimationCurve( + blink::WebFloatPoint target_value, + blink::WebAnimationCurve::TimingFunctionType timing_function); +#endif + virtual blink::WebTransformAnimationCurve* createTransformAnimationCurve(); + virtual blink::WebTransformOperations* createTransformOperations(); + virtual blink::WebFilterOperations* createFilterOperations(); + + private: + DISALLOW_COPY_AND_ASSIGN(WebCompositorSupportImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_COMPOSITOR_SUPPORT_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_content_layer_impl.cc b/content/renderer/compositor_bindings/web_content_layer_impl.cc new file mode 100644 index 0000000..1a1eb43 --- /dev/null +++ b/content/renderer/compositor_bindings/web_content_layer_impl.cc @@ -0,0 +1,90 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_content_layer_impl.h" + +#include "cc/layers/content_layer.h" +#include "cc/layers/picture_layer.h" +#include "third_party/WebKit/public/platform/WebContentLayerClient.h" +#include "third_party/WebKit/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/public/platform/WebFloatRect.h" +#include "third_party/WebKit/public/platform/WebRect.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/skia/include/utils/SkMatrix44.h" + +using cc::ContentLayer; +using cc::PictureLayer; + +namespace content { + +WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client) + : client_(client), ignore_lcd_text_change_(false) { + if (WebLayerImpl::UsingPictureLayer()) + layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this))); + else + layer_ = make_scoped_ptr(new WebLayerImpl(ContentLayer::Create(this))); + layer_->layer()->SetIsDrawable(true); + can_use_lcd_text_ = layer_->layer()->can_use_lcd_text(); +} + +WebContentLayerImpl::~WebContentLayerImpl() { + if (WebLayerImpl::UsingPictureLayer()) + static_cast<PictureLayer*>(layer_->layer())->ClearClient(); + else + static_cast<ContentLayer*>(layer_->layer())->ClearClient(); +} + +blink::WebLayer* WebContentLayerImpl::layer() { + return layer_.get(); +} + +void WebContentLayerImpl::setDoubleSided(bool double_sided) { + layer_->layer()->SetDoubleSided(double_sided); +} + +void WebContentLayerImpl::setDrawCheckerboardForMissingTiles(bool enable) { + layer_->layer()->SetDrawCheckerboardForMissingTiles(enable); +} + +void WebContentLayerImpl::PaintContents( + SkCanvas* canvas, + const gfx::Rect& clip, + gfx::RectF* opaque, + ContentLayerClient::GraphicsContextStatus graphics_context_status) { + if (!client_) + return; + + blink::WebFloatRect web_opaque; + client_->paintContents( + canvas, + clip, + can_use_lcd_text_, + web_opaque, + graphics_context_status == ContentLayerClient::GRAPHICS_CONTEXT_ENABLED + ? blink::WebContentLayerClient::GraphicsContextEnabled + : blink::WebContentLayerClient::GraphicsContextDisabled); + *opaque = web_opaque; +} + +void WebContentLayerImpl::DidChangeLayerCanUseLCDText() { + // It is important to make this comparison because the LCD text status + // here can get out of sync with that in the layer. + if (can_use_lcd_text_ == layer_->layer()->can_use_lcd_text()) + return; + + // LCD text cannot be enabled once disabled. + if (layer_->layer()->can_use_lcd_text() && ignore_lcd_text_change_) + return; + + can_use_lcd_text_ = layer_->layer()->can_use_lcd_text(); + ignore_lcd_text_change_ = true; + layer_->invalidate(); +} + +bool WebContentLayerImpl::FillsBoundsCompletely() const { + return false; +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_content_layer_impl.h b/content/renderer/compositor_bindings/web_content_layer_impl.h new file mode 100644 index 0000000..435acfd --- /dev/null +++ b/content/renderer/compositor_bindings/web_content_layer_impl.h @@ -0,0 +1,62 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_CONTENT_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_CONTENT_LAYER_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/layers/content_layer_client.h" +#include "content/common/content_export.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "third_party/WebKit/public/platform/WebContentLayer.h" + +namespace cc { +class IntRect; +class FloatRect; +} + +namespace blink { +class WebContentLayerClient; +} + +namespace content { + +class WebContentLayerImpl : public blink::WebContentLayer, + public cc::ContentLayerClient { + public: + CONTENT_EXPORT explicit WebContentLayerImpl( + blink::WebContentLayerClient*); + + // WebContentLayer implementation. + virtual blink::WebLayer* layer(); + virtual void setDoubleSided(bool double_sided); + virtual void setDrawCheckerboardForMissingTiles(bool checkerboard); + + protected: + virtual ~WebContentLayerImpl(); + + // ContentLayerClient implementation. + virtual void PaintContents(SkCanvas* canvas, + const gfx::Rect& clip, + gfx::RectF* opaque, + ContentLayerClient::GraphicsContextStatus + graphics_context_status) OVERRIDE; + virtual void DidChangeLayerCanUseLCDText() OVERRIDE; + virtual bool FillsBoundsCompletely() const OVERRIDE; + + scoped_ptr<WebLayerImpl> layer_; + blink::WebContentLayerClient* client_; + bool draws_content_; + + private: + bool can_use_lcd_text_; + bool ignore_lcd_text_change_; + + DISALLOW_COPY_AND_ASSIGN(WebContentLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_CONTENT_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_external_bitmap_impl.cc b/content/renderer/compositor_bindings/web_external_bitmap_impl.cc new file mode 100644 index 0000000..bf3d853 --- /dev/null +++ b/content/renderer/compositor_bindings/web_external_bitmap_impl.cc @@ -0,0 +1,47 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_external_bitmap_impl.h" + +#include "base/memory/shared_memory.h" + +namespace content { + +namespace { + +SharedMemoryAllocationFunction g_memory_allocator; + +} // namespace + +void SetSharedMemoryAllocationFunction( + SharedMemoryAllocationFunction allocator) { + g_memory_allocator = allocator; +} + +WebExternalBitmapImpl::WebExternalBitmapImpl() { +} + +WebExternalBitmapImpl::~WebExternalBitmapImpl() { +} + +void WebExternalBitmapImpl::setSize(blink::WebSize size) { + if (size != size_) { + size_t byte_size = size.width * size.height * 4; + shared_memory_ = g_memory_allocator(byte_size); + if (shared_memory_) + shared_memory_->Map(byte_size); + size_ = size; + } +} + +blink::WebSize WebExternalBitmapImpl::size() { + return size_; +} + +uint8* WebExternalBitmapImpl::pixels() { + return static_cast<uint8*>(shared_memory_->memory()); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_external_bitmap_impl.h b/content/renderer/compositor_bindings/web_external_bitmap_impl.h new file mode 100644 index 0000000..4d7769e --- /dev/null +++ b/content/renderer/compositor_bindings/web_external_bitmap_impl.h @@ -0,0 +1,47 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_BITMAP_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_BITMAP_IMPL_H_ + +#include "base/bind.h" +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebExternalBitmap.h" + +namespace base { +class SharedMemory; +} + +namespace content { + +typedef scoped_ptr<base::SharedMemory>(*SharedMemoryAllocationFunction)(size_t); + +// Sets the function that this will use to allocate shared memory. +CONTENT_EXPORT void SetSharedMemoryAllocationFunction( + SharedMemoryAllocationFunction); + +class WebExternalBitmapImpl : public blink::WebExternalBitmap { + public: + CONTENT_EXPORT explicit WebExternalBitmapImpl(); + virtual ~WebExternalBitmapImpl(); + + // blink::WebExternalBitmap implementation. + virtual blink::WebSize size() OVERRIDE; + virtual void setSize(blink::WebSize size) OVERRIDE; + virtual uint8* pixels() OVERRIDE; + + base::SharedMemory* shared_memory() { return shared_memory_.get(); } + + private: + scoped_ptr<base::SharedMemory> shared_memory_; + blink::WebSize size_; + + DISALLOW_COPY_AND_ASSIGN(WebExternalBitmapImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_BITMAP_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_external_texture_layer_impl.cc b/content/renderer/compositor_bindings/web_external_texture_layer_impl.cc new file mode 100644 index 0000000..9709d59 --- /dev/null +++ b/content/renderer/compositor_bindings/web_external_texture_layer_impl.cc @@ -0,0 +1,130 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_external_texture_layer_impl.h" + +#include "cc/layers/texture_layer.h" +#include "cc/resources/resource_update_queue.h" +#include "cc/resources/single_release_callback.h" +#include "cc/resources/texture_mailbox.h" +#include "content/renderer/compositor_bindings/web_external_bitmap_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" +#include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" +#include "third_party/WebKit/public/platform/WebFloatRect.h" +#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/khronos/GLES2/gl2.h" + +using cc::TextureLayer; +using cc::ResourceUpdateQueue; + +namespace content { + +WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( + blink::WebExternalTextureLayerClient* client) + : client_(client) { + cc::TextureLayerClient* cc_client = client_ ? this : NULL; + scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(cc_client); + layer->SetIsDrawable(true); + layer_.reset(new WebLayerImpl(layer)); +} + +WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { + static_cast<TextureLayer*>(layer_->layer())->ClearClient(); +} + +blink::WebLayer* WebExternalTextureLayerImpl::layer() { + return layer_.get(); +} + +void WebExternalTextureLayerImpl::clearTexture() { + TextureLayer* layer = static_cast<TextureLayer*>(layer_->layer()); + layer->ClearTexture(); +} + +void WebExternalTextureLayerImpl::setOpaque(bool opaque) { + static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); +} + +void WebExternalTextureLayerImpl::setPremultipliedAlpha( + bool premultiplied_alpha) { + static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( + premultiplied_alpha); +} + +void WebExternalTextureLayerImpl::setBlendBackgroundColor(bool blend) { + static_cast<TextureLayer*>(layer_->layer())->SetBlendBackgroundColor(blend); +} + +void WebExternalTextureLayerImpl::setRateLimitContext(bool rate_limit) { + static_cast<TextureLayer*>(layer_->layer())->SetRateLimitContext(rate_limit); +} + +bool WebExternalTextureLayerImpl::PrepareTextureMailbox( + cc::TextureMailbox* mailbox, + scoped_ptr<cc::SingleReleaseCallback>* release_callback, + bool use_shared_memory) { + blink::WebExternalTextureMailbox client_mailbox; + WebExternalBitmapImpl* bitmap = NULL; + + if (use_shared_memory) + bitmap = AllocateBitmap(); + if (!client_->prepareMailbox(&client_mailbox, bitmap)) { + if (bitmap) + free_bitmaps_.push_back(bitmap); + return false; + } + gpu::Mailbox name; + name.SetName(client_mailbox.name); + if (bitmap) { + *mailbox = cc::TextureMailbox(bitmap->shared_memory(), bitmap->size()); + } else { + *mailbox = + cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint); + } + mailbox->set_allow_overlay(client_mailbox.allowOverlay); + + if (mailbox->IsValid()) { + *release_callback = cc::SingleReleaseCallback::Create( + base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, + this->AsWeakPtr(), + client_mailbox, + bitmap)); + } + + return true; +} + +WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { + if (!free_bitmaps_.empty()) { + WebExternalBitmapImpl* result = free_bitmaps_.back(); + free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); + return result; + } + return new WebExternalBitmapImpl; +} + +// static +void WebExternalTextureLayerImpl::DidReleaseMailbox( + base::WeakPtr<WebExternalTextureLayerImpl> layer, + const blink::WebExternalTextureMailbox& mailbox, + WebExternalBitmapImpl* bitmap, + unsigned sync_point, + bool lost_resource) { + if (lost_resource || !layer) { + delete bitmap; + return; + } + + blink::WebExternalTextureMailbox available_mailbox; + memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); + available_mailbox.syncPoint = sync_point; + if (bitmap) + layer->free_bitmaps_.push_back(bitmap); + layer->client_->mailboxReleased(available_mailbox); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_external_texture_layer_impl.h b/content/renderer/compositor_bindings/web_external_texture_layer_impl.h new file mode 100644 index 0000000..bc46b93 --- /dev/null +++ b/content/renderer/compositor_bindings/web_external_texture_layer_impl.h @@ -0,0 +1,73 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_TEXTURE_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_TEXTURE_LAYER_IMPL_H_ + +#include "base/bind.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" +#include "cc/layers/texture_layer_client.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebExternalTextureLayer.h" + +namespace cc { +class SingleReleaseCallback; +class TextureMailbox; +} + +namespace blink { +struct WebFloatRect; +struct WebExternalTextureMailbox; +} + +namespace content { + +class WebLayerImpl; +class WebExternalBitmapImpl; + +class WebExternalTextureLayerImpl + : public blink::WebExternalTextureLayer, + public cc::TextureLayerClient, + public base::SupportsWeakPtr<WebExternalTextureLayerImpl> { + public: + CONTENT_EXPORT explicit WebExternalTextureLayerImpl( + blink::WebExternalTextureLayerClient*); + virtual ~WebExternalTextureLayerImpl(); + + // blink::WebExternalTextureLayer implementation. + virtual blink::WebLayer* layer(); + virtual void clearTexture(); + virtual void setOpaque(bool opaque); + virtual void setPremultipliedAlpha(bool premultiplied); + virtual void setBlendBackgroundColor(bool blend); + virtual void setRateLimitContext(bool rate_limit); + + // TextureLayerClient implementation. + virtual bool PrepareTextureMailbox( + cc::TextureMailbox* mailbox, + scoped_ptr<cc::SingleReleaseCallback>* release_callback, + bool use_shared_memory) OVERRIDE; + + private: + static void DidReleaseMailbox( + base::WeakPtr<WebExternalTextureLayerImpl> layer, + const blink::WebExternalTextureMailbox& mailbox, + WebExternalBitmapImpl* bitmap, + unsigned sync_point, + bool lost_resource); + + WebExternalBitmapImpl* AllocateBitmap(); + + blink::WebExternalTextureLayerClient* client_; + scoped_ptr<WebLayerImpl> layer_; + ScopedVector<WebExternalBitmapImpl> free_bitmaps_; + + DISALLOW_COPY_AND_ASSIGN(WebExternalTextureLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_EXTERNAL_TEXTURE_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_filter_animation_curve_impl.cc b/content/renderer/compositor_bindings/web_filter_animation_curve_impl.cc new file mode 100644 index 0000000..944726e --- /dev/null +++ b/content/renderer/compositor_bindings/web_filter_animation_curve_impl.cc @@ -0,0 +1,59 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_filter_animation_curve_impl.h" + +#include "cc/animation/keyframed_animation_curve.h" +#include "cc/animation/timing_function.h" +#include "cc/output/filter_operations.h" +#include "content/renderer/compositor_bindings/web_animation_curve_common.h" +#include "content/renderer/compositor_bindings/web_filter_operations_impl.h" + +using blink::WebFilterKeyframe; + +namespace content { + +WebFilterAnimationCurveImpl::WebFilterAnimationCurveImpl() + : curve_(cc::KeyframedFilterAnimationCurve::Create()) { +} + +WebFilterAnimationCurveImpl::~WebFilterAnimationCurveImpl() { +} + +blink::WebAnimationCurve::AnimationCurveType WebFilterAnimationCurveImpl::type() + const { + return WebAnimationCurve::AnimationCurveTypeFilter; +} + +void WebFilterAnimationCurveImpl::add(const WebFilterKeyframe& keyframe, + TimingFunctionType type) { + const cc::FilterOperations& filter_operations = + static_cast<const WebFilterOperationsImpl&>(keyframe.value()) + .AsFilterOperations(); + curve_->AddKeyframe(cc::FilterKeyframe::Create( + keyframe.time(), filter_operations, CreateTimingFunction(type))); +} + +void WebFilterAnimationCurveImpl::add(const WebFilterKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2) { + const cc::FilterOperations& filter_operations = + static_cast<const WebFilterOperationsImpl&>(keyframe.value()) + .AsFilterOperations(); + curve_->AddKeyframe(cc::FilterKeyframe::Create( + keyframe.time(), + filter_operations, + cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2) + .PassAs<cc::TimingFunction>())); +} + +scoped_ptr<cc::AnimationCurve> +WebFilterAnimationCurveImpl::CloneToAnimationCurve() const { + return curve_->Clone(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_filter_animation_curve_impl.h b/content/renderer/compositor_bindings/web_filter_animation_curve_impl.h new file mode 100644 index 0000000..82e8295 --- /dev/null +++ b/content/renderer/compositor_bindings/web_filter_animation_curve_impl.h @@ -0,0 +1,51 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_ANIMATION_CURVE_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_ANIMATION_CURVE_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebFilterAnimationCurve.h" + +namespace cc { +class AnimationCurve; +class KeyframedFilterAnimationCurve; +} + +namespace blink { +class WebFilterKeyframe; +} + +namespace content { + +class WebFilterAnimationCurveImpl : public blink::WebFilterAnimationCurve { + public: + CONTENT_EXPORT WebFilterAnimationCurveImpl(); + virtual ~WebFilterAnimationCurveImpl(); + + // blink::WebAnimationCurve implementation. + virtual AnimationCurveType type() const; + + // blink::WebFilterAnimationCurve implementation. + virtual void add(const blink::WebFilterKeyframe& keyframe, + TimingFunctionType type); + virtual void add(const blink::WebFilterKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2); + + scoped_ptr<cc::AnimationCurve> CloneToAnimationCurve() const; + + private: + scoped_ptr<cc::KeyframedFilterAnimationCurve> curve_; + + DISALLOW_COPY_AND_ASSIGN(WebFilterAnimationCurveImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_ANIMATION_CURVE_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_filter_operations_impl.cc b/content/renderer/compositor_bindings/web_filter_operations_impl.cc new file mode 100644 index 0000000..2a11ea8 --- /dev/null +++ b/content/renderer/compositor_bindings/web_filter_operations_impl.cc @@ -0,0 +1,96 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_filter_operations_impl.h" + +#include "base/basictypes.h" +#include "skia/ext/refptr.h" +#include "third_party/WebKit/public/platform/WebColor.h" +#include "third_party/WebKit/public/platform/WebPoint.h" +#include "third_party/skia/include/core/SkScalar.h" + +namespace content { + +WebFilterOperationsImpl::WebFilterOperationsImpl() { +} + +WebFilterOperationsImpl::~WebFilterOperationsImpl() { +} + +const cc::FilterOperations& WebFilterOperationsImpl::AsFilterOperations() + const { + return filter_operations_; +} + +void WebFilterOperationsImpl::appendGrayscaleFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateGrayscaleFilter(amount)); +} + +void WebFilterOperationsImpl::appendSepiaFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateSepiaFilter(amount)); +} + +void WebFilterOperationsImpl::appendSaturateFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateSaturateFilter(amount)); +} + +void WebFilterOperationsImpl::appendHueRotateFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateHueRotateFilter(amount)); +} + +void WebFilterOperationsImpl::appendInvertFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateInvertFilter(amount)); +} + +void WebFilterOperationsImpl::appendBrightnessFilter(float amount) { + filter_operations_.Append( + cc::FilterOperation::CreateBrightnessFilter(amount)); +} + +void WebFilterOperationsImpl::appendContrastFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateContrastFilter(amount)); +} + +void WebFilterOperationsImpl::appendOpacityFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateOpacityFilter(amount)); +} + +void WebFilterOperationsImpl::appendBlurFilter(float amount) { + filter_operations_.Append(cc::FilterOperation::CreateBlurFilter(amount)); +} + +void WebFilterOperationsImpl::appendDropShadowFilter(blink::WebPoint offset, + float std_deviation, + blink::WebColor color) { + filter_operations_.Append(cc::FilterOperation::CreateDropShadowFilter( + offset, std_deviation, color)); +} + +void WebFilterOperationsImpl::appendColorMatrixFilter(SkScalar matrix[20]) { + filter_operations_.Append( + cc::FilterOperation::CreateColorMatrixFilter(matrix)); +} + +void WebFilterOperationsImpl::appendZoomFilter(float amount, int inset) { + filter_operations_.Append( + cc::FilterOperation::CreateZoomFilter(amount, inset)); +} + +void WebFilterOperationsImpl::appendSaturatingBrightnessFilter(float amount) { + filter_operations_.Append( + cc::FilterOperation::CreateSaturatingBrightnessFilter(amount)); +} + +void WebFilterOperationsImpl::appendReferenceFilter( + SkImageFilter* image_filter) { + filter_operations_.Append( + cc::FilterOperation::CreateReferenceFilter(skia::SharePtr(image_filter))); +} + +void WebFilterOperationsImpl::clear() { + filter_operations_.Clear(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_filter_operations_impl.h b/content/renderer/compositor_bindings/web_filter_operations_impl.h new file mode 100644 index 0000000..d3020e6 --- /dev/null +++ b/content/renderer/compositor_bindings/web_filter_operations_impl.h @@ -0,0 +1,50 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_OPERATIONS_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_OPERATIONS_IMPL_H_ + +#include "cc/output/filter_operations.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebFilterOperations.h" + +namespace content { + +class WebFilterOperationsImpl : public blink::WebFilterOperations { + public: + CONTENT_EXPORT WebFilterOperationsImpl(); + virtual ~WebFilterOperationsImpl(); + + const cc::FilterOperations& AsFilterOperations() const; + + // Implementation of blink::WebFilterOperations methods + virtual void appendGrayscaleFilter(float amount); + virtual void appendSepiaFilter(float amount); + virtual void appendSaturateFilter(float amount); + virtual void appendHueRotateFilter(float amount); + virtual void appendInvertFilter(float amount); + virtual void appendBrightnessFilter(float amount); + virtual void appendContrastFilter(float amount); + virtual void appendOpacityFilter(float amount); + virtual void appendBlurFilter(float amount); + virtual void appendDropShadowFilter(blink::WebPoint offset, + float std_deviation, + blink::WebColor color); + virtual void appendColorMatrixFilter(SkScalar matrix[20]); + virtual void appendZoomFilter(float amount, int inset); + virtual void appendSaturatingBrightnessFilter(float amount); + virtual void appendReferenceFilter(SkImageFilter* image_filter); + + virtual void clear(); + + private: + cc::FilterOperations filter_operations_; + + DISALLOW_COPY_AND_ASSIGN(WebFilterOperationsImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FILTER_OPERATIONS_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_float_animation_curve_impl.cc b/content/renderer/compositor_bindings/web_float_animation_curve_impl.cc new file mode 100644 index 0000000..caa1f9b --- /dev/null +++ b/content/renderer/compositor_bindings/web_float_animation_curve_impl.cc @@ -0,0 +1,60 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_float_animation_curve_impl.h" + +#include "cc/animation/animation_curve.h" +#include "cc/animation/keyframed_animation_curve.h" +#include "cc/animation/timing_function.h" +#include "content/renderer/compositor_bindings/web_animation_curve_common.h" + +using blink::WebFloatKeyframe; + +namespace content { + +WebFloatAnimationCurveImpl::WebFloatAnimationCurveImpl() + : curve_(cc::KeyframedFloatAnimationCurve::Create()) { +} + +WebFloatAnimationCurveImpl::~WebFloatAnimationCurveImpl() { +} + +blink::WebAnimationCurve::AnimationCurveType + WebFloatAnimationCurveImpl::type() const { + return blink::WebAnimationCurve::AnimationCurveTypeFloat; +} + +void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe) { + add(keyframe, TimingFunctionTypeEase); +} + +void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe, + TimingFunctionType type) { + curve_->AddKeyframe(cc::FloatKeyframe::Create( + keyframe.time, keyframe.value, CreateTimingFunction(type))); +} + +void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2) { + curve_->AddKeyframe(cc::FloatKeyframe::Create( + keyframe.time, + keyframe.value, + cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2) + .PassAs<cc::TimingFunction>())); +} + +float WebFloatAnimationCurveImpl::getValue(double time) const { + return curve_->GetValue(time); +} + +scoped_ptr<cc::AnimationCurve> +WebFloatAnimationCurveImpl::CloneToAnimationCurve() const { + return curve_->Clone(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_float_animation_curve_impl.h b/content/renderer/compositor_bindings/web_float_animation_curve_impl.h new file mode 100644 index 0000000..4c67b41 --- /dev/null +++ b/content/renderer/compositor_bindings/web_float_animation_curve_impl.h @@ -0,0 +1,54 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FLOAT_ANIMATION_CURVE_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FLOAT_ANIMATION_CURVE_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebFloatAnimationCurve.h" + +namespace cc { +class AnimationCurve; +class KeyframedFloatAnimationCurve; +} + +namespace blink { +struct WebFloatKeyframe; +} + +namespace content { + +class WebFloatAnimationCurveImpl : public blink::WebFloatAnimationCurve { + public: + CONTENT_EXPORT WebFloatAnimationCurveImpl(); + virtual ~WebFloatAnimationCurveImpl(); + + // WebAnimationCurve implementation. + virtual AnimationCurveType type() const; + + // WebFloatAnimationCurve implementation. + virtual void add(const blink::WebFloatKeyframe& keyframe); + virtual void add(const blink::WebFloatKeyframe& keyframe, + TimingFunctionType type); + virtual void add(const blink::WebFloatKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2); + + virtual float getValue(double time) const; + + scoped_ptr<cc::AnimationCurve> CloneToAnimationCurve() const; + + private: + scoped_ptr<cc::KeyframedFloatAnimationCurve> curve_; + + DISALLOW_COPY_AND_ASSIGN(WebFloatAnimationCurveImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_FLOAT_ANIMATION_CURVE_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_float_animation_curve_unittest.cc b/content/renderer/compositor_bindings/web_float_animation_curve_unittest.cc new file mode 100644 index 0000000..bc7c410 --- /dev/null +++ b/content/renderer/compositor_bindings/web_float_animation_curve_unittest.cc @@ -0,0 +1,234 @@ +// Copyright 2014 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 "base/memory/scoped_ptr.h" +#include "cc/animation/timing_function.h" +#include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h" +#include "testing/gtest/include/gtest/gtest.h" + +using blink::WebAnimationCurve; +using blink::WebFloatAnimationCurve; +using blink::WebFloatKeyframe; + +namespace content { +namespace { + +// Tests that a float animation with one keyframe works as expected. +TEST(WebFloatAnimationCurveTest, OneFloatKeyframe) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 2), + WebAnimationCurve::TimingFunctionTypeLinear); + EXPECT_FLOAT_EQ(2, curve->getValue(-1)); + EXPECT_FLOAT_EQ(2, curve->getValue(0)); + EXPECT_FLOAT_EQ(2, curve->getValue(0.5)); + EXPECT_FLOAT_EQ(2, curve->getValue(1)); + EXPECT_FLOAT_EQ(2, curve->getValue(2)); +} + +// Tests that a float animation with two keyframes works as expected. +TEST(WebFloatAnimationCurveTest, TwoFloatKeyframe) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 2), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 4), + WebAnimationCurve::TimingFunctionTypeLinear); + EXPECT_FLOAT_EQ(2, curve->getValue(-1)); + EXPECT_FLOAT_EQ(2, curve->getValue(0)); + EXPECT_FLOAT_EQ(3, curve->getValue(0.5)); + EXPECT_FLOAT_EQ(4, curve->getValue(1)); + EXPECT_FLOAT_EQ(4, curve->getValue(2)); +} + +// Tests that a float animation with three keyframes works as expected. +TEST(WebFloatAnimationCurveTest, ThreeFloatKeyframe) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 2), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 4), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(2, 8), + WebAnimationCurve::TimingFunctionTypeLinear); + EXPECT_FLOAT_EQ(2, curve->getValue(-1)); + EXPECT_FLOAT_EQ(2, curve->getValue(0)); + EXPECT_FLOAT_EQ(3, curve->getValue(0.5)); + EXPECT_FLOAT_EQ(4, curve->getValue(1)); + EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); + EXPECT_FLOAT_EQ(8, curve->getValue(2)); + EXPECT_FLOAT_EQ(8, curve->getValue(3)); +} + +// Tests that a float animation with multiple keys at a given time works sanely. +TEST(WebFloatAnimationCurveTest, RepeatedFloatKeyTimes) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 4), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 4), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 6), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(2, 6), + WebAnimationCurve::TimingFunctionTypeLinear); + + EXPECT_FLOAT_EQ(4, curve->getValue(-1)); + EXPECT_FLOAT_EQ(4, curve->getValue(0)); + EXPECT_FLOAT_EQ(4, curve->getValue(0.5)); + + // There is a discontinuity at 1. Any value between 4 and 6 is valid. + float value = curve->getValue(1); + EXPECT_TRUE(value >= 4 && value <= 6); + + EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); + EXPECT_FLOAT_EQ(6, curve->getValue(2)); + EXPECT_FLOAT_EQ(6, curve->getValue(3)); +} + +// Tests that the keyframes may be added out of order. +TEST(WebFloatAnimationCurveTest, UnsortedKeyframes) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(2, 8), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(0, 2), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 4), + WebAnimationCurve::TimingFunctionTypeLinear); + + EXPECT_FLOAT_EQ(2, curve->getValue(-1)); + EXPECT_FLOAT_EQ(2, curve->getValue(0)); + EXPECT_FLOAT_EQ(3, curve->getValue(0.5)); + EXPECT_FLOAT_EQ(4, curve->getValue(1)); + EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); + EXPECT_FLOAT_EQ(8, curve->getValue(2)); + EXPECT_FLOAT_EQ(8, curve->getValue(3)); +} + +// Tests that a cubic bezier timing function works as expected. +TEST(WebFloatAnimationCurveTest, CubicBezierTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), 0.25, 0, 0.75, 1); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + EXPECT_FLOAT_EQ(0, curve->getValue(0)); + EXPECT_LT(0, curve->getValue(0.25)); + EXPECT_GT(0.25, curve->getValue(0.25)); + EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); + EXPECT_LT(0.75, curve->getValue(0.75)); + EXPECT_GT(1, curve->getValue(0.75)); + EXPECT_FLOAT_EQ(1, curve->getValue(1)); +} + +// Tests that an ease timing function works as expected. +TEST(WebFloatAnimationCurveTest, EaseTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), WebAnimationCurve::TimingFunctionTypeEase); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::EaseTimingFunction::Create()); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +// Tests using a linear timing function. +TEST(WebFloatAnimationCurveTest, LinearTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), + WebAnimationCurve::TimingFunctionTypeLinear); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(time, curve->getValue(time)); + } +} + +// Tests that an ease in timing function works as expected. +TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), + WebAnimationCurve::TimingFunctionTypeEaseIn); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::EaseInTimingFunction::Create()); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +// Tests that an ease in timing function works as expected. +TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), + WebAnimationCurve::TimingFunctionTypeEaseOut); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::EaseOutTimingFunction::Create()); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +// Tests that an ease in timing function works as expected. +TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0), + WebAnimationCurve::TimingFunctionTypeEaseInOut); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::EaseInOutTimingFunction::Create()); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +// Tests that an ease in timing function works as expected. +TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + double x1 = 0.3; + double y1 = 0.2; + double x2 = 0.8; + double y2 = 0.7; + curve->add(WebFloatKeyframe(0, 0), x1, y1, x2, y2); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +// Tests that the default timing function is indeed ease. +TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) { + scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); + curve->add(WebFloatKeyframe(0, 0)); + curve->add(WebFloatKeyframe(1, 1), + WebAnimationCurve::TimingFunctionTypeLinear); + + scoped_ptr<cc::TimingFunction> timing_function( + cc::EaseTimingFunction::Create()); + for (int i = 0; i <= 4; ++i) { + const double time = i * 0.25; + EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); + } +} + +} // namespace +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_image_layer_impl.cc b/content/renderer/compositor_bindings/web_image_layer_impl.cc new file mode 100644 index 0000000..ecbfbd0 --- /dev/null +++ b/content/renderer/compositor_bindings/web_image_layer_impl.cc @@ -0,0 +1,39 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_image_layer_impl.h" + +#include "cc/layers/image_layer.h" +#include "cc/layers/picture_image_layer.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h" + +namespace content { + +WebImageLayerImpl::WebImageLayerImpl() { + if (WebLayerImpl::UsingPictureLayer()) + layer_.reset(new WebLayerImplFixedBounds(cc::PictureImageLayer::Create())); + else + layer_.reset(new WebLayerImpl(cc::ImageLayer::Create())); +} + +WebImageLayerImpl::~WebImageLayerImpl() { +} + +blink::WebLayer* WebImageLayerImpl::layer() { + return layer_.get(); +} + +void WebImageLayerImpl::setBitmap(SkBitmap bitmap) { + if (WebLayerImpl::UsingPictureLayer()) { + static_cast<cc::PictureImageLayer*>(layer_->layer())->SetBitmap(bitmap); + static_cast<WebLayerImplFixedBounds*>(layer_.get())->SetFixedBounds( + gfx::Size(bitmap.width(), bitmap.height())); + } else { + static_cast<cc::ImageLayer*>(layer_->layer())->SetBitmap(bitmap); + } +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_image_layer_impl.h b/content/renderer/compositor_bindings/web_image_layer_impl.h new file mode 100644 index 0000000..359cfa5 --- /dev/null +++ b/content/renderer/compositor_bindings/web_image_layer_impl.h @@ -0,0 +1,35 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_IMAGE_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_IMAGE_LAYER_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebImageLayer.h" +#include "third_party/skia/include/core/SkBitmap.h" + +namespace content { + +class WebLayerImpl; + +class WebImageLayerImpl : public blink::WebImageLayer { + public: + CONTENT_EXPORT WebImageLayerImpl(); + virtual ~WebImageLayerImpl(); + + // blink::WebImageLayer implementation. + virtual blink::WebLayer* layer(); + virtual void setBitmap(SkBitmap); + + private: + scoped_ptr<WebLayerImpl> layer_; + + DISALLOW_COPY_AND_ASSIGN(WebImageLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_IMAGE_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_layer_impl.cc b/content/renderer/compositor_bindings/web_layer_impl.cc new file mode 100644 index 0000000..a575412 --- /dev/null +++ b/content/renderer/compositor_bindings/web_layer_impl.cc @@ -0,0 +1,489 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_layer_impl.h" + +#include "base/bind.h" +#include "base/debug/trace_event_impl.h" +#include "base/lazy_instance.h" +#include "base/strings/string_util.h" +#include "base/threading/thread_checker.h" +#include "cc/animation/animation.h" +#include "cc/base/region.h" +#include "cc/base/switches.h" +#include "cc/layers/layer.h" +#include "cc/layers/layer_position_constraint.h" +#include "cc/trees/layer_tree_host.h" +#include "content/renderer/compositor_bindings/web_animation_impl.h" +#include "content/renderer/compositor_bindings/web_blend_mode.h" +#include "content/renderer/compositor_bindings/web_filter_operations_impl.h" +#include "content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h" +#include "third_party/WebKit/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/public/platform/WebFloatRect.h" +#include "third_party/WebKit/public/platform/WebGraphicsLayerDebugInfo.h" +#include "third_party/WebKit/public/platform/WebLayerClient.h" +#include "third_party/WebKit/public/platform/WebLayerPositionConstraint.h" +#include "third_party/WebKit/public/platform/WebLayerScrollClient.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/skia/include/utils/SkMatrix44.h" + +using cc::Animation; +using cc::Layer; +using blink::WebLayer; +using blink::WebFloatPoint; +using blink::WebVector; +using blink::WebRect; +using blink::WebSize; +using blink::WebColor; +using blink::WebFilterOperations; + +namespace content { +namespace { + +bool g_impl_side_painting_enabled = false; + +} // namespace + +WebLayerImpl::WebLayerImpl() : layer_(Layer::Create()) { + web_layer_client_ = NULL; + layer_->SetLayerClient(this); +} + +WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) : layer_(layer) { + web_layer_client_ = NULL; + layer_->SetLayerClient(this); +} + +WebLayerImpl::~WebLayerImpl() { + layer_->ClearRenderSurface(); + layer_->set_layer_animation_delegate(NULL); + web_layer_client_ = NULL; +} + +// static +bool WebLayerImpl::UsingPictureLayer() { + return g_impl_side_painting_enabled; +} + +// static +void WebLayerImpl::SetImplSidePaintingEnabled(bool enabled) { + g_impl_side_painting_enabled = enabled; +} + +int WebLayerImpl::id() const { + return layer_->id(); +} + +void WebLayerImpl::invalidateRect(const blink::WebFloatRect& rect) { + layer_->SetNeedsDisplayRect(rect); +} + +void WebLayerImpl::invalidate() { + layer_->SetNeedsDisplay(); +} + +void WebLayerImpl::addChild(WebLayer* child) { + layer_->AddChild(static_cast<WebLayerImpl*>(child)->layer()); +} + +void WebLayerImpl::insertChild(WebLayer* child, size_t index) { + layer_->InsertChild(static_cast<WebLayerImpl*>(child)->layer(), index); +} + +void WebLayerImpl::replaceChild(WebLayer* reference, WebLayer* new_layer) { + layer_->ReplaceChild(static_cast<WebLayerImpl*>(reference)->layer(), + static_cast<WebLayerImpl*>(new_layer)->layer()); +} + +void WebLayerImpl::removeFromParent() { + layer_->RemoveFromParent(); +} + +void WebLayerImpl::removeAllChildren() { + layer_->RemoveAllChildren(); +} + +void WebLayerImpl::setBounds(const WebSize& size) { layer_->SetBounds(size); } + +WebSize WebLayerImpl::bounds() const { + return layer_->bounds(); +} + +void WebLayerImpl::setMasksToBounds(bool masks_to_bounds) { + layer_->SetMasksToBounds(masks_to_bounds); +} + +bool WebLayerImpl::masksToBounds() const { + return layer_->masks_to_bounds(); +} + +void WebLayerImpl::setMaskLayer(WebLayer* maskLayer) { + layer_->SetMaskLayer( + maskLayer ? static_cast<WebLayerImpl*>(maskLayer)->layer() : 0); +} + +void WebLayerImpl::setReplicaLayer(WebLayer* replica_layer) { + layer_->SetReplicaLayer( + replica_layer ? static_cast<WebLayerImpl*>(replica_layer)->layer() : 0); +} + +void WebLayerImpl::setOpacity(float opacity) { + layer_->SetOpacity(opacity); +} + +float WebLayerImpl::opacity() const { + return layer_->opacity(); +} + +void WebLayerImpl::setBlendMode(blink::WebBlendMode blend_mode) { + layer_->SetBlendMode(BlendModeToSkia(blend_mode)); +} + +blink::WebBlendMode WebLayerImpl::blendMode() const { + return BlendModeFromSkia(layer_->blend_mode()); +} + +void WebLayerImpl::setIsRootForIsolatedGroup(bool isolate) { + layer_->SetIsRootForIsolatedGroup(isolate); +} + +bool WebLayerImpl::isRootForIsolatedGroup() { + return layer_->is_root_for_isolated_group(); +} + +void WebLayerImpl::setOpaque(bool opaque) { + layer_->SetContentsOpaque(opaque); +} + +bool WebLayerImpl::opaque() const { + return layer_->contents_opaque(); +} + +void WebLayerImpl::setPosition(const WebFloatPoint& position) { + layer_->SetPosition(position); +} + +WebFloatPoint WebLayerImpl::position() const { + return layer_->position(); +} + +void WebLayerImpl::setTransform(const SkMatrix44& matrix) { + gfx::Transform transform; + transform.matrix() = matrix; + layer_->SetTransform(transform); +} + +void WebLayerImpl::setTransformOrigin(const blink::WebFloatPoint3D& point) { + gfx::Point3F gfx_point = point; + layer_->SetTransformOrigin(gfx_point); +} + +blink::WebFloatPoint3D WebLayerImpl::transformOrigin() const { + return layer_->transform_origin(); +} + +void WebLayerImpl::setAnchorPoint(const blink::WebFloatPoint&) {} + +blink::WebFloatPoint WebLayerImpl::anchorPoint() const { + return blink::WebFloatPoint(); +} + +void WebLayerImpl::setAnchorPointZ(float) {} + +float WebLayerImpl::anchorPointZ() const { + return 0.f; +}; + +SkMatrix44 WebLayerImpl::transform() const { + return layer_->transform().matrix(); +} + +void WebLayerImpl::setDrawsContent(bool draws_content) { + layer_->SetIsDrawable(draws_content); +} + +bool WebLayerImpl::drawsContent() const { + return layer_->DrawsContent(); +} + +void WebLayerImpl::setShouldFlattenTransform(bool flatten) { + layer_->SetShouldFlattenTransform(flatten); +} + +void WebLayerImpl::setRenderingContext(int context) { + layer_->SetIs3dSorted(context != 0); +} + +void WebLayerImpl::setUseParentBackfaceVisibility( + bool use_parent_backface_visibility) { + layer_->set_use_parent_backface_visibility(use_parent_backface_visibility); +} + +void WebLayerImpl::setBackgroundColor(WebColor color) { + layer_->SetBackgroundColor(color); +} + +WebColor WebLayerImpl::backgroundColor() const { + return layer_->background_color(); +} + +void WebLayerImpl::setFilters(const WebFilterOperations& filters) { + const WebFilterOperationsImpl& filters_impl = + static_cast<const WebFilterOperationsImpl&>(filters); + layer_->SetFilters(filters_impl.AsFilterOperations()); +} + +void WebLayerImpl::setBackgroundFilters(const WebFilterOperations& filters) { + const WebFilterOperationsImpl& filters_impl = + static_cast<const WebFilterOperationsImpl&>(filters); + layer_->SetBackgroundFilters(filters_impl.AsFilterOperations()); +} + +void WebLayerImpl::setAnimationDelegate(blink::WebAnimationDelegate* delegate) { + animation_delegate_adapter_.reset( + new WebToCCAnimationDelegateAdapter(delegate)); + layer_->set_layer_animation_delegate(animation_delegate_adapter_.get()); +} + +bool WebLayerImpl::addAnimation(blink::WebAnimation* animation) { + bool result = layer_->AddAnimation( + static_cast<WebAnimationImpl*>(animation)->PassAnimation()); + delete animation; + return result; +} + +void WebLayerImpl::removeAnimation(int animation_id) { + layer_->RemoveAnimation(animation_id); +} + +void WebLayerImpl::removeAnimation( + int animation_id, + blink::WebAnimation::TargetProperty target_property) { + layer_->layer_animation_controller()->RemoveAnimation( + animation_id, static_cast<Animation::TargetProperty>(target_property)); +} + +void WebLayerImpl::pauseAnimation(int animation_id, double time_offset) { + layer_->PauseAnimation(animation_id, time_offset); +} + +bool WebLayerImpl::hasActiveAnimation() { + return layer_->HasActiveAnimation(); +} + +void WebLayerImpl::setForceRenderSurface(bool force_render_surface) { + layer_->SetForceRenderSurface(force_render_surface); +} + +void WebLayerImpl::setScrollPosition(blink::WebPoint position) { + layer_->SetScrollOffset(gfx::Point(position).OffsetFromOrigin()); +} + +blink::WebPoint WebLayerImpl::scrollPosition() const { + return gfx::PointAtOffsetFromOrigin(layer_->scroll_offset()); +} + +void WebLayerImpl::setScrollClipLayer(WebLayer* clip_layer) { + if (!clip_layer) { + layer_->SetScrollClipLayerId(Layer::INVALID_ID); + return; + } + layer_->SetScrollClipLayerId(clip_layer->id()); +} + +bool WebLayerImpl::scrollable() const { + return layer_->scrollable(); +} + +void WebLayerImpl::setUserScrollable(bool horizontal, bool vertical) { + layer_->SetUserScrollable(horizontal, vertical); +} + +bool WebLayerImpl::userScrollableHorizontal() const { + return layer_->user_scrollable_horizontal(); +} + +bool WebLayerImpl::userScrollableVertical() const { + return layer_->user_scrollable_vertical(); +} + +void WebLayerImpl::setHaveWheelEventHandlers(bool have_wheel_event_handlers) { + layer_->SetHaveWheelEventHandlers(have_wheel_event_handlers); +} + +bool WebLayerImpl::haveWheelEventHandlers() const { + return layer_->have_wheel_event_handlers(); +} + +void WebLayerImpl::setHaveScrollEventHandlers(bool have_scroll_event_handlers) { + layer_->SetHaveScrollEventHandlers(have_scroll_event_handlers); +} + +bool WebLayerImpl::haveScrollEventHandlers() const { + return layer_->have_scroll_event_handlers(); +} + +void WebLayerImpl::setShouldScrollOnMainThread( + bool should_scroll_on_main_thread) { + layer_->SetShouldScrollOnMainThread(should_scroll_on_main_thread); +} + +bool WebLayerImpl::shouldScrollOnMainThread() const { + return layer_->should_scroll_on_main_thread(); +} + +void WebLayerImpl::setNonFastScrollableRegion(const WebVector<WebRect>& rects) { + cc::Region region; + for (size_t i = 0; i < rects.size(); ++i) + region.Union(rects[i]); + layer_->SetNonFastScrollableRegion(region); +} + +WebVector<WebRect> WebLayerImpl::nonFastScrollableRegion() const { + size_t num_rects = 0; + for (cc::Region::Iterator region_rects(layer_->non_fast_scrollable_region()); + region_rects.has_rect(); + region_rects.next()) + ++num_rects; + + WebVector<WebRect> result(num_rects); + size_t i = 0; + for (cc::Region::Iterator region_rects(layer_->non_fast_scrollable_region()); + region_rects.has_rect(); + region_rects.next()) { + result[i] = region_rects.rect(); + ++i; + } + return result; +} + +void WebLayerImpl::setTouchEventHandlerRegion(const WebVector<WebRect>& rects) { + cc::Region region; + for (size_t i = 0; i < rects.size(); ++i) + region.Union(rects[i]); + layer_->SetTouchEventHandlerRegion(region); +} + +WebVector<WebRect> WebLayerImpl::touchEventHandlerRegion() const { + size_t num_rects = 0; + for (cc::Region::Iterator region_rects(layer_->touch_event_handler_region()); + region_rects.has_rect(); + region_rects.next()) + ++num_rects; + + WebVector<WebRect> result(num_rects); + size_t i = 0; + for (cc::Region::Iterator region_rects(layer_->touch_event_handler_region()); + region_rects.has_rect(); + region_rects.next()) { + result[i] = region_rects.rect(); + ++i; + } + return result; +} + +void WebLayerImpl::setIsContainerForFixedPositionLayers(bool enable) { + layer_->SetIsContainerForFixedPositionLayers(enable); +} + +bool WebLayerImpl::isContainerForFixedPositionLayers() const { + return layer_->IsContainerForFixedPositionLayers(); +} + +static blink::WebLayerPositionConstraint ToWebLayerPositionConstraint( + const cc::LayerPositionConstraint& constraint) { + blink::WebLayerPositionConstraint web_constraint; + web_constraint.isFixedPosition = constraint.is_fixed_position(); + web_constraint.isFixedToRightEdge = constraint.is_fixed_to_right_edge(); + web_constraint.isFixedToBottomEdge = constraint.is_fixed_to_bottom_edge(); + return web_constraint; +} + +static cc::LayerPositionConstraint ToLayerPositionConstraint( + const blink::WebLayerPositionConstraint& web_constraint) { + cc::LayerPositionConstraint constraint; + constraint.set_is_fixed_position(web_constraint.isFixedPosition); + constraint.set_is_fixed_to_right_edge(web_constraint.isFixedToRightEdge); + constraint.set_is_fixed_to_bottom_edge(web_constraint.isFixedToBottomEdge); + return constraint; +} + +void WebLayerImpl::setPositionConstraint( + const blink::WebLayerPositionConstraint& constraint) { + layer_->SetPositionConstraint(ToLayerPositionConstraint(constraint)); +} + +blink::WebLayerPositionConstraint WebLayerImpl::positionConstraint() const { + return ToWebLayerPositionConstraint(layer_->position_constraint()); +} + +void WebLayerImpl::setScrollClient(blink::WebLayerScrollClient* scroll_client) { + if (scroll_client) { + layer_->set_did_scroll_callback( + base::Bind(&blink::WebLayerScrollClient::didScroll, + base::Unretained(scroll_client))); + } else { + layer_->set_did_scroll_callback(base::Closure()); + } +} + +bool WebLayerImpl::isOrphan() const { + return !layer_->layer_tree_host(); +} + +void WebLayerImpl::setWebLayerClient(blink::WebLayerClient* client) { + web_layer_client_ = client; +} + +class TracedDebugInfo : public base::debug::ConvertableToTraceFormat { + public: + // This object takes ownership of the debug_info object. + explicit TracedDebugInfo(blink::WebGraphicsLayerDebugInfo* debug_info) + : debug_info_(debug_info) {} + virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { + DCHECK(thread_checker_.CalledOnValidThread()); + blink::WebString web_string; + debug_info_->appendAsTraceFormat(&web_string); + out->append(web_string.utf8()); + } + + private: + virtual ~TracedDebugInfo() {} + scoped_ptr<blink::WebGraphicsLayerDebugInfo> debug_info_; + base::ThreadChecker thread_checker_; +}; + +scoped_refptr<base::debug::ConvertableToTraceFormat> +WebLayerImpl::TakeDebugInfo() { + if (!web_layer_client_) + return NULL; + blink::WebGraphicsLayerDebugInfo* debug_info = + web_layer_client_->takeDebugInfoFor(this); + + if (debug_info) + return new TracedDebugInfo(debug_info); + else + return NULL; +} + +void WebLayerImpl::setScrollParent(blink::WebLayer* parent) { + cc::Layer* scroll_parent = NULL; + if (parent) + scroll_parent = static_cast<WebLayerImpl*>(parent)->layer(); + layer_->SetScrollParent(scroll_parent); +} + +void WebLayerImpl::setClipParent(blink::WebLayer* parent) { + cc::Layer* clip_parent = NULL; + if (parent) + clip_parent = static_cast<WebLayerImpl*>(parent)->layer(); + layer_->SetClipParent(clip_parent); +} + +Layer* WebLayerImpl::layer() const { + return layer_.get(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_layer_impl.h b/content/renderer/compositor_bindings/web_layer_impl.h new file mode 100644 index 0000000..72f2b347 --- /dev/null +++ b/content/renderer/compositor_bindings/web_layer_impl.h @@ -0,0 +1,161 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_H_ + +#include <string> + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "cc/layers/layer_client.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebAnimation.h" +#include "third_party/WebKit/public/platform/WebCString.h" +#include "third_party/WebKit/public/platform/WebColor.h" +#include "third_party/WebKit/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/public/platform/WebLayer.h" +#include "third_party/WebKit/public/platform/WebPoint.h" +#include "third_party/WebKit/public/platform/WebRect.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/WebKit/public/platform/WebString.h" +#include "third_party/WebKit/public/platform/WebVector.h" +#include "third_party/skia/include/utils/SkMatrix44.h" + +namespace cc { +class Layer; +} + +namespace blink { +class WebFilterOperations; +class WebLayerClient; +struct WebFloatRect; +} + +namespace base { +namespace debug { +class ConvertableToTraceFormat; +} +} + +namespace content { + +class WebToCCAnimationDelegateAdapter; + +class WebLayerImpl : public blink::WebLayer, public cc::LayerClient { + public: + CONTENT_EXPORT WebLayerImpl(); + CONTENT_EXPORT explicit WebLayerImpl( + scoped_refptr<cc::Layer>); + virtual ~WebLayerImpl(); + + static bool UsingPictureLayer(); + CONTENT_EXPORT static void SetImplSidePaintingEnabled( + bool enabled); + + CONTENT_EXPORT cc::Layer* layer() const; + + // WebLayer implementation. + virtual int id() const; + virtual void invalidateRect(const blink::WebFloatRect&); + virtual void invalidate(); + virtual void addChild(blink::WebLayer* child); + virtual void insertChild(blink::WebLayer* child, size_t index); + virtual void replaceChild(blink::WebLayer* reference, + blink::WebLayer* new_layer); + virtual void removeFromParent(); + virtual void removeAllChildren(); + virtual void setBounds(const blink::WebSize& bounds); + virtual blink::WebSize bounds() const; + virtual void setMasksToBounds(bool masks_to_bounds); + virtual bool masksToBounds() const; + virtual void setMaskLayer(blink::WebLayer* mask); + virtual void setReplicaLayer(blink::WebLayer* replica); + virtual void setOpacity(float opacity); + virtual float opacity() const; + virtual void setBlendMode(blink::WebBlendMode blend_mode); + virtual blink::WebBlendMode blendMode() const; + virtual void setIsRootForIsolatedGroup(bool root); + virtual bool isRootForIsolatedGroup(); + virtual void setOpaque(bool opaque); + virtual bool opaque() const; + virtual void setPosition(const blink::WebFloatPoint& position); + virtual blink::WebFloatPoint position() const; + virtual void setTransform(const SkMatrix44& transform); + virtual void setTransformOrigin(const blink::WebFloatPoint3D& point); + virtual blink::WebFloatPoint3D transformOrigin() const; + + // FIXME: get rid of these once Blink is no longer using them. + virtual void setAnchorPoint(const blink::WebFloatPoint&); + virtual blink::WebFloatPoint anchorPoint() const; + virtual void setAnchorPointZ(float); + virtual float anchorPointZ() const ; + + virtual SkMatrix44 transform() const; + virtual void setDrawsContent(bool draws_content); + virtual bool drawsContent() const; + virtual void setShouldFlattenTransform(bool flatten); + virtual void setRenderingContext(int context); + virtual void setUseParentBackfaceVisibility(bool visible); + virtual void setBackgroundColor(blink::WebColor color); + virtual blink::WebColor backgroundColor() const; + virtual void setFilters(const blink::WebFilterOperations& filters); + virtual void setBackgroundFilters(const blink::WebFilterOperations& filters); + virtual void setAnimationDelegate(blink::WebAnimationDelegate* delegate); + virtual bool addAnimation(blink::WebAnimation* animation); + virtual void removeAnimation(int animation_id); + virtual void removeAnimation(int animation_id, + blink::WebAnimation::TargetProperty); + virtual void pauseAnimation(int animation_id, double time_offset); + virtual bool hasActiveAnimation(); + virtual void setForceRenderSurface(bool force); + virtual void setScrollPosition(blink::WebPoint position); + virtual blink::WebPoint scrollPosition() const; + virtual void setScrollClipLayer(blink::WebLayer* clip_layer); + virtual bool scrollable() const; + virtual void setUserScrollable(bool horizontal, bool vertical); + virtual bool userScrollableHorizontal() const; + virtual bool userScrollableVertical() const; + virtual void setHaveWheelEventHandlers(bool have_wheel_event_handlers); + virtual bool haveWheelEventHandlers() const; + virtual void setHaveScrollEventHandlers(bool have_scroll_event_handlers); + virtual bool haveScrollEventHandlers() const; + virtual void setShouldScrollOnMainThread(bool scroll_on_main); + virtual bool shouldScrollOnMainThread() const; + virtual void setNonFastScrollableRegion( + const blink::WebVector<blink::WebRect>& region); + virtual blink::WebVector<blink::WebRect> nonFastScrollableRegion() const; + virtual void setTouchEventHandlerRegion( + const blink::WebVector<blink::WebRect>& region); + virtual blink::WebVector<blink::WebRect> touchEventHandlerRegion() const; + virtual void setIsContainerForFixedPositionLayers(bool is_container); + virtual bool isContainerForFixedPositionLayers() const; + virtual void setPositionConstraint( + const blink::WebLayerPositionConstraint& constraint); + virtual blink::WebLayerPositionConstraint positionConstraint() const; + virtual void setScrollClient(blink::WebLayerScrollClient* client); + virtual bool isOrphan() const; + virtual void setWebLayerClient(blink::WebLayerClient* client); + + // LayerClient implementation. + virtual scoped_refptr<base::debug::ConvertableToTraceFormat> + TakeDebugInfo() OVERRIDE; + + virtual void setScrollParent(blink::WebLayer* parent); + virtual void setClipParent(blink::WebLayer* parent); + + protected: + scoped_refptr<cc::Layer> layer_; + blink::WebLayerClient* web_layer_client_; + + private: + scoped_ptr<WebToCCAnimationDelegateAdapter> animation_delegate_adapter_; + + DISALLOW_COPY_AND_ASSIGN(WebLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.cc b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.cc new file mode 100644 index 0000000..b3195f9 --- /dev/null +++ b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.cc @@ -0,0 +1,101 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h" + +#include "cc/layers/layer.h" +#include "third_party/WebKit/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/skia/include/utils/SkMatrix44.h" + +using cc::Layer; + +namespace content { + +WebLayerImplFixedBounds::WebLayerImplFixedBounds() { +} + +WebLayerImplFixedBounds::WebLayerImplFixedBounds(scoped_refptr<Layer> layer) + : WebLayerImpl(layer) { +} + +WebLayerImplFixedBounds::~WebLayerImplFixedBounds() { +} + +void WebLayerImplFixedBounds::invalidateRect(const blink::WebFloatRect& rect) { + // Partial invalidations seldom occur for such layers. + // Simply invalidate the whole layer to avoid transformation of coordinates. + invalidate(); +} + +void WebLayerImplFixedBounds::setTransformOrigin( + const blink::WebFloatPoint3D& transform_origin) { + if (transform_origin != this->transformOrigin()) { + layer_->SetTransformOrigin(transform_origin); + UpdateLayerBoundsAndTransform(); + } +} + +void WebLayerImplFixedBounds::setBounds(const blink::WebSize& bounds) { + if (original_bounds_ != gfx::Size(bounds)) { + original_bounds_ = bounds; + UpdateLayerBoundsAndTransform(); + } +} + +blink::WebSize WebLayerImplFixedBounds::bounds() const { + return original_bounds_; +} + +void WebLayerImplFixedBounds::setTransform(const SkMatrix44& matrix) { + gfx::Transform transform; + transform.matrix() = matrix; + SetTransformInternal(transform); +} + +SkMatrix44 WebLayerImplFixedBounds::transform() const { + return original_transform_.matrix(); +} + +void WebLayerImplFixedBounds::SetFixedBounds(gfx::Size fixed_bounds) { + if (fixed_bounds_ != fixed_bounds) { + fixed_bounds_ = fixed_bounds; + UpdateLayerBoundsAndTransform(); + } +} + +void WebLayerImplFixedBounds::SetTransformInternal( + const gfx::Transform& transform) { + if (original_transform_ != transform) { + original_transform_ = transform; + UpdateLayerBoundsAndTransform(); + } +} + +void WebLayerImplFixedBounds::UpdateLayerBoundsAndTransform() { + if (fixed_bounds_.IsEmpty() || original_bounds_.IsEmpty() || + fixed_bounds_ == original_bounds_ || + // For now fall back to non-fixed bounds for non-zero transform origin. + // TODO(wangxianzhu): Support non-zero anchor point for fixed bounds. + transformOrigin().x || + transformOrigin().y) { + layer_->SetBounds(original_bounds_); + layer_->SetTransform(original_transform_); + return; + } + + layer_->SetBounds(fixed_bounds_); + + // Apply bounds scale (bounds/fixed_bounds) over original transform. + gfx::Transform transform_with_bounds_scale(original_transform_); + float bounds_scale_x = + static_cast<float>(original_bounds_.width()) / fixed_bounds_.width(); + float bounds_scale_y = + static_cast<float>(original_bounds_.height()) / fixed_bounds_.height(); + transform_with_bounds_scale.Scale(bounds_scale_x, bounds_scale_y); + layer_->SetTransform(transform_with_bounds_scale); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h new file mode 100644 index 0000000..2048666f --- /dev/null +++ b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h @@ -0,0 +1,52 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_FIXED_BOUNDS_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_FIXED_BOUNDS_H_ + +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "ui/gfx/size.h" +#include "ui/gfx/transform.h" + +namespace content { + +// A special implementation of WebLayerImpl for layers that its contents +// need to be automatically scaled when the bounds changes. The compositor +// can efficiently handle the bounds change of such layers if the bounds +// is fixed to a given value and the change of bounds are converted to +// transformation scales. +class WebLayerImplFixedBounds : public WebLayerImpl { + public: + CONTENT_EXPORT WebLayerImplFixedBounds(); + CONTENT_EXPORT explicit WebLayerImplFixedBounds( + scoped_refptr<cc::Layer>); + virtual ~WebLayerImplFixedBounds(); + + // WebLayerImpl overrides. + virtual void invalidateRect(const blink::WebFloatRect& rect); + virtual void setTransformOrigin( + const blink::WebFloatPoint3D& transform_origin); + virtual void setBounds(const blink::WebSize& bounds); + virtual blink::WebSize bounds() const; + virtual void setTransform(const SkMatrix44& transform); + virtual SkMatrix44 transform() const; + + CONTENT_EXPORT void SetFixedBounds(gfx::Size bounds); + + protected: + void SetTransformInternal(const gfx::Transform& transform); + void UpdateLayerBoundsAndTransform(); + + gfx::Transform original_transform_; + gfx::Size original_bounds_; + gfx::Size fixed_bounds_; + + private: + DISALLOW_COPY_AND_ASSIGN(WebLayerImplFixedBounds); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_LAYER_IMPL_FIXED_BOUNDS_H_ + diff --git a/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc new file mode 100644 index 0000000..1935e20 --- /dev/null +++ b/content/renderer/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc @@ -0,0 +1,168 @@ +// Copyright 2014 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 <vector> +#include "cc/layers/picture_image_layer.h" +#include "cc/test/fake_layer_tree_host.h" +#include "cc/test/geometry_test_utils.h" +#include "cc/trees/layer_tree_host_common.h" +#include "content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/public/platform/WebFloatPoint.h" +#include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/skia/include/utils/SkMatrix44.h" +#include "ui/gfx/point3_f.h" + +using blink::WebFloatPoint; +using blink::WebSize; + +namespace content { +namespace { + +TEST(WebLayerImplFixedBoundsTest, IdentityBounds) { + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); + layer->setAnchorPoint(WebFloatPoint(0, 0)); + layer->SetFixedBounds(gfx::Size(100, 100)); + layer->setBounds(WebSize(100, 100)); + EXPECT_EQ(WebSize(100, 100), layer->bounds()); + EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); + EXPECT_EQ(gfx::Transform(), layer->layer()->transform()); +} + +gfx::Point3F TransformPoint(const gfx::Transform& transform, + const gfx::Point3F& point) { + gfx::Point3F result = point; + transform.TransformPoint(&result); + return result; +} + +void CheckBoundsScaleSimple(WebLayerImplFixedBounds* layer, + const WebSize& bounds, + const gfx::Size& fixed_bounds) { + layer->setBounds(bounds); + layer->SetFixedBounds(fixed_bounds); + + EXPECT_EQ(bounds, layer->bounds()); + EXPECT_EQ(fixed_bounds, layer->layer()->bounds()); + EXPECT_TRUE(layer->transform().isIdentity()); + + // An arbitrary point to check the scale and transforms. + gfx::Point3F original_point(10, 20, 1); + gfx::Point3F scaled_point( + original_point.x() * bounds.width / fixed_bounds.width(), + original_point.y() * bounds.height / fixed_bounds.height(), + original_point.z()); + // Test if the bounds scale is correctly applied in transform. + EXPECT_POINT3F_EQ( + scaled_point, + TransformPoint(layer->layer()->transform(), original_point)); +} + +TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) { + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); + layer->setAnchorPoint(WebFloatPoint(0, 0)); + CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250)); + // Change fixed_bounds. + CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100)); + // Change bounds. + CheckBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100)); +} + +void ExpectEqualLayerRectsInTarget(cc::Layer* layer1, cc::Layer* layer2) { + gfx::RectF layer1_rect_in_target(layer1->content_bounds()); + layer1->draw_transform().TransformRect(&layer1_rect_in_target); + + gfx::RectF layer2_rect_in_target(layer2->content_bounds()); + layer2->draw_transform().TransformRect(&layer2_rect_in_target); + + EXPECT_FLOAT_RECT_EQ(layer1_rect_in_target, layer2_rect_in_target); +} + +void CompareFixedBoundsLayerAndNormalLayer(const WebFloatPoint& anchor_point, + const gfx::Transform& transform) { + const gfx::Size kDeviceViewportSize(800, 600); + const float kDeviceScaleFactor = 2.f; + const float kPageScaleFactor = 1.5f; + + WebSize bounds(150, 200); + WebFloatPoint position(20, 30); + gfx::Size fixed_bounds(160, 70); + + scoped_ptr<WebLayerImplFixedBounds> root_layer(new WebLayerImplFixedBounds()); + + WebLayerImplFixedBounds* fixed_bounds_layer = + new WebLayerImplFixedBounds(cc::PictureImageLayer::Create()); + fixed_bounds_layer->setBounds(bounds); + fixed_bounds_layer->SetFixedBounds(fixed_bounds); + fixed_bounds_layer->setAnchorPoint(anchor_point); + fixed_bounds_layer->setTransform(transform.matrix()); + fixed_bounds_layer->setPosition(position); + root_layer->addChild(fixed_bounds_layer); + + WebLayerImpl* normal_layer(new WebLayerImpl(cc::PictureImageLayer::Create())); + + normal_layer->setBounds(bounds); + normal_layer->setAnchorPoint(anchor_point); + normal_layer->setTransform(transform.matrix()); + normal_layer->setPosition(position); + root_layer->addChild(normal_layer); + + scoped_ptr<cc::FakeLayerTreeHost> host = cc::FakeLayerTreeHost::Create(); + host->SetRootLayer(root_layer->layer()); + + { + cc::RenderSurfaceLayerList render_surface_layer_list; + cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( + root_layer->layer(), kDeviceViewportSize, &render_surface_layer_list); + inputs.device_scale_factor = kDeviceScaleFactor; + inputs.page_scale_factor = kPageScaleFactor; + inputs.page_scale_application_layer = root_layer->layer(), + cc::LayerTreeHostCommon::CalculateDrawProperties(&inputs); + + ExpectEqualLayerRectsInTarget(normal_layer->layer(), + fixed_bounds_layer->layer()); + } + + // Change of fixed bounds should not affect the target geometries. + fixed_bounds_layer->SetFixedBounds( + gfx::Size(fixed_bounds.width() / 2, fixed_bounds.height() * 2)); + + { + cc::RenderSurfaceLayerList render_surface_layer_list; + cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( + root_layer->layer(), kDeviceViewportSize, &render_surface_layer_list); + inputs.device_scale_factor = kDeviceScaleFactor; + inputs.page_scale_factor = kPageScaleFactor; + inputs.page_scale_application_layer = root_layer->layer(), + cc::LayerTreeHostCommon::CalculateDrawProperties(&inputs); + + ExpectEqualLayerRectsInTarget(normal_layer->layer(), + fixed_bounds_layer->layer()); + } +} + +// A black box test that ensures WebLayerImplFixedBounds won't change target +// geometries. Simple case: identity transforms and zero anchor point. +TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplSimple) { + CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), gfx::Transform()); +} + +// A black box test that ensures WebLayerImplFixedBounds won't change target +// geometries. Complex case: complex transforms and non-zero anchor point. +TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplComplex) { + gfx::Transform transform; + // These are arbitrary values that should not affect the results. + transform.Translate3d(50, 60, 70); + transform.Scale3d(2, 3, 4); + transform.RotateAbout(gfx::Vector3dF(33, 44, 55), 99); + + CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), transform); + + // With non-zero anchor point, WebLayerImplFixedBounds will fall back to + // WebLayerImpl. + CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0.4f, 0.6f), transform); +} + +} // namespace +} // namespace content diff --git a/content/renderer/compositor_bindings/web_nine_patch_layer_impl.cc b/content/renderer/compositor_bindings/web_nine_patch_layer_impl.cc new file mode 100644 index 0000000..55a7501 --- /dev/null +++ b/content/renderer/compositor_bindings/web_nine_patch_layer_impl.cc @@ -0,0 +1,62 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_nine_patch_layer_impl.h" + +#include "base/command_line.h" +#include "cc/base/switches.h" +#include "cc/layers/nine_patch_layer.h" +#include "cc/layers/picture_image_layer.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h" + +namespace content { + +WebNinePatchLayerImpl::WebNinePatchLayerImpl() { + layer_.reset(new WebLayerImpl(cc::NinePatchLayer::Create())); +} + +WebNinePatchLayerImpl::~WebNinePatchLayerImpl() { +} + +blink::WebLayer* WebNinePatchLayerImpl::layer() { + return layer_.get(); +} + +void WebNinePatchLayerImpl::setBitmap(SkBitmap bitmap, + const blink::WebRect& aperture) { + setBitmap(bitmap); + setAperture(aperture); + setBorder(blink::WebRect(aperture.x, + aperture.y, + bitmap.width() - aperture.width, + bitmap.height() - aperture.height)); +} + +void WebNinePatchLayerImpl::setBitmap(SkBitmap bitmap) { + cc::NinePatchLayer* nine_patch = + static_cast<cc::NinePatchLayer*>(layer_->layer()); + nine_patch->SetBitmap(bitmap); +} + +void WebNinePatchLayerImpl::setAperture(const blink::WebRect& aperture) { + cc::NinePatchLayer* nine_patch = + static_cast<cc::NinePatchLayer*>(layer_->layer()); + nine_patch->SetAperture(gfx::Rect(aperture)); +} + +void WebNinePatchLayerImpl::setBorder(const blink::WebRect& border) { + cc::NinePatchLayer* nine_patch = + static_cast<cc::NinePatchLayer*>(layer_->layer()); + nine_patch->SetBorder(gfx::Rect(border)); +} + +void WebNinePatchLayerImpl::setFillCenter(bool fill_center) { + cc::NinePatchLayer* nine_patch = + static_cast<cc::NinePatchLayer*>(layer_->layer()); + nine_patch->SetFillCenter(fill_center); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_nine_patch_layer_impl.h b/content/renderer/compositor_bindings/web_nine_patch_layer_impl.h new file mode 100644 index 0000000..cad69d7 --- /dev/null +++ b/content/renderer/compositor_bindings/web_nine_patch_layer_impl.h @@ -0,0 +1,42 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_NINE_PATCH_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_NINE_PATCH_LAYER_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebNinePatchLayer.h" +#include "third_party/skia/include/core/SkBitmap.h" + +namespace content { + +class WebLayerImpl; + +class WebNinePatchLayerImpl : public blink::WebNinePatchLayer { + public: + CONTENT_EXPORT WebNinePatchLayerImpl(); + virtual ~WebNinePatchLayerImpl(); + + // blink::WebNinePatchLayer implementation. + virtual blink::WebLayer* layer(); + + // TODO(ccameron): Remove setBitmap(SkBitmap, blink::WebRect) in favor of + // setBitmap(), setAperture(), and setBorder(); + virtual void setBitmap(SkBitmap bitmap, const blink::WebRect& aperture); + virtual void setBitmap(SkBitmap bitmap); + virtual void setAperture(const blink::WebRect& aperture); + virtual void setBorder(const blink::WebRect& border); + virtual void setFillCenter(bool fill_center); + + private: + scoped_ptr<WebLayerImpl> layer_; + + DISALLOW_COPY_AND_ASSIGN(WebNinePatchLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_NINE_PATCH_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.cc b/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.cc new file mode 100644 index 0000000..3b75271 --- /dev/null +++ b/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.cc @@ -0,0 +1,55 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h" + +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + +#include "cc/animation/scroll_offset_animation_curve.h" +#include "cc/animation/timing_function.h" +#include "content/renderer/compositor_bindings/web_animation_curve_common.h" + +using blink::WebFloatPoint; + +namespace content { + +WebScrollOffsetAnimationCurveImpl::WebScrollOffsetAnimationCurveImpl( + WebFloatPoint target_value, + TimingFunctionType timing_function) + : curve_(cc::ScrollOffsetAnimationCurve::Create( + gfx::Vector2dF(target_value.x, target_value.y), + CreateTimingFunction(timing_function))) { +} + +WebScrollOffsetAnimationCurveImpl::~WebScrollOffsetAnimationCurveImpl() { +} + +blink::WebAnimationCurve::AnimationCurveType +WebScrollOffsetAnimationCurveImpl::type() const { + return WebAnimationCurve::AnimationCurveTypeScrollOffset; +} + +void WebScrollOffsetAnimationCurveImpl::setInitialValue( + WebFloatPoint initial_value) { + curve_->SetInitialValue(gfx::Vector2dF(initial_value.x, initial_value.y)); +} + +WebFloatPoint WebScrollOffsetAnimationCurveImpl::getValue(double time) const { + gfx::Vector2dF value = curve_->GetValue(time); + return WebFloatPoint(value.x(), value.y()); +} + +double WebScrollOffsetAnimationCurveImpl::duration() const { + return curve_->Duration(); +} + +scoped_ptr<cc::AnimationCurve> +WebScrollOffsetAnimationCurveImpl::CloneToAnimationCurve() const { + return curve_->Clone(); +} + +} // namespace content + +#endif // WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + diff --git a/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h b/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h new file mode 100644 index 0000000..4c29f8f --- /dev/null +++ b/content/renderer/compositor_bindings/web_scroll_offset_animation_curve_impl.h @@ -0,0 +1,52 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLL_OFFSET_ANIMATION_CURVE_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLL_OFFSET_ANIMATION_CURVE_IMPL_H_ + +#include "third_party/WebKit/public/platform/WebAnimationCurve.h" + +#if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebScrollOffsetAnimationCurve.h" + +namespace cc { +class AnimationCurve; +class ScrollOffsetAnimationCurve; +} + +namespace content { + +class WebScrollOffsetAnimationCurveImpl + : public blink::WebScrollOffsetAnimationCurve { + public: + CONTENT_EXPORT WebScrollOffsetAnimationCurveImpl( + blink::WebFloatPoint target_value, + TimingFunctionType timing_function); + virtual ~WebScrollOffsetAnimationCurveImpl(); + + // blink::WebAnimationCurve implementation. + virtual AnimationCurveType type() const; + + // blink::WebScrollOffsetAnimationCurve implementation. + virtual void setInitialValue(blink::WebFloatPoint initial_value); + virtual blink::WebFloatPoint getValue(double time) const; + virtual double duration() const; + + scoped_ptr<cc::AnimationCurve> CloneToAnimationCurve() const; + + private: + scoped_ptr<cc::ScrollOffsetAnimationCurve> curve_; + + DISALLOW_COPY_AND_ASSIGN(WebScrollOffsetAnimationCurveImpl); +}; + +} // namespace content + +#endif // WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLL_OFFSET_ANIMATION_CURVE_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_scrollbar_layer_impl.cc b/content/renderer/compositor_bindings/web_scrollbar_layer_impl.cc new file mode 100644 index 0000000..0d3be19 --- /dev/null +++ b/content/renderer/compositor_bindings/web_scrollbar_layer_impl.cc @@ -0,0 +1,74 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_scrollbar_layer_impl.h" + +#include "cc/layers/layer.h" +#include "cc/layers/painted_scrollbar_layer.h" +#include "cc/layers/scrollbar_layer_interface.h" +#include "cc/layers/solid_color_scrollbar_layer.h" +#include "content/renderer/compositor_bindings/scrollbar_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" + +using cc::PaintedScrollbarLayer; +using cc::SolidColorScrollbarLayer; + +namespace { + +cc::ScrollbarOrientation ConvertOrientation( + blink::WebScrollbar::Orientation orientation) { + return orientation == blink::WebScrollbar::Horizontal ? cc::HORIZONTAL + : cc::VERTICAL; +} + +} // namespace + +namespace content { + +WebScrollbarLayerImpl::WebScrollbarLayerImpl( + blink::WebScrollbar* scrollbar, + blink::WebScrollbarThemePainter painter, + blink::WebScrollbarThemeGeometry* geometry) + : layer_(new WebLayerImpl(PaintedScrollbarLayer::Create( + scoped_ptr<cc::Scrollbar>( + new ScrollbarImpl(make_scoped_ptr(scrollbar), + painter, + make_scoped_ptr(geometry))).Pass(), + 0))) { +} + +WebScrollbarLayerImpl::WebScrollbarLayerImpl( + blink::WebScrollbar::Orientation orientation, + int thumb_thickness, + int track_start, + bool is_left_side_vertical_scrollbar) + : layer_(new WebLayerImpl( + SolidColorScrollbarLayer::Create(ConvertOrientation(orientation), + thumb_thickness, + track_start, + is_left_side_vertical_scrollbar, + 0))) { +} + +WebScrollbarLayerImpl::~WebScrollbarLayerImpl() { +} + +blink::WebLayer* WebScrollbarLayerImpl::layer() { + return layer_.get(); +} + +void WebScrollbarLayerImpl::setScrollLayer(blink::WebLayer* layer) { + cc::Layer* scroll_layer = + layer ? static_cast<WebLayerImpl*>(layer)->layer() : 0; + layer_->layer()->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); +} + +void WebScrollbarLayerImpl::setClipLayer(blink::WebLayer* layer) { + cc::Layer* clip_layer = + layer ? static_cast<WebLayerImpl*>(layer)->layer() : 0; + layer_->layer()->ToScrollbarLayer()->SetClipLayer(clip_layer->id()); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_scrollbar_layer_impl.h b/content/renderer/compositor_bindings/web_scrollbar_layer_impl.h new file mode 100644 index 0000000..47719e1 --- /dev/null +++ b/content/renderer/compositor_bindings/web_scrollbar_layer_impl.h @@ -0,0 +1,48 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLLBAR_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLLBAR_LAYER_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebScrollbar.h" +#include "third_party/WebKit/public/platform/WebScrollbarLayer.h" + +namespace blink { +class WebScrollbarThemeGeometry; +class WebScrollbarThemePainter; +} + +namespace content { + +class WebLayerImpl; + +class WebScrollbarLayerImpl : public blink::WebScrollbarLayer { + public: + CONTENT_EXPORT WebScrollbarLayerImpl( + blink::WebScrollbar* scrollbar, + blink::WebScrollbarThemePainter painter, + blink::WebScrollbarThemeGeometry* geometry); + CONTENT_EXPORT WebScrollbarLayerImpl( + blink::WebScrollbar::Orientation orientation, + int thumb_thickness, + int track_start, + bool is_left_side_vertical_scrollbar); + virtual ~WebScrollbarLayerImpl(); + + // blink::WebScrollbarLayer implementation. + virtual blink::WebLayer* layer(); + virtual void setScrollLayer(blink::WebLayer* layer); + virtual void setClipLayer(blink::WebLayer* layer); + + private: + scoped_ptr<WebLayerImpl> layer_; + + DISALLOW_COPY_AND_ASSIGN(WebScrollbarLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SCROLLBAR_LAYER_IMPL_H_ diff --git a/content/renderer/compositor_bindings/web_solid_color_layer_impl.cc b/content/renderer/compositor_bindings/web_solid_color_layer_impl.cc new file mode 100644 index 0000000..6cd9c19 --- /dev/null +++ b/content/renderer/compositor_bindings/web_solid_color_layer_impl.cc @@ -0,0 +1,31 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_solid_color_layer_impl.h" + +#include "cc/layers/solid_color_layer.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" + +using cc::SolidColorLayer; + +namespace content { + +WebSolidColorLayerImpl::WebSolidColorLayerImpl() + : layer_(new WebLayerImpl(SolidColorLayer::Create())) { + layer_->layer()->SetIsDrawable(true); +} + +WebSolidColorLayerImpl::~WebSolidColorLayerImpl() { +} + +blink::WebLayer* WebSolidColorLayerImpl::layer() { + return layer_.get(); +} + +void WebSolidColorLayerImpl::setBackgroundColor(blink::WebColor color) { + layer_->setBackgroundColor(color); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_solid_color_layer_impl.h b/content/renderer/compositor_bindings/web_solid_color_layer_impl.h new file mode 100644 index 0000000..fe6eefe --- /dev/null +++ b/content/renderer/compositor_bindings/web_solid_color_layer_impl.h @@ -0,0 +1,34 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SOLID_COLOR_LAYER_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SOLID_COLOR_LAYER_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebColor.h" +#include "third_party/WebKit/public/platform/WebSolidColorLayer.h" + +namespace content { +class WebLayerImpl; + +class WebSolidColorLayerImpl : public blink::WebSolidColorLayer { + public: + CONTENT_EXPORT WebSolidColorLayerImpl(); + virtual ~WebSolidColorLayerImpl(); + + // blink::WebSolidColorLayer implementation. + virtual blink::WebLayer* layer(); + virtual void setBackgroundColor(blink::WebColor); + + private: + scoped_ptr<WebLayerImpl> layer_; + + DISALLOW_COPY_AND_ASSIGN(WebSolidColorLayerImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_SOLID_COLOR_LAYER_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.cc b/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.cc new file mode 100644 index 0000000..5a953bd --- /dev/null +++ b/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.cc @@ -0,0 +1,33 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h" + +#include "third_party/WebKit/public/platform/WebAnimationDelegate.h" + +namespace content { + +WebToCCAnimationDelegateAdapter::WebToCCAnimationDelegateAdapter( + blink::WebAnimationDelegate* delegate) + : delegate_(delegate) { +} + +void WebToCCAnimationDelegateAdapter::NotifyAnimationStarted( + base::TimeTicks monotonic_time, + cc::Animation::TargetProperty target_property) { + delegate_->notifyAnimationStarted( + (monotonic_time - base::TimeTicks()).InSecondsF(), + static_cast<blink::WebAnimation::TargetProperty>(target_property)); +} + +void WebToCCAnimationDelegateAdapter::NotifyAnimationFinished( + base::TimeTicks monotonic_time, + cc::Animation::TargetProperty target_property) { + delegate_->notifyAnimationFinished( + (monotonic_time - base::TimeTicks()).InSecondsF(), + static_cast<blink::WebAnimation::TargetProperty>(target_property)); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h b/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h new file mode 100644 index 0000000..b80b627 --- /dev/null +++ b/content/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h @@ -0,0 +1,39 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TO_CC_ANIMATION_DELEGATE_ADAPTER_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TO_CC_ANIMATION_DELEGATE_ADAPTER_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "cc/animation/animation_delegate.h" + +namespace blink { +class WebAnimationDelegate; +} + +namespace content { + +class WebToCCAnimationDelegateAdapter : public cc::AnimationDelegate { + public: + explicit WebToCCAnimationDelegateAdapter( + blink::WebAnimationDelegate* delegate); + + private: + virtual void NotifyAnimationStarted( + base::TimeTicks monotonic_time, + cc::Animation::TargetProperty target_property) OVERRIDE; + virtual void NotifyAnimationFinished( + base::TimeTicks monotonic_time, + cc::Animation::TargetProperty target_property) OVERRIDE; + + blink::WebAnimationDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(WebToCCAnimationDelegateAdapter); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TO_CC_ANIMATION_DELEGATE_ADAPTER_H_ + diff --git a/content/renderer/compositor_bindings/web_transform_animation_curve_impl.cc b/content/renderer/compositor_bindings/web_transform_animation_curve_impl.cc new file mode 100644 index 0000000..8b03f48 --- /dev/null +++ b/content/renderer/compositor_bindings/web_transform_animation_curve_impl.cc @@ -0,0 +1,63 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_transform_animation_curve_impl.h" + +#include "cc/animation/keyframed_animation_curve.h" +#include "cc/animation/timing_function.h" +#include "cc/animation/transform_operations.h" +#include "content/renderer/compositor_bindings/web_animation_curve_common.h" +#include "content/renderer/compositor_bindings/web_transform_operations_impl.h" + +using blink::WebTransformKeyframe; + +namespace content { + +WebTransformAnimationCurveImpl::WebTransformAnimationCurveImpl() + : curve_(cc::KeyframedTransformAnimationCurve::Create()) { +} + +WebTransformAnimationCurveImpl::~WebTransformAnimationCurveImpl() { +} + +blink::WebAnimationCurve::AnimationCurveType +WebTransformAnimationCurveImpl::type() const { + return WebAnimationCurve::AnimationCurveTypeTransform; +} + +void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe) { + add(keyframe, TimingFunctionTypeEase); +} + +void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe, + TimingFunctionType type) { + const cc::TransformOperations& transform_operations = + static_cast<const WebTransformOperationsImpl&>(keyframe.value()) + .AsTransformOperations(); + curve_->AddKeyframe(cc::TransformKeyframe::Create( + keyframe.time(), transform_operations, CreateTimingFunction(type))); +} + +void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2) { + const cc::TransformOperations& transform_operations = + static_cast<const WebTransformOperationsImpl&>(keyframe.value()) + .AsTransformOperations(); + curve_->AddKeyframe(cc::TransformKeyframe::Create( + keyframe.time(), + transform_operations, + cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2) + .PassAs<cc::TimingFunction>())); +} + +scoped_ptr<cc::AnimationCurve> +WebTransformAnimationCurveImpl::CloneToAnimationCurve() const { + return curve_->Clone(); +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_transform_animation_curve_impl.h b/content/renderer/compositor_bindings/web_transform_animation_curve_impl.h new file mode 100644 index 0000000..5a0576d --- /dev/null +++ b/content/renderer/compositor_bindings/web_transform_animation_curve_impl.h @@ -0,0 +1,53 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_ANIMATION_CURVE_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_ANIMATION_CURVE_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebTransformAnimationCurve.h" + +namespace cc { +class AnimationCurve; +class KeyframedTransformAnimationCurve; +} + +namespace blink { +class WebTransformKeyframe; +} + +namespace content { + +class WebTransformAnimationCurveImpl + : public blink::WebTransformAnimationCurve { + public: + CONTENT_EXPORT WebTransformAnimationCurveImpl(); + virtual ~WebTransformAnimationCurveImpl(); + + // blink::WebAnimationCurve implementation. + virtual AnimationCurveType type() const; + + // blink::WebTransformAnimationCurve implementation. + virtual void add(const blink::WebTransformKeyframe& keyframe); + virtual void add(const blink::WebTransformKeyframe& keyframe, + TimingFunctionType type); + virtual void add(const blink::WebTransformKeyframe& keyframe, + double x1, + double y1, + double x2, + double y2); + + scoped_ptr<cc::AnimationCurve> CloneToAnimationCurve() const; + + private: + scoped_ptr<cc::KeyframedTransformAnimationCurve> curve_; + + DISALLOW_COPY_AND_ASSIGN(WebTransformAnimationCurveImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_ANIMATION_CURVE_IMPL_H_ + diff --git a/content/renderer/compositor_bindings/web_transform_operations_impl.cc b/content/renderer/compositor_bindings/web_transform_operations_impl.cc new file mode 100644 index 0000000..cfec1b4 --- /dev/null +++ b/content/renderer/compositor_bindings/web_transform_operations_impl.cc @@ -0,0 +1,69 @@ +// Copyright 2014 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 "content/renderer/compositor_bindings/web_transform_operations_impl.h" + +#include <algorithm> + +#include "ui/gfx/transform.h" + +namespace content { + +WebTransformOperationsImpl::WebTransformOperationsImpl() { +} + +const cc::TransformOperations& +WebTransformOperationsImpl::AsTransformOperations() const { + return transform_operations_; +} + +bool WebTransformOperationsImpl::canBlendWith( + const blink::WebTransformOperations& other) const { + const WebTransformOperationsImpl& other_impl = + static_cast<const WebTransformOperationsImpl&>(other); + return transform_operations_.CanBlendWith(other_impl.transform_operations_); +} + +void WebTransformOperationsImpl::appendTranslate(double x, double y, double z) { + transform_operations_.AppendTranslate(x, y, z); +} + +void WebTransformOperationsImpl::appendRotate(double x, + double y, + double z, + double degrees) { + transform_operations_.AppendRotate(x, y, z, degrees); +} + +void WebTransformOperationsImpl::appendScale(double x, double y, double z) { + transform_operations_.AppendScale(x, y, z); +} + +void WebTransformOperationsImpl::appendSkew(double x, double y) { + transform_operations_.AppendSkew(x, y); +} + +void WebTransformOperationsImpl::appendPerspective(double depth) { + transform_operations_.AppendPerspective(depth); +} + +void WebTransformOperationsImpl::appendMatrix(const SkMatrix44& matrix) { + gfx::Transform transform(gfx::Transform::kSkipInitialization); + transform.matrix() = matrix; + transform_operations_.AppendMatrix(transform); +} + +void WebTransformOperationsImpl::appendIdentity() { + transform_operations_.AppendIdentity(); +} + +bool WebTransformOperationsImpl::isIdentity() const { + return transform_operations_.IsIdentity(); +} + +WebTransformOperationsImpl::~WebTransformOperationsImpl() { +} + +} // namespace content + diff --git a/content/renderer/compositor_bindings/web_transform_operations_impl.h b/content/renderer/compositor_bindings/web_transform_operations_impl.h new file mode 100644 index 0000000..f0f7b47 --- /dev/null +++ b/content/renderer/compositor_bindings/web_transform_operations_impl.h @@ -0,0 +1,42 @@ +// Copyright 2014 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. + +#ifndef CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_OPERATIONS_IMPL_H_ +#define CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_OPERATIONS_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/animation/transform_operations.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebTransformOperations.h" + +namespace content { + +class WebTransformOperationsImpl : public blink::WebTransformOperations { + public: + CONTENT_EXPORT WebTransformOperationsImpl(); + virtual ~WebTransformOperationsImpl(); + + const cc::TransformOperations& AsTransformOperations() const; + + // Implementation of blink::WebTransformOperations methods + virtual bool canBlendWith(const blink::WebTransformOperations& other) const; + virtual void appendTranslate(double x, double y, double z); + virtual void appendRotate(double x, double y, double z, double degrees); + virtual void appendScale(double x, double y, double z); + virtual void appendSkew(double x, double y); + virtual void appendPerspective(double depth); + virtual void appendMatrix(const SkMatrix44&); + virtual void appendIdentity(); + virtual bool isIdentity() const; + + private: + cc::TransformOperations transform_operations_; + + DISALLOW_COPY_AND_ASSIGN(WebTransformOperationsImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_COMPOSITOR_BINDINGS_WEB_TRANSFORM_OPERATIONS_IMPL_H_ + diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index f974828..fe393c7 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -31,6 +31,7 @@ #include "content/common/content_switches_internal.h" #include "content/common/gpu/client/context_provider_command_buffer.h" #include "content/public/common/content_switches.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/input/input_handler_manager.h" #include "content/renderer/render_thread_impl.h" #include "gpu/command_buffer/client/gles2_interface.h" @@ -40,7 +41,6 @@ #include "ui/gfx/frame_time.h" #include "ui/gl/gl_switches.h" #include "ui/native_theme/native_theme_switches.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" namespace base { class Value; @@ -452,7 +452,7 @@ void RenderWidgetCompositor::setSurfaceReady() { void RenderWidgetCompositor::setRootLayer(const blink::WebLayer& layer) { layer_tree_host_->SetRootLayer( - static_cast<const webkit::WebLayerImpl*>(&layer)->layer()); + static_cast<const WebLayerImpl*>(&layer)->layer()); } void RenderWidgetCompositor::clearRootLayer() { @@ -545,7 +545,7 @@ void RenderWidgetCompositor::didStopFlinging() { } void RenderWidgetCompositor::registerForAnimations(blink::WebLayer* layer) { - cc::Layer* cc_layer = static_cast<webkit::WebLayerImpl*>(layer)->layer(); + cc::Layer* cc_layer = static_cast<WebLayerImpl*>(layer)->layer(); cc_layer->layer_animation_controller()->SetAnimationRegistrar( layer_tree_host_->animation_registrar()); } @@ -555,14 +555,13 @@ void RenderWidgetCompositor::registerViewportLayers( const blink::WebLayer* innerViewportScrollLayer, const blink::WebLayer* outerViewportScrollLayer) { layer_tree_host_->RegisterViewportLayers( - static_cast<const webkit::WebLayerImpl*>(pageScaleLayer)->layer(), - static_cast<const webkit::WebLayerImpl*>(innerViewportScrollLayer) - ->layer(), + static_cast<const WebLayerImpl*>(pageScaleLayer)->layer(), + static_cast<const WebLayerImpl*>(innerViewportScrollLayer)->layer(), // The outer viewport layer will only exist when using pinch virtual // viewports. - outerViewportScrollLayer ? static_cast<const webkit::WebLayerImpl*>( - outerViewportScrollLayer)->layer() - : NULL); + outerViewportScrollLayer + ? static_cast<const WebLayerImpl*>(outerViewportScrollLayer)->layer() + : NULL); } void RenderWidgetCompositor::clearViewportLayers() { diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index fcf37ce..9833546 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -19,6 +19,7 @@ #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/render_frame.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/media/android/renderer_demuxer_android.h" #include "content/renderer/media/android/renderer_media_player_manager.h" #include "content/renderer/media/crypto/key_systems.h" @@ -51,7 +52,6 @@ #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkTypeface.h" #include "ui/gfx/image/image.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" static const uint32 kGLTextureExternalOES = 0x8D65; @@ -730,8 +730,7 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { // Lazily allocate compositing layer. if (!video_weblayer_) { - video_weblayer_.reset( - new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); + video_weblayer_.reset(new WebLayerImpl(cc::VideoLayer::Create(this))); client_->setWebLayer(video_weblayer_.get()); } diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h index 3cfacff..67d09e0 100644 --- a/content/renderer/media/android/webmediaplayer_android.h +++ b/content/renderer/media/android/webmediaplayer_android.h @@ -49,14 +49,11 @@ namespace media { class MediaLog; } -namespace webkit { -class WebLayerImpl; -} - namespace content { class RendererCdmManager; class RendererMediaPlayerManager; class WebContentDecryptionModuleImpl; +class WebLayerImpl; class WebMediaPlayerDelegate; // This class implements blink::WebMediaPlayer by keeping the android @@ -392,7 +389,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, // not NULL while the compositor is actively using this webmediaplayer. cc::VideoFrameProvider::Client* video_frame_provider_client_; - scoped_ptr<webkit::WebLayerImpl> video_weblayer_; + scoped_ptr<WebLayerImpl> video_weblayer_; #if defined(VIDEO_HOLE) // A rectangle represents the geometry of video frame, when computed last diff --git a/content/renderer/media/webmediaplayer_impl.cc b/content/renderer/media/webmediaplayer_impl.cc index 7b8bb49..088d545 100644 --- a/content/renderer/media/webmediaplayer_impl.cc +++ b/content/renderer/media/webmediaplayer_impl.cc @@ -24,6 +24,7 @@ #include "cc/layers/video_layer.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/render_frame.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/media/buffered_data_source.h" #include "content/renderer/media/crypto/key_systems.h" #include "content/renderer/media/render_media_log.h" @@ -71,7 +72,6 @@ #include "third_party/WebKit/public/web/WebSecurityOrigin.h" #include "third_party/WebKit/public/web/WebView.h" #include "v8/include/v8.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" #if defined(ENABLE_PEPPER_CDMS) #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" @@ -964,7 +964,7 @@ void WebMediaPlayerImpl::OnPipelineMetadata( if (hasVideo()) { DCHECK(!video_weblayer_); video_weblayer_.reset( - new webkit::WebLayerImpl(cc::VideoLayer::Create(compositor_))); + new WebLayerImpl(cc::VideoLayer::Create(compositor_))); video_weblayer_->setOpaque(opaque_); client_->setWebLayer(video_weblayer_.get()); } diff --git a/content/renderer/media/webmediaplayer_impl.h b/content/renderer/media/webmediaplayer_impl.h index 8911e3b..87c180e 100644 --- a/content/renderer/media/webmediaplayer_impl.h +++ b/content/renderer/media/webmediaplayer_impl.h @@ -47,15 +47,13 @@ class GpuVideoAcceleratorFactories; class MediaLog; } -namespace webkit { -class WebLayerImpl; -} namespace content { class BufferedDataSource; class VideoFrameCompositor; class WebAudioSourceProviderImpl; class WebContentDecryptionModuleImpl; +class WebLayerImpl; class WebMediaPlayerDelegate; class WebMediaPlayerParams; class WebTextTrackImpl; @@ -337,7 +335,7 @@ class WebMediaPlayerImpl // The compositor layer for displaying the video content when using composited // playback. - scoped_ptr<webkit::WebLayerImpl> video_weblayer_; + scoped_ptr<WebLayerImpl> video_weblayer_; // Text track objects get a unique index value when they're created. int text_track_index_; diff --git a/content/renderer/media/webmediaplayer_ms.cc b/content/renderer/media/webmediaplayer_ms.cc index fe8d7a5..b466d31 100644 --- a/content/renderer/media/webmediaplayer_ms.cc +++ b/content/renderer/media/webmediaplayer_ms.cc @@ -12,6 +12,7 @@ #include "base/metrics/histogram.h" #include "cc/layers/video_layer.h" #include "content/public/renderer/render_view.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/media/media_stream_audio_renderer.h" #include "content/renderer/media/media_stream_renderer_factory.h" #include "content/renderer/media/video_frame_provider.h" @@ -28,7 +29,6 @@ #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebView.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" using blink::WebCanvas; using blink::WebMediaPlayer; @@ -414,8 +414,7 @@ void WebMediaPlayerMS::OnFrameAvailable( GetClient()->sizeChanged(); if (video_frame_provider_) { - video_weblayer_.reset( - new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); + video_weblayer_.reset(new WebLayerImpl(cc::VideoLayer::Create(this))); video_weblayer_->setOpaque(true); GetClient()->setWebLayer(video_weblayer_.get()); } diff --git a/content/renderer/media/webmediaplayer_ms.h b/content/renderer/media/webmediaplayer_ms.h index 51f90e8..7e8944a 100644 --- a/content/renderer/media/webmediaplayer_ms.h +++ b/content/renderer/media/webmediaplayer_ms.h @@ -25,14 +25,12 @@ namespace media { class MediaLog; } -namespace webkit { -class WebLayerImpl; -} namespace content { class MediaStreamAudioRenderer; class MediaStreamRendererFactory; class VideoFrameProvider; +class WebLayerImpl; class WebMediaPlayerDelegate; // WebMediaPlayerMS delegates calls from WebCore::MediaPlayerPrivate to @@ -168,7 +166,7 @@ class WebMediaPlayerMS base::Lock current_frame_lock_; bool pending_repaint_; - scoped_ptr<webkit::WebLayerImpl> video_weblayer_; + scoped_ptr<WebLayerImpl> video_weblayer_; // A pointer back to the compositor to inform it about state changes. This is // not NULL while the compositor is actively using this webmediaplayer. diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index 065571b..91e16b0 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -24,6 +24,7 @@ #include "content/public/common/content_constants.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/content_renderer_client.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/npapi/webplugin_delegate_proxy.h" #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_process.h" @@ -57,7 +58,6 @@ #include "url/gurl.h" #include "url/url_util.h" #include "webkit/child/multipart_response_delegate.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" using blink::WebCanvas; using blink::WebConsoleMessage; @@ -852,7 +852,7 @@ void WebPluginImpl::AcceleratedPluginSwappedIOSurface() { if (next_io_surface_id_) { if (!io_surface_layer_.get()) { io_surface_layer_ = cc::IOSurfaceLayer::Create(); - web_layer_.reset(new webkit::WebLayerImpl(io_surface_layer_)); + web_layer_.reset(new WebLayerImpl(io_surface_layer_)); container_->setWebLayer(web_layer_.get()); } io_surface_layer_->SetIOSurfaceProperties( diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index 7db4c54..6e7ff9f 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -24,6 +24,7 @@ #include "content/public/common/content_switches.h" #include "content/public/common/page_zoom.h" #include "content/public/renderer/content_renderer_client.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/gpu/render_widget_compositor.h" #include "content/renderer/pepper/common.h" #include "content/renderer/pepper/content_decryptor_delegate.h" @@ -126,7 +127,6 @@ #include "ui/gfx/rect_conversions.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" #include "v8/include/v8.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" #if defined(OS_CHROMEOS) #include "ui/events/keycodes/keyboard_codes_posix.h" @@ -2039,10 +2039,10 @@ void PepperPluginInstanceImpl::UpdateLayer() { // wmode=transparent was specified. opaque = opaque || fullscreen_container_; texture_layer_->SetContentsOpaque(opaque); - web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); + web_layer_.reset(new WebLayerImpl(texture_layer_)); } else if (want_compositor_layer) { compositor_layer_ = bound_compositor_->layer(); - web_layer_.reset(new webkit::WebLayerImpl(compositor_layer_)); + web_layer_.reset(new WebLayerImpl(compositor_layer_)); } if (web_layer_) { diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index e66bd92..2fcaab4 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -63,6 +63,8 @@ #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/render_process_observer.h" #include "content/public/renderer/render_view_visitor.h" +#include "content/renderer/compositor_bindings/web_external_bitmap_impl.h" +#include "content/renderer/compositor_bindings/web_layer_impl.h" #include "content/renderer/devtools/devtools_agent_filter.h" #include "content/renderer/dom_storage/dom_storage_dispatcher.h" #include "content/renderer/dom_storage/webstoragearea_impl.h" @@ -121,8 +123,6 @@ #include "ui/base/layout.h" #include "ui/base/ui_base_switches.h" #include "v8/include/v8.h" -#include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" #if defined(OS_ANDROID) #include <cpu-features.h> @@ -413,8 +413,7 @@ void RenderThreadImpl::Init() { is_impl_side_painting_enabled_ = command_line.HasSwitch(switches::kEnableImplSidePainting); - webkit::WebLayerImpl::SetImplSidePaintingEnabled( - is_impl_side_painting_enabled_); + WebLayerImpl::SetImplSidePaintingEnabled(is_impl_side_painting_enabled_); is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy) && !command_line.HasSwitch(switches::kDisableZeroCopy); @@ -808,7 +807,7 @@ void RenderThreadImpl::EnsureWebKitInitialized() { if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) ScheduleIdleHandler(kLongIdleHandlerDelayMs); - webkit::SetSharedMemoryAllocationFunction(AllocateSharedMemoryFunction); + SetSharedMemoryAllocationFunction(AllocateSharedMemoryFunction); // Limit use of the scaled image cache to when deferred image decoding is // enabled. diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h index 1cd15d8..ee0ccb1 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.h +++ b/content/renderer/renderer_webkitplatformsupport_impl.h @@ -9,11 +9,11 @@ #include "base/memory/scoped_ptr.h" #include "content/child/blink_platform_impl.h" #include "content/common/content_export.h" +#include "content/renderer/compositor_bindings/web_compositor_support_impl.h" #include "content/renderer/webpublicsuffixlist_impl.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" #include "third_party/WebKit/public/platform/WebIDBFactory.h" #include "third_party/WebKit/public/platform/WebScreenOrientationType.h" -#include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h" namespace base { class MessageLoopProxy; @@ -230,7 +230,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; - webkit::WebCompositorSupportImpl compositor_support_; + WebCompositorSupportImpl compositor_support_; scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_; |