diff --git a/BUILD.gn b/BUILD.gn index deb0e79a09..850fb61bd6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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") { diff --git a/modules/particles/BUILD.gn b/modules/particles/BUILD.gn index 9c12f5a73f..746c2782ae 100644 --- a/modules/particles/BUILD.gn +++ b/modules/particles/BUILD.gn @@ -22,7 +22,6 @@ static_library("particles") { include_dirs = [ "../../tools/timer" ] deps = [ "../..:skia", - "../skottie", "../skresources", ] sources = skia_particle_sources diff --git a/modules/particles/include/SkParticleDrawable.h b/modules/particles/include/SkParticleDrawable.h index 5e9f4a2804..82a7bf0c28 100644 --- a/modules/particles/include/SkParticleDrawable.h +++ b/modules/particles/include/SkParticleDrawable.h @@ -27,8 +27,6 @@ public: static sk_sp MakeCircle(int radius); static sk_sp MakeImage(const char* imagePath, const char* imageName, int cols, int rows); - static sk_sp MakeSkottie(const char* animPath, const char* animName, - int cols, int rows); }; #endif // SkParticleEffect_DEFINED diff --git a/modules/particles/src/BUILD.bazel b/modules/particles/src/BUILD.bazel index 9124fcfdb2..7a9a5bc398 100644 --- a/modules/particles/src/BUILD.bazel +++ b/modules/particles/src/BUILD.bazel @@ -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", ], diff --git a/modules/particles/src/SkParticleDrawable.cpp b/modules/particles/src/SkParticleDrawable.cpp index 6abd2227b6..790eb7bf22 100644 --- a/modules/particles/src/SkParticleDrawable.cpp +++ b/modules/particles/src/SkParticleDrawable.cpp @@ -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 - static sk_sp 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 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(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 fAnimation; -}; - void SkParticleDrawable::RegisterDrawableTypes() { REGISTER_REFLECTED(SkParticleDrawable); REGISTER_REFLECTED(SkCircleDrawable); REGISTER_REFLECTED(SkImageDrawable); - REGISTER_REFLECTED(SkSkottieDrawable); } sk_sp SkParticleDrawable::MakeCircle(int radius) { @@ -265,9 +196,3 @@ sk_sp SkParticleDrawable::MakeImage(const char* imagePath, int cols, int rows) { return sk_sp(new SkImageDrawable(imagePath, imageName, cols, rows)); } - -sk_sp SkParticleDrawable::MakeSkottie(const char* animPath, - const char* animName, - int cols, int rows) { - return sk_sp(new SkSkottieDrawable(animPath, animName)); -} diff --git a/resources/particles/skottie_particle.json b/resources/particles/skottie_particle.json deleted file mode 100644 index 1419bfc165..0000000000 --- a/resources/particles/skottie_particle.json +++ /dev/null @@ -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": [] - } \ No newline at end of file diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 85b39c4d36..42e9938075 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -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", diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 2cdb1c6c4e..5e239251ad 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -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 GetResourceAsData(const char* resource) { sk_sp MakeResourceAsTypeface(const char* resource, int ttcIndex) { return SkTypeface::MakeFromStream(GetResourceAsStream(resource), ttcIndex); } - -sk_sp 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 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(); -} diff --git a/tools/Resources.h b/tools/Resources.h index a9b93b5ce7..0ab7fdf23c 100644 --- a/tools/Resources.h +++ b/tools/Resources.h @@ -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 class SkBitmap; class SkData; @@ -40,18 +38,4 @@ std::unique_ptr GetResourceAsStream(const char* resource); sk_sp 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 load(const char resource_path[], const char resource_name[]) const override; - sk_sp 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> fResources; -}; - #endif // Resources_DEFINED diff --git a/tools/viewer/ParticlesSlide.cpp b/tools/viewer/ParticlesSlide.cpp index 513b99a008..1ae58bada0 100644 --- a/tools/viewer/ParticlesSlide.cpp +++ b/tools/viewer/ParticlesSlide.cpp @@ -27,6 +27,36 @@ using namespace sk_app; +class TestingResourceProvider : public skresources::ResourceProvider { +public: + TestingResourceProvider() {} + + sk_sp 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 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> fResources; +}; + +/////////////////////////////////////////////////////////////////////////////// + static int InputTextCallback(ImGuiInputTextCallbackData* data) { if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) { SkString* s = (SkString*)data->UserData; diff --git a/tools/viewer/SkottieSlide.cpp b/tools/viewer/SkottieSlide.cpp index 3a8b74a87c..046d57672d 100644 --- a/tools/viewer/SkottieSlide.cpp +++ b/tools/viewer/SkottieSlide.cpp @@ -116,7 +116,6 @@ public: static std::unique_ptr MakeConfetti() { return std::make_unique("confetti.json"); } static std::unique_ptr MakeSine() { return std::make_unique("sinusoidal_emitter.json"); } - static std::unique_ptr MakeSkottie() { return std::make_unique("skottie_particle.json"); } explicit ParticleMarker(const char* effect_file) { SkParticleEffect::RegisterParticleTypes(); @@ -127,8 +126,9 @@ public: skjson::DOM dom(static_cast(fileData->data()), fileData->size()); SkFromJsonVisitor fromJson(dom.root()); params->visitFields(&fromJson); - auto provider = sk_make_sp(); - 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(*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