Commit 00d6281c authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Add API in gfx::Canvas for Skottie

This patch adds an API to gfx::Canvas to draw skottie directly on the
backing canvas. It also removes the bitmap rasterization of each
animation frame from the ui thread and offloads it to cc.

Bug: 890224
Change-Id: Ibf8d9b682428be26c12caa4cccaae9bd53bb255a
Component: gfx, canvas, skia vector animation
Reviewed-on: https://chromium-review.googlesource.com/c/1292527
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601419}
parent 0f3a7b0a
......@@ -441,6 +441,12 @@ void Canvas::DrawImageInPath(const ImageSkia& image,
canvas_->drawPath(path, flags);
}
void Canvas::DrawSkottie(scoped_refptr<cc::SkottieWrapper> skottie,
const Rect& dst,
float t) {
canvas_->drawSkottie(std::move(skottie), RectToSkRect(dst), t);
}
void Canvas::DrawStringRect(const base::string16& text,
const FontList& font_list,
SkColor color,
......
......@@ -20,6 +20,10 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/text_constants.h"
namespace cc {
class SkottieWrapper;
} // namespace cc
namespace gfx {
class Rect;
......@@ -360,6 +364,13 @@ class GFX_EXPORT Canvas {
const SkPath& path,
const cc::PaintFlags& flags);
// Draws the frame of the |skottie| animation specified by the normalized time
// instant t [0->first frame .. 1->last frame] onto the region corresponded by
// |dst| in the canvas.
void DrawSkottie(scoped_refptr<cc::SkottieWrapper> skottie,
const Rect& dst,
float t);
// Draws text with the specified color, fonts and location. The text is
// aligned to the left, vertically centered, clipped to the region. If the
// text is too big, it is truncated and '...' is added to the end.
......
......@@ -204,23 +204,9 @@ void SkiaVectorAnimation::Paint(gfx::Canvas* canvas,
void SkiaVectorAnimation::PaintFrame(gfx::Canvas* canvas,
float t,
const gfx::Size& size) {
TRACE_EVENT0("ui", "SkiaVectorAnimation Paint");
DCHECK_GE(t, 0.f);
DCHECK_LE(t, 1.f);
float scale = canvas->UndoDeviceScaleFactor();
gfx::Size pixel_size = gfx::ScaleToRoundedSize(size, scale);
SkBitmap bitmap;
bitmap.allocN32Pixels(std::round(pixel_size.width()),
std::round(pixel_size.height()), false);
SkCanvas skcanvas(bitmap);
skcanvas.clear(SK_ColorTRANSPARENT);
skottie_->Draw(&skcanvas, t,
SkRect::MakeWH(pixel_size.width(), pixel_size.height()));
canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bitmap), 0, 0);
canvas->DrawSkottie(skottie(), gfx::Rect(size), t);
}
void SkiaVectorAnimation::InitTimer(const base::TimeTicks& timestamp) {
......
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