Commit 8479b804 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Move SkottieWrapper to cc paint

This patch moves the SkottieWrapper from ui/gfx to cc/paint. This is the
next step in moving the rasterization of skottie to worker threads.

Bug: 890224
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I2b5f47b60a11bfbc495bb260ad6003ced85d6fad
Component: cc, paint, gfx, views
Reviewed-on: https://chromium-review.googlesource.com/c/1285091Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600540}
parent ae127f8f
......@@ -79,6 +79,8 @@ cc_component("paint") {
"skia_paint_canvas.h",
"skia_paint_image_generator.cc",
"skia_paint_image_generator.h",
"skottie_wrapper.cc",
"skottie_wrapper.h",
"solid_color_analyzer.cc",
"solid_color_analyzer.h",
"transfer_cache_deserialize_helper.h",
......
......@@ -9,4 +9,7 @@ specific_include_rules = {
"oop_pixeltest.cc": [
"+gpu/command_buffer",
],
"skottie_wrapper.h": [
"+third_party/skia",
],
}
......@@ -2,19 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/skottie_wrapper.h"
#include "cc/paint/skottie_wrapper.h"
#include "base/memory/ref_counted_memory.h"
#include "base/trace_event/trace_event.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkStream.h"
#include "ui/gfx/geometry/size.h"
namespace gfx {
namespace cc {
SkottieWrapper::SkottieWrapper(
const scoped_refptr<base::RefCountedMemory>& data_stream) {
TRACE_EVENT0("ui", "SkottieWrapper Parse");
TRACE_EVENT0("cc", "SkottieWrapper Parse");
SkMemoryStream sk_stream(data_stream->front(), data_stream->size());
animation_ = skottie::Animation::Make(&sk_stream);
}
......@@ -24,13 +22,10 @@ SkottieWrapper::SkottieWrapper(std::unique_ptr<SkMemoryStream> stream)
SkottieWrapper::~SkottieWrapper() {}
void SkottieWrapper::Draw(SkCanvas* canvas, float t, const gfx::Size& size) {
SkRect dst = SkRect::MakeXYWH(0, 0, size.width(), size.height());
{
base::AutoLock lock(lock_);
animation_->seek(t);
animation_->render(canvas, &dst);
}
void SkottieWrapper::Draw(SkCanvas* canvas, float t, const SkRect& rect) {
base::AutoLock lock(lock_);
animation_->seek(t);
animation_->render(canvas, &rect);
}
} // namespace gfx
} // namespace cc
......@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_SKOTTIE_WRAPPER_H_
#define UI_GFX_SKOTTIE_WRAPPER_H_
#ifndef CC_PAINT_SKOTTIE_WRAPPER_H_
#define CC_PAINT_SKOTTIE_WRAPPER_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "cc/paint/paint_export.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/modules/skottie/include/Skottie.h"
#include "ui/gfx/gfx_export.h"
class SkCanvas;
class SkMemoryStream;
......@@ -20,22 +21,21 @@ namespace base {
class RefCountedMemory;
} // namespace base
namespace gfx {
class Size;
namespace cc {
// A wrapper over Skia's Skottie object that can be shared by multiple
// SkiaVectorAnimation objects. This class is thread safe when performing a draw
// on an SkCanvas.
class GFX_EXPORT SkottieWrapper
class CC_PAINT_EXPORT SkottieWrapper
: public base::RefCountedThreadSafe<SkottieWrapper> {
public:
explicit SkottieWrapper(
const scoped_refptr<base::RefCountedMemory>& data_stream);
explicit SkottieWrapper(std::unique_ptr<SkMemoryStream> stream);
// A thread safe call that will draw an image of size |size| for the frame at
// normalized time instant |t| onto the |canvas|.
void Draw(SkCanvas* canvas, float t, const Size& size);
// A thread safe call that will draw an image with bounds |rect| for the
// frame at normalized time instant |t| onto the |canvas|.
void Draw(SkCanvas* canvas, float t, const SkRect& rect);
float duration() const { return animation_->duration(); }
SkSize size() const { return animation_->size(); }
......@@ -50,6 +50,6 @@ class GFX_EXPORT SkottieWrapper
DISALLOW_COPY_AND_ASSIGN(SkottieWrapper);
};
} // namespace gfx
} // namespace cc
#endif // UI_GFX_SKOTTIE_WRAPPER_H_
#endif // CC_PAINT_SKOTTIE_WRAPPER_H_
......@@ -223,8 +223,6 @@ jumbo_component("gfx") {
"skia_vector_animation.cc",
"skia_vector_animation.h",
"skia_vector_animation_observer.h",
"skottie_wrapper.cc",
"skottie_wrapper.h",
]
} else {
sources += [
......
......@@ -5,6 +5,7 @@
#include "ui/gfx/skia_vector_animation.h"
#include "base/trace_event/trace_event.h"
#include "cc/paint/skottie_wrapper.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
......@@ -13,7 +14,6 @@
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/skia_vector_animation_observer.h"
#include "ui/gfx/skottie_wrapper.h"
namespace gfx {
......@@ -69,7 +69,8 @@ double SkiaVectorAnimation::TimerControl::GetNormalizedEndOffset() const {
return end_offset_.InMillisecondsF() * progress_per_millisecond_;
}
SkiaVectorAnimation::SkiaVectorAnimation(scoped_refptr<SkottieWrapper> skottie)
SkiaVectorAnimation::SkiaVectorAnimation(
scoped_refptr<cc::SkottieWrapper> skottie)
: skottie_(skottie) {}
SkiaVectorAnimation::~SkiaVectorAnimation() {}
......@@ -216,7 +217,8 @@ void SkiaVectorAnimation::PaintFrame(gfx::Canvas* canvas,
SkCanvas skcanvas(bitmap);
skcanvas.clear(SK_ColorTRANSPARENT);
skottie_->Draw(&skcanvas, t, pixel_size);
skottie_->Draw(&skcanvas, t,
SkRect::MakeWH(pixel_size.width(), pixel_size.height()));
canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bitmap), 0, 0);
}
......
......@@ -16,11 +16,14 @@
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
namespace cc {
class SkottieWrapper;
} // namespace cc
namespace gfx {
class Canvas;
class SkiaVectorAnimationTest;
class SkiaVectorAnimationObserver;
class SkottieWrapper;
// This class is a wrapper over the Skia object for lottie vector graphic
// animations. It has its own timeline manager for the animation controls. The
......@@ -81,7 +84,7 @@ class GFX_EXPORT SkiaVectorAnimation {
kLoop // Same as LINEAR, except the animation repeats after it ends.
};
explicit SkiaVectorAnimation(scoped_refptr<SkottieWrapper> skottie);
explicit SkiaVectorAnimation(scoped_refptr<cc::SkottieWrapper> skottie);
~SkiaVectorAnimation();
void SetAnimationObserver(SkiaVectorAnimationObserver* Observer);
......@@ -138,7 +141,7 @@ class GFX_EXPORT SkiaVectorAnimation {
void PaintFrame(gfx::Canvas* canvas, float t, const gfx::Size& size);
// Returns the skottie object that contins the animation data.
scoped_refptr<SkottieWrapper> skottie() const { return skottie_; }
scoped_refptr<cc::SkottieWrapper> skottie() const { return skottie_; }
private:
friend class SkiaVectorAnimationTest;
......@@ -231,7 +234,7 @@ class GFX_EXPORT SkiaVectorAnimation {
SkiaVectorAnimationObserver* observer_ = nullptr;
scoped_refptr<SkottieWrapper> skottie_;
scoped_refptr<cc::SkottieWrapper> skottie_;
DISALLOW_COPY_AND_ASSIGN(SkiaVectorAnimation);
};
......
......@@ -10,12 +10,12 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/simple_test_tick_clock.h"
#include "cc/paint/skottie_wrapper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkStream.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/skia_vector_animation_observer.h"
#include "ui/gfx/skottie_wrapper.h"
namespace gfx {
namespace {
......@@ -102,7 +102,7 @@ class SkiaVectorAnimationTest : public testing::Test {
void SetUp() override {
canvas_.reset(new gfx::Canvas(gfx::Size(kAnimationWidth, kAnimationHeight),
1.f, false));
skottie_ = base::MakeRefCounted<SkottieWrapper>(
skottie_ = base::MakeRefCounted<cc::SkottieWrapper>(
std::make_unique<SkMemoryStream>(kData, std::strlen(kData)));
animation_ = std::make_unique<SkiaVectorAnimation>(skottie_);
}
......@@ -190,7 +190,7 @@ class SkiaVectorAnimationTest : public testing::Test {
protected:
std::unique_ptr<SkiaVectorAnimation> animation_;
scoped_refptr<SkottieWrapper> skottie_;
scoped_refptr<cc::SkottieWrapper> skottie_;
private:
std::unique_ptr<gfx::Canvas> canvas_;
......@@ -202,7 +202,7 @@ class SkiaVectorAnimationTest : public testing::Test {
TEST_F(SkiaVectorAnimationTest, InitializationAndLoadingData) {
auto bytes = base::MakeRefCounted<base::RefCountedBytes>(
std::vector<unsigned char>(kData, kData + std::strlen(kData)));
skottie_ = base::MakeRefCounted<SkottieWrapper>(bytes.get());
skottie_ = base::MakeRefCounted<cc::SkottieWrapper>(bytes.get());
animation_ = std::make_unique<SkiaVectorAnimation>(skottie_);
EXPECT_FLOAT_EQ(animation_->GetOriginalSize().width(), kAnimationWidth);
EXPECT_FLOAT_EQ(animation_->GetOriginalSize().height(), kAnimationHeight);
......@@ -210,7 +210,7 @@ TEST_F(SkiaVectorAnimationTest, InitializationAndLoadingData) {
kAnimationDuration);
EXPECT_TRUE(IsStopped());
skottie_ = base::MakeRefCounted<SkottieWrapper>(
skottie_ = base::MakeRefCounted<cc::SkottieWrapper>(
std::make_unique<SkMemoryStream>(kData, std::strlen(kData)));
animation_ = std::make_unique<SkiaVectorAnimation>(skottie_);
EXPECT_FLOAT_EQ(animation_->GetOriginalSize().width(), kAnimationWidth);
......
......@@ -7,8 +7,8 @@
#include <utility>
#include "base/logging.h"
#include "cc/paint/skottie_wrapper.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/skottie_wrapper.h"
#include "ui/views/widget/widget.h"
namespace views {
......
......@@ -14,8 +14,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "cc/paint/skottie_wrapper.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/skottie_wrapper.h"
#include "ui/views/border.h"
#include "ui/views/controls/animated_image_view.h"
#include "ui/views/controls/button/button.h"
......@@ -99,7 +99,7 @@ class AnimationGallery : public View,
#endif // defined(OS_POSIX)
base::ReadFileToString(path, &json);
auto skottie = base::MakeRefCounted<gfx::SkottieWrapper>(
auto skottie = base::MakeRefCounted<cc::SkottieWrapper>(
base::RefCountedString::TakeString(&json));
animated_image_view_->SetAnimatedImage(
std::make_unique<gfx::SkiaVectorAnimation>(skottie));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment