Use SkUniqueCFRef in SkImage*CG.
This clarifies ownership and makes the code more readable.
It is safe to use unique_ptr directly for UniqueCFRef, since
unique_ptr does not call the deleter with nullptr.
Change-Id: I4326a86059fb31488d1e163faca95a6c29960039
Reviewed-on: https://skia-review.googlesource.com/155612
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
diff --git a/src/utils/mac/SkUniqueCFRef.h b/src/utils/mac/SkUniqueCFRef.h
new file mode 100644
index 0000000..6c90727
--- /dev/null
+++ b/src/utils/mac/SkUniqueCFRef.h
@@ -0,0 +1,27 @@
+/*
+ * 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 SkUniqueCFRef_DEFINED
+#define SkUniqueCFRef_DEFINED
+
+#include "SkTypes.h" // Keep this before any #ifdef ...
+#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
+
+#include "SkTemplates.h"
+#include "SkTLogic.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <memory>
+
+namespace {
+template <typename CFRef> using SkUniqueCFRef =
+ std::unique_ptr<skstd::remove_pointer_t<CFRef>,
+ SkFunctionWrapper<void, skstd::remove_pointer_t<CFTypeRef>, CFRelease>>;
+} // namespace
+
+#endif
+#endif