Revert "create ParticleDrawable for animated Skotties"

This reverts commit ddd64d35c6.

Reason for revert: breaking the android build

Original change's description:
> create ParticleDrawable for animated Skotties
>
> Change-Id: Ieaea5e9c358604a25f0fecd7bac71a0450359653
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538042
> Reviewed-by: Florin Malita <fmalita@google.com>
> Commit-Queue: Jorge Betancourt <jmbetancourt@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

Change-Id: Ida2bfe6359790a49a8c2b4f8a3b96d9b14da5600
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539083
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
Derek Sollenberger 2022-05-11 23:34:40 +00:00 committed by SkCQ
parent 353e2c65c9
commit d4aa36a9b6
11 changed files with 37 additions and 159 deletions

View File

@ -2022,7 +2022,6 @@ if (skia_enable_tools) {
}
deps = [
":flags",
"modules/skresources",
"modules/svg",
]
public_deps = [ ":gpu_tool_utils" ]
@ -3204,10 +3203,7 @@ if (skia_enable_tools) {
"fuzz/oss_fuzz/FuzzSkParagraph.cpp",
"tools/Resources.cpp",
]
deps = [
"modules/skparagraph",
"modules/skresources",
]
deps = [ "modules/skparagraph" ]
}
libfuzzer_app("api_svg_canvas") {

View File

@ -22,7 +22,6 @@ static_library("particles") {
include_dirs = [ "../../tools/timer" ]
deps = [
"../..:skia",
"../skottie",
"../skresources",
]
sources = skia_particle_sources

View File

@ -27,8 +27,6 @@ public:
static sk_sp<SkParticleDrawable> MakeCircle(int radius);
static sk_sp<SkParticleDrawable> MakeImage(const char* imagePath, const char* imageName,
int cols, int rows);
static sk_sp<SkParticleDrawable> MakeSkottie(const char* animPath, const char* animName,
int cols, int rows);
};
#endif // SkParticleEffect_DEFINED

View File

@ -42,7 +42,6 @@ generated_cc_atom(
"//include/private:SkTPin_hdr",
"//modules/particles/include:SkParticleData_hdr",
"//modules/particles/include:SkParticleDrawable_hdr",
"//modules/skottie/include:Skottie_hdr",
"//modules/skresources/include:SkResources_hdr",
"//src/core:SkAutoMalloc_hdr",
],

View File

@ -16,12 +16,9 @@
#include "include/core/SkSurface.h"
#include "include/private/SkTPin.h"
#include "modules/particles/include/SkParticleData.h"
#include "modules/skottie/include/Skottie.h"
#include "modules/skresources/include/SkResources.h"
#include "src/core/SkAutoMalloc.h"
#include <math.h>
static sk_sp<SkImage> make_circle_image(int radius) {
auto surface = SkSurface::MakeRasterN32Premul(radius * 2, radius * 2);
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
@ -184,76 +181,10 @@ private:
sk_sp<SkImage> fImage;
};
class SkSkottieDrawable : public SkParticleDrawable {
public:
SkSkottieDrawable(const char* animationPath = "", const char* animationName = "")
: fPath(animationPath)
, fName(animationName) {}
REFLECTED(SkSkottieDrawable, SkParticleDrawable)
void draw(SkCanvas* canvas, const SkParticles& particles, int count) override {
float* animationFrames = particles.fData[SkParticles::kSpriteFrame].get();
float* scales = particles.fData[SkParticles::kScale].get();
float* dir[] = {
particles.fData[SkParticles::kHeadingX].get(),
particles.fData[SkParticles::kHeadingY].get(),
};
float width = fAnimation->size().width();
float height = fAnimation->size().height();
for (int i = 0; i < count; ++i) {
// get skottie frame
double frame = animationFrames[i] * fAnimation->duration() * fAnimation->fps();
frame = SkTPin(frame, 0.0, fAnimation->duration() * fAnimation->fps());
// move and scale
SkAutoCanvasRestore acr(canvas, true);
float s = scales[i];
float rads = atan2(dir[0][i], -dir[1][i]);
auto mat = SkMatrix::Translate(particles.fData[SkParticles::kPositionX][i],
particles.fData[SkParticles::kPositionY][i])
* SkMatrix::Scale(s, s)
* SkMatrix::RotateRad(rads)
* SkMatrix::Translate(width / -2, height / -2);
canvas->concat(mat);
// draw
fAnimation->seekFrame(frame);
fAnimation->render(canvas);
}
}
void prepare(const skresources::ResourceProvider* resourceProvider) override {
skottie::Animation::Builder builder;
if (auto asset = resourceProvider->load(fPath.c_str(), fName.c_str())) {
SkDebugf("Loading lottie particle \"%s:%s\"\n", fPath.c_str(), fName.c_str());
fAnimation = builder.make(reinterpret_cast<const char*>(asset->data()), asset->size());
}
if (!fAnimation) {
SkDebugf("Could not load bodymovin animation \"%s:%s\"\n", fPath.c_str(),
fName.c_str());
}
}
void visitFields(SkFieldVisitor* v) override {
v->visit("Path", fPath);
v->visit("Name", fName);
}
private:
SkString fPath;
SkString fName;
// Cached
sk_sp<skottie::Animation> fAnimation;
};
void SkParticleDrawable::RegisterDrawableTypes() {
REGISTER_REFLECTED(SkParticleDrawable);
REGISTER_REFLECTED(SkCircleDrawable);
REGISTER_REFLECTED(SkImageDrawable);
REGISTER_REFLECTED(SkSkottieDrawable);
}
sk_sp<SkParticleDrawable> SkParticleDrawable::MakeCircle(int radius) {
@ -265,9 +196,3 @@ sk_sp<SkParticleDrawable> SkParticleDrawable::MakeImage(const char* imagePath,
int cols, int rows) {
return sk_sp<SkParticleDrawable>(new SkImageDrawable(imagePath, imageName, cols, rows));
}
sk_sp<SkParticleDrawable> SkParticleDrawable::MakeSkottie(const char* animPath,
const char* animName,
int cols, int rows) {
return sk_sp<SkParticleDrawable>(new SkSkottieDrawable(animPath, animName));
}

View File

@ -1,28 +0,0 @@
{
"MaxCount": 32,
"Drawable": {
"Type": "SkSkottieDrawable",
"Path": "skottie",
"Name": "skottie_sample_2.json"
},
"Code": [
"void effectSpawn(inout Effect effect) {",
" effect.rate = 15;",
"}",
"",
"void spawn(inout Particle p) {",
" p.lifetime = 1.0 + rand(p.seed) * 2.0;",
" p.scale = 0.25;",
"}",
"",
"void update(inout Particle p) {",
" p.frame = p.age;",
" float a = radians(rand(p.seed) * 360);",
" float invAge = 1 - p.age;",
" p.vel = float2(cos(a), sin(a)) * mix(250, 550, rand(p.seed)) * invAge * invAge;",
" p.dir = normalize(p.vel);",
"}",
""
],
"Bindings": []
}

View File

@ -249,7 +249,6 @@ generated_cc_atom(
"//include/core:SkData_hdr",
"//include/core:SkImage_hdr",
"//include/core:SkString_hdr",
"//modules/skresources/include:SkResources_hdr",
],
)
@ -265,7 +264,6 @@ generated_cc_atom(
"//include/core:SkData_hdr",
"//include/core:SkImageGenerator_hdr",
"//include/core:SkImage_hdr",
"//include/core:SkPath_hdr",
"//include/core:SkStream_hdr",
"//include/core:SkTypeface_hdr",
"//src/core:SkOSFile_hdr",

View File

@ -10,7 +10,6 @@
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkPath.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"
#include "src/core/SkOSFile.h"
@ -60,24 +59,3 @@ sk_sp<SkData> GetResourceAsData(const char* resource) {
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource, int ttcIndex) {
return SkTypeface::MakeFromStream(GetResourceAsStream(resource), ttcIndex);
}
sk_sp<SkData> TestingResourceProvider::load(const char path[], const char name[]) const {
auto it = fResources.find(name);
if (it != fResources.end()) {
return it->second;
} else {
return GetResourceAsData(SkOSPath::Join(path, name).c_str());
}
}
sk_sp<skresources::ImageAsset> TestingResourceProvider::loadImageAsset(const char resource_path[],
const char resource_name[],
const char /*resource_id*/[])
const {
auto data = this->load(resource_path, resource_name);
return skresources::MultiFrameImageAsset::Make(data);
}
void TestingResourceProvider::addPath(const char resource_name[], const SkPath& path) {
fResources[resource_name] = path.serialize();
}

View File

@ -12,8 +12,6 @@
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkString.h"
#include "modules/skresources/include/SkResources.h"
#include <unordered_map>
class SkBitmap;
class SkData;
@ -40,18 +38,4 @@ std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource);
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource, int ttcIndex = 0);
// A simple ResourceProvider implementing base functionality for loading images and skotties
class TestingResourceProvider : public skresources::ResourceProvider {
public:
TestingResourceProvider() {}
sk_sp<SkData> load(const char resource_path[], const char resource_name[]) const override;
sk_sp<skresources::ImageAsset> loadImageAsset(const char resource_path[],
const char resource_name[],
const char /*resource_id*/[]) const override;
void addPath(const char resource_name[], const SkPath& path);
private:
std::unordered_map<std::string, sk_sp<SkData>> fResources;
};
#endif // Resources_DEFINED

View File

@ -27,6 +27,36 @@
using namespace sk_app;
class TestingResourceProvider : public skresources::ResourceProvider {
public:
TestingResourceProvider() {}
sk_sp<SkData> load(const char resource_path[], const char resource_name[]) const override {
auto it = fResources.find(resource_name);
if (it != fResources.end()) {
return it->second;
} else {
return GetResourceAsData(SkOSPath::Join(resource_path, resource_name).c_str());
}
}
sk_sp<skresources::ImageAsset> loadImageAsset(const char resource_path[],
const char resource_name[],
const char /*resource_id*/[]) const override {
auto data = this->load(resource_path, resource_name);
return skresources::MultiFrameImageAsset::Make(data);
}
void addPath(const char resource_name[], const SkPath& path) {
fResources[resource_name] = path.serialize();
}
private:
std::unordered_map<std::string, sk_sp<SkData>> fResources;
};
///////////////////////////////////////////////////////////////////////////////
static int InputTextCallback(ImGuiInputTextCallbackData* data) {
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
SkString* s = (SkString*)data->UserData;

View File

@ -116,7 +116,6 @@ public:
static std::unique_ptr<Decorator> MakeConfetti() { return std::make_unique<ParticleMarker>("confetti.json"); }
static std::unique_ptr<Decorator> MakeSine() { return std::make_unique<ParticleMarker>("sinusoidal_emitter.json"); }
static std::unique_ptr<Decorator> MakeSkottie() { return std::make_unique<ParticleMarker>("skottie_particle.json"); }
explicit ParticleMarker(const char* effect_file) {
SkParticleEffect::RegisterParticleTypes();
@ -127,8 +126,9 @@ public:
skjson::DOM dom(static_cast<const char*>(fileData->data()), fileData->size());
SkFromJsonVisitor fromJson(dom.root());
params->visitFields(&fromJson);
auto provider = sk_make_sp<TestingResourceProvider>();
params->prepare(provider.get());
// We can pass in a null pointer because the SkCircleDrawable used in confetti.json
// doesn't use the resource provider
params->prepare(nullptr);
} else {
SkDebugf("no particle effect file found at: %s\n", effectJsonPath.c_str());
}
@ -157,10 +157,9 @@ static const struct DecoratorRec {
const char* fName;
std::unique_ptr<Decorator>(*fFactory)();
} kDecorators[] = {
{ "Simple marker", SimpleMarker::Make },
{ "Confetti", ParticleMarker::MakeConfetti },
{ "Sine Wave", ParticleMarker::MakeSine },
{ "Nested Skotties", ParticleMarker::MakeSkottie },
{ "Simple marker", SimpleMarker::Make },
{ "Confetti", ParticleMarker::MakeConfetti },
{ "Sine Wave", ParticleMarker::MakeSine },
};
} // namespace