aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/android
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
commita87508008dfa1604baf2d4e39bf44704c00f261c (patch)
tree0be2ade96772037a02803b30e157c367d931e3d9 /src/deps/skia/include/android
parent4a19a3f07f1887903e5638a3be167f0c7b377ba3 (diff)
downloadbun-jarred/canvas.tar.gz
bun-jarred/canvas.tar.zst
bun-jarred/canvas.zip
Diffstat (limited to 'src/deps/skia/include/android')
-rw-r--r--src/deps/skia/include/android/BUILD.bazel24
-rw-r--r--src/deps/skia/include/android/SkAndroidFrameworkUtils.h61
-rw-r--r--src/deps/skia/include/android/SkAnimatedImage.h179
3 files changed, 264 insertions, 0 deletions
diff --git a/src/deps/skia/include/android/BUILD.bazel b/src/deps/skia/include/android/BUILD.bazel
new file mode 100644
index 000000000..0ee0f5aa7
--- /dev/null
+++ b/src/deps/skia/include/android/BUILD.bazel
@@ -0,0 +1,24 @@
+load("//bazel:macros.bzl", "generated_cc_atom")
+
+generated_cc_atom(
+ name = "SkAndroidFrameworkUtils_hdr",
+ hdrs = ["SkAndroidFrameworkUtils.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ "//include/core:SkRefCnt_hdr",
+ "//include/core:SkTypes_hdr",
+ ],
+)
+
+generated_cc_atom(
+ name = "SkAnimatedImage_hdr",
+ hdrs = ["SkAnimatedImage.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ "//include/codec:SkCodecAnimation_hdr",
+ "//include/core:SkBitmap_hdr",
+ "//include/core:SkDrawable_hdr",
+ "//include/core:SkMatrix_hdr",
+ "//include/core:SkRect_hdr",
+ ],
+)
diff --git a/src/deps/skia/include/android/SkAndroidFrameworkUtils.h b/src/deps/skia/include/android/SkAndroidFrameworkUtils.h
new file mode 100644
index 000000000..577bfab72
--- /dev/null
+++ b/src/deps/skia/include/android/SkAndroidFrameworkUtils.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkAndroidFrameworkUtils_DEFINED
+#define SkAndroidFrameworkUtils_DEFINED
+
+#include "include/core/SkRefCnt.h"
+#include "include/core/SkTypes.h"
+
+#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
+
+class SkCanvas;
+struct SkIRect;
+struct SkRect;
+class SkSurface;
+
+/**
+ * SkAndroidFrameworkUtils expose private APIs used only by Android framework.
+ */
+class SkAndroidFrameworkUtils {
+public:
+
+#if SK_SUPPORT_GPU
+ /**
+ * clipWithStencil draws the current clip into a stencil buffer with reference value and mask
+ * set to 0x1. This function works only on a GPU canvas.
+ *
+ * @param canvas A GPU canvas that has a non-empty clip.
+ *
+ * @return true on success or false if clip is empty or not a GPU canvas.
+ */
+ static bool clipWithStencil(SkCanvas* canvas);
+#endif //SK_SUPPORT_GPU
+
+ static void SafetyNetLog(const char*);
+
+ static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas);
+
+ static int SaveBehind(SkCanvas* canvas, const SkRect* subset);
+
+ // Operating within the canvas' clip stack, this resets the geometry of the clip to be wide
+ // open modula any device clip restriction that was set outside of the clip stack.
+ static void ResetClip(SkCanvas* canvas);
+
+ /**
+ * Unrolls a chain of nested SkPaintFilterCanvas to return the base wrapped canvas.
+ *
+ * @param canvas A SkPaintFilterCanvas or any other SkCanvas subclass.
+ *
+ * @return SkCanvas that was found in the innermost SkPaintFilterCanvas.
+ */
+ static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas);
+};
+
+#endif // SK_BUILD_FOR_ANDROID_ANDROID
+
+#endif // SkAndroidFrameworkUtils_DEFINED
diff --git a/src/deps/skia/include/android/SkAnimatedImage.h b/src/deps/skia/include/android/SkAnimatedImage.h
new file mode 100644
index 000000000..8143c1722
--- /dev/null
+++ b/src/deps/skia/include/android/SkAnimatedImage.h
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkAnimatedImage_DEFINED
+#define SkAnimatedImage_DEFINED
+
+#include "include/codec/SkCodecAnimation.h"
+#include "include/core/SkBitmap.h"
+#include "include/core/SkDrawable.h"
+#include "include/core/SkMatrix.h"
+#include "include/core/SkRect.h"
+
+class SkAndroidCodec;
+class SkImage;
+class SkPicture;
+
+/**
+ * Thread unsafe drawable for drawing animated images (e.g. GIF).
+ */
+class SK_API SkAnimatedImage : public SkDrawable {
+public:
+ /**
+ * Create an SkAnimatedImage from the SkAndroidCodec.
+ *
+ * Returns null on failure to allocate pixels. On success, this will
+ * decode the first frame.
+ *
+ * @param info Width and height may require scaling.
+ * @param cropRect Rectangle to crop to after scaling.
+ * @param postProcess Picture to apply after scaling and cropping.
+ */
+ static sk_sp<SkAnimatedImage> Make(std::unique_ptr<SkAndroidCodec>,
+ const SkImageInfo& info, SkIRect cropRect, sk_sp<SkPicture> postProcess);
+
+ /**
+ * Simpler version that uses the default size, no cropping, and no postProcess.
+ */
+ static sk_sp<SkAnimatedImage> Make(std::unique_ptr<SkAndroidCodec>);
+
+ ~SkAnimatedImage() override;
+
+ /**
+ * Reset the animation to the beginning.
+ */
+ void reset();
+
+ /**
+ * Whether the animation completed.
+ *
+ * Returns true after all repetitions are complete, or an error stops the
+ * animation. Gets reset to false if the animation is restarted.
+ */
+ bool isFinished() const { return fFinished; }
+
+ /**
+ * Returned by decodeNextFrame and currentFrameDuration if the animation
+ * is not running.
+ */
+ static constexpr int kFinished = -1;
+
+ /**
+ * Decode the next frame.
+ *
+ * If the animation is on the last frame or has hit an error, returns
+ * kFinished.
+ */
+ int decodeNextFrame();
+
+ /**
+ * Returns the current frame as an SkImage. The SkImage will not change
+ * after it has been returned.
+ * If there is no current frame, nullptr will be returned.
+ */
+ sk_sp<SkImage> getCurrentFrame();
+
+ /**
+ * How long to display the current frame.
+ *
+ * Useful for the first frame, for which decodeNextFrame is called
+ * internally.
+ */
+ int currentFrameDuration() {
+ return fCurrentFrameDuration;
+ }
+
+ /**
+ * Change the repetition count.
+ *
+ * By default, the image will repeat the number of times indicated in the
+ * encoded data.
+ *
+ * Use SkCodec::kRepetitionCountInfinite for infinite, and 0 to show all
+ * frames once and then stop.
+ */
+ void setRepetitionCount(int count);
+
+ /**
+ * Return the currently set repetition count.
+ */
+ int getRepetitionCount() const {
+ return fRepetitionCount;
+ }
+
+ /**
+ * Return the total number of frames in the animation.
+ */
+ int getFrameCount() const { return fFrameCount; }
+
+protected:
+ SkRect onGetBounds() override;
+ void onDraw(SkCanvas*) override;
+
+private:
+ struct Frame {
+ SkBitmap fBitmap;
+ int fIndex;
+ SkCodecAnimation::DisposalMethod fDisposalMethod;
+
+ // init() may have to create a new SkPixelRef, if the
+ // current one is already in use by another owner (e.g.
+ // an SkPicture). This determines whether to copy the
+ // existing one to the new one.
+ enum class OnInit {
+ // Restore the image from the old SkPixelRef to the
+ // new one.
+ kRestoreIfNecessary,
+ // No need to restore.
+ kNoRestore,
+ };
+
+ Frame();
+ bool init(const SkImageInfo& info, OnInit);
+ bool copyTo(Frame*) const;
+ };
+
+ std::unique_ptr<SkAndroidCodec> fCodec;
+ SkImageInfo fDecodeInfo;
+ const SkIRect fCropRect;
+ const sk_sp<SkPicture> fPostProcess;
+ const int fFrameCount;
+ SkMatrix fMatrix;
+ int fSampleSize;
+
+ bool fFinished;
+ int fCurrentFrameDuration;
+ Frame fDisplayFrame;
+ Frame fDecodingFrame;
+ Frame fRestoreFrame;
+ int fRepetitionCount;
+ int fRepetitionsCompleted;
+
+ SkAnimatedImage(std::unique_ptr<SkAndroidCodec>, const SkImageInfo& requestedInfo,
+ SkIRect cropRect, sk_sp<SkPicture> postProcess);
+
+ int computeNextFrame(int current, bool* animationEnded);
+ double finish();
+
+ /**
+ * True if there is no crop, orientation, or post decoding scaling.
+ */
+ bool simple() const { return fMatrix.isIdentity() && !fPostProcess
+ && fCropRect == fDecodeInfo.bounds(); }
+
+ /**
+ * Returns the current frame as an SkImage.
+ *
+ * Like getCurrentFrame, but only returns the raw data from the internal SkBitmap. (i.e. no
+ * scaling, orientation-correction or cropping.) If simple(), this is the final output.
+ */
+ sk_sp<SkImage> getCurrentFrameSimple();
+
+ using INHERITED = SkDrawable;
+};
+
+#endif // SkAnimatedImage_DEFINED