add SkStubHeifDecoderAPI.h
This should let us build SkHeifCodec even without libheif.
I didn't look at libheif itself, so this stub may disagree
a bit with the actual interface... just flailed around until
it compiled and linked.
This turns on the stub in most of our internal builds.
Change-Id: I62ed4993198118b2a8217ec846d92ff637cc8ab9
Reviewed-on: https://skia-review.googlesource.com/62321
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 2b333af..03a11a6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -31,7 +31,7 @@
skia_use_piex = !is_win
skia_use_zlib = true
skia_use_metal = false
- skia_use_libheif = false
+ skia_use_libheif = is_skia_dev_build
skia_android_serial = ""
skia_enable_discrete_gpu = true
diff --git a/src/codec/SkHeifCodec.h b/src/codec/SkHeifCodec.h
index 5c74dd6..6eb8e9c 100644
--- a/src/codec/SkHeifCodec.h
+++ b/src/codec/SkHeifCodec.h
@@ -15,7 +15,16 @@
#include "SkImageInfo.h"
#include "SkSwizzler.h"
#include "SkStream.h"
-#include "HeifDecoderAPI.h"
+
+#if !defined(__has_include)
+ #define __has_include(x) 0
+#endif
+
+#if __has_include("HeifDecoderAPI.h")
+ #include "HeifDecoderAPI.h"
+#else
+ #include "SkStubHeifDecoderAPI.h"
+#endif
class SkHeifCodec : public SkCodec {
public:
diff --git a/src/codec/SkStubHeifDecoderAPI.h b/src/codec/SkStubHeifDecoderAPI.h
new file mode 100644
index 0000000..6987f76
--- /dev/null
+++ b/src/codec/SkStubHeifDecoderAPI.h
@@ -0,0 +1,70 @@
+/*
+ * 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 SkStubHeifDecoderAPI_DEFINED
+#define SkStubHeifDecoderAPI_DEFINED
+
+// This stub implementation of HeifDecoderAPI.h lets us compile SkHeifCodec.cpp
+// even when libheif is not available. It, of course, does nothing and fails to decode.
+
+#include <memory>
+#include <stddef.h>
+#include <stdint.h>
+using off64_t = int64_t;
+
+enum HeifColorFormat {
+ kHeifColorFormat_RGB565,
+ kHeifColorFormat_RGBA_8888,
+ kHeifColorFormat_BGRA_8888,
+};
+
+struct HeifStream {
+ virtual ~HeifStream() {}
+
+ virtual size_t read(void*, size_t) = 0;
+ virtual bool rewind() = 0;
+ virtual bool seek(size_t) = 0;
+ virtual bool hasLength() const = 0;
+ virtual size_t getLength() const = 0;
+};
+
+struct HeifFrameInfo {
+ int mRotationAngle;
+ int mWidth;
+ int mHeight;
+ int mBytesPerPixel;
+
+ size_t mIccSize;
+ std::unique_ptr<char[]> mIccData;
+};
+
+struct HeifDecoder {
+ bool init(HeifStream* stream, HeifFrameInfo*) {
+ delete stream;
+ return false;
+ }
+
+ bool decode(HeifFrameInfo*) {
+ return false;
+ }
+
+ bool setOutputColor(HeifColorFormat) {
+ return false;
+ }
+
+ bool getScanline(uint8_t*) {
+ return false;
+ }
+
+ int skipScanlines(int) {
+ return 0;
+ }
+};
+
+static inline HeifDecoder* createHeifDecoder() { return new HeifDecoder; }
+
+#endif//SkStubHeifDecoderAPI_DEFINED