Skip to content

Commit

Permalink
Revert "[skottie] Add image sampling and transform options"
Browse files Browse the repository at this point in the history
This reverts commit 2f24405.

Reason for revert: broke Win/shared 

Original change's description:
> [skottie] Add image sampling and transform options
>
> Expand the SkImageAsset API to support controlling sampling options and
> pass an additional transform.
>
> Bug: skia:10944, skia:10942
> Change-Id: I7bad0b2ab58ed40fe4b425de0eb6970a4c7d7117
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340097
> Commit-Queue: Florin Malita <[email protected]>
> Commit-Queue: Florin Malita <[email protected]>
> Reviewed-by: Mike Reed <[email protected]>

[email protected],[email protected],[email protected],[email protected]

Change-Id: I59d4161356ffdc20588f1bd3beb33c54e44807a2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10944
Bug: skia:10942
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340619
Reviewed-by: Florin Malita <[email protected]>
Commit-Queue: Florin Malita <[email protected]>
  • Loading branch information
fmalita authored and Skia Commit-Bot committed Dec 3, 2020
1 parent d39aec0 commit b81842a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 226 deletions.
9 changes: 0 additions & 9 deletions include/core/SkSamplingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ struct SK_API SkSamplingOptions {
, cubic(c) {}

explicit SkSamplingOptions(SkFilterQuality);

bool operator==(const SkSamplingOptions& other) const {
return useCubic == other.useCubic
&& cubic.B == other.cubic.B
&& cubic.C == other.cubic.C
&& filter == other.filter
&& mipmap == other.mipmap;
}
bool operator!=(const SkSamplingOptions& other) const { return !(*this == other); }
};

#endif
1 change: 0 additions & 1 deletion modules/skottie/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ if (skia_enable_skottie) {
sources = [
"src/SkottieTest.cpp",
"tests/AudioLayer.cpp",
"tests/Image.cpp",
"tests/Keyframe.cpp",
"tests/Text.cpp",
]
Expand Down
39 changes: 15 additions & 24 deletions modules/skottie/src/layers/FootageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ namespace internal {

namespace {

SkMatrix image_matrix(const ImageAsset::FrameData& frame_data, const SkISize& dest_size) {
if (!frame_data.image) {
return SkMatrix::I();
}

return frame_data.matrix * SkMatrix::MakeRectToRect(SkRect::Make(frame_data.image->bounds()),
SkRect::Make(dest_size),
SkMatrix::kCenter_ScaleToFit);
SkMatrix image_matrix(const sk_sp<SkImage>& image, const SkISize& dest_size) {
return image ? SkMatrix::MakeRectToRect(SkRect::Make(image->bounds()),
SkRect::Make(dest_size),
SkMatrix::kCenter_ScaleToFit)
: SkMatrix::I();
}

class FootageAnimator final : public Animator {
Expand All @@ -48,15 +45,10 @@ class FootageAnimator final : public Animator {
return false;
}

auto frame_data = fAsset->getFrameData((t + fTimeBias) * fTimeScale);
const auto m = image_matrix(frame_data, fAssetSize);
if (frame_data.image != fImageNode->getImage() ||
frame_data.sampling != fImageNode->getSamplingOptions() ||
m != fImageTransformNode->getMatrix()) {

fImageNode->setImage(std::move(frame_data.image));
fImageNode->setSamplingOptions(frame_data.sampling);
fImageTransformNode->setMatrix(m);
auto frame = fAsset->getFrame((t + fTimeBias) * fTimeScale);
if (frame != fImageNode->getImage()) {
fImageTransformNode->setMatrix(image_matrix(frame, fAssetSize));
fImageNode->setImage(std::move(frame));
return true;
}

Expand Down Expand Up @@ -110,6 +102,7 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachFootageAsset(const skjson::Objec
SkASSERT(asset_info->fAsset);

auto image_node = sksg::Image::Make(nullptr);
image_node->setQuality(kMedium_SkFilterQuality);

// Optional image transform (mapping the intrinsic image size to declared asset size).
sk_sp<sksg::Matrix<SkMatrix>> image_transform;
Expand All @@ -128,19 +121,17 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachFootageAsset(const skjson::Objec
1 / fFrameRate));
} else {
// No animator needed, resolve the (only) frame upfront.
auto frame_data = asset_info->fAsset->getFrameData(0);
if (!frame_data.image) {
auto frame = asset_info->fAsset->getFrame(0);
if (!frame) {
this->log(Logger::Level::kError, nullptr, "Could not load single-frame image asset.");
return nullptr;
}

const auto m = image_matrix(frame_data, asset_info->fSize);
if (!m.isIdentity()) {
image_transform = sksg::Matrix<SkMatrix>::Make(m);
if (frame->bounds().size() != asset_info->fSize) {
image_transform = sksg::Matrix<SkMatrix>::Make(image_matrix(frame, asset_info->fSize));
}

image_node->setImage(std::move(frame_data.image));
image_node->setSamplingOptions(frame_data.sampling);
image_node->setImage(std::move(frame));
}

// Image layers are sized explicitly.
Expand Down
133 changes: 0 additions & 133 deletions modules/skottie/tests/Image.cpp

This file was deleted.

30 changes: 2 additions & 28 deletions modules/skresources/include/SkResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#define SkResources_DEFINED

#include "include/core/SkData.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
Expand All @@ -36,41 +34,17 @@ class SK_API ImageAsset : public SkRefCnt {
virtual bool isMultiFrame() = 0;

/**
* DEPRECATED: override getFrameData() instead.
*
* Returns the SkImage for a given frame.
*
* If the image asset is static, getFrame() is only called once, at animation load time.
* Otherwise, this gets invoked every time the animation time is adjusted (on every seek).
*
* Embedders should cache and serve the same SkImage whenever possible, for efficiency.
*
* @param t Frame time code, in seconds, relative to the image layer timeline origin
* (in-point).
*/
virtual sk_sp<SkImage> getFrame(float t);

struct FrameData {
// SkImage payload.
sk_sp<SkImage> image;
// Resampling parameters.
SkSamplingOptions sampling;
// Additional image transform to be applied before AE scaling rules.
SkMatrix matrix = SkMatrix::I();
};

/**
* Returns the payload for a given frame.
*
* If the image asset is static, getFrameData() is only called once, at animation load time.
* If the image asset is static, getImage() is only called once, at animation load time.
* Otherwise, this gets invoked every time the animation time is adjusted (on every seek).
*
* Embedders should cache and serve the same SkImage whenever possible, for efficiency.
*
* @param t Frame time code, in seconds, relative to the image layer timeline origin
* (in-point).
*/
virtual FrameData getFrameData(float t);
virtual sk_sp<SkImage> getFrame(float t) = 0;
};

class MultiFrameImageAsset final : public ImageAsset {
Expand Down
13 changes: 0 additions & 13 deletions modules/skresources/src/SkResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,6 @@ class VideoAsset final : public ImageAsset {

} // namespace

sk_sp<SkImage> ImageAsset::getFrame(float t) {
return nullptr;
}

ImageAsset::FrameData ImageAsset::getFrameData(float t) {
// legacy behavior
return {
this->getFrame(t),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest),
SkMatrix::I(),
};
}

sk_sp<MultiFrameImageAsset> MultiFrameImageAsset::Make(sk_sp<SkData> data, bool predecode) {
if (auto codec = SkCodec::MakeFromData(std::move(data))) {
return sk_sp<MultiFrameImageAsset>(
Expand Down
14 changes: 7 additions & 7 deletions modules/sksg/include/SkSGImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "modules/sksg/include/SkSGRenderNode.h"

#include "include/core/SkSamplingOptions.h"
#include "include/core/SkFilterQuality.h"

class SkImage;

Expand All @@ -26,9 +26,9 @@ class Image final : public RenderNode {
return sk_sp<Image>(new Image(std::move(image)));
}

SG_ATTRIBUTE(Image , sk_sp<SkImage> , fImage )
SG_ATTRIBUTE(SamplingOptions, SkSamplingOptions, fSamplingOptions)
SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
SG_ATTRIBUTE(Image, sk_sp<SkImage> , fImage )
SG_ATTRIBUTE(Quality , SkFilterQuality, fQuality )
SG_ATTRIBUTE(AntiAlias, bool , fAntiAlias)

protected:
explicit Image(sk_sp<SkImage>);
Expand All @@ -39,9 +39,9 @@ class Image final : public RenderNode {
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;

private:
SkSamplingOptions fSamplingOptions;
sk_sp<SkImage> fImage;
bool fAntiAlias = true;
sk_sp<SkImage> fImage;
SkFilterQuality fQuality = kNone_SkFilterQuality;
bool fAntiAlias = true;

using INHERITED = RenderNode;
};
Expand Down
12 changes: 1 addition & 11 deletions modules/sksg/src/SkSGImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ void Image::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
return;
}

// Ignoring cubic params and trilerp for now.
// TODO: convert to drawImage(sampling options) when available.
auto legacy_quality = [](const SkSamplingOptions& sampling) {
return
sampling.useCubic ? SkFilterQuality::kHigh_SkFilterQuality :
sampling.filter == SkFilterMode::kNearest ? SkFilterQuality::kNone_SkFilterQuality :
sampling.mipmap == SkMipmapMode::kNone ? SkFilterQuality::kLow_SkFilterQuality :
SkFilterQuality::kMedium_SkFilterQuality;
};

SkPaint paint;
paint.setAntiAlias(fAntiAlias);
paint.setFilterQuality(legacy_quality(fSamplingOptions));
paint.setFilterQuality(fQuality);

sksg::RenderNode::ScopedRenderContext local_ctx(canvas, ctx);
if (ctx) {
Expand Down

0 comments on commit b81842a

Please sign in to comment.