Allow constrained and unconstrained picture-images
authorMatt Sarett <msarett@google.com>
Mon, 9 Jan 2017 20:59:17 +0000 (15:59 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 9 Jan 2017 21:40:27 +0000 (21:40 +0000)
BUG=skia:

Change-Id: Id9b7b2c82c634fec50f9a57f4b59ce0c02e0706a
Reviewed-on: https://skia-review.googlesource.com/6818
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
include/core/SkImage.h
src/core/SkPictureImageGenerator.cpp
src/image/SkImage.cpp

index 7d282daecf24bbed6c991cdeb2c1d36b5523e8bc..9ecfb272a6629bcb3625d66cd2a0aa45f3e63b33 100644 (file)
@@ -159,15 +159,17 @@ public:
         kF16,
     };
 
-#ifdef SK_USE_LEGACY_MAKE_PICTURE_API
+    /**
+     *  Create a new image from the specified picture.
+     *  This SkImage has no defined BitDepth or SkColorSpace, it is a flexible container for
+     *  draw commands.
+     */
     static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
                                           const SkMatrix* matrix, const SkPaint* paint);
-#endif
 
     /**
      *  Create a new image from the specified picture.
-     *  Creating an SkImage from an SkPicture requires snapping the picture to a particular
-     *  BitDepth and SkColorSpace.
+     *  On creation of the SkImage, snap the SkPicture to a particular BitDepth and SkColorSpace.
      */
     static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture>, const SkISize& dimensions,
                                           const SkMatrix*, const SkPaint*, BitDepth,
index 3a4749b48035c984d95be43e704314c7633c6425..762654af706b960a51851abb79dfd2e925b40a54 100644 (file)
@@ -44,15 +44,15 @@ SkImageGenerator* SkPictureImageGenerator::Create(const SkISize& size, const SkP
                                                   const SkMatrix* matrix, const SkPaint* paint,
                                                   SkImage::BitDepth bitDepth,
                                                   sk_sp<SkColorSpace> colorSpace) {
-    if (!picture || size.isEmpty() || !colorSpace) {
+    if (!picture || size.isEmpty()) {
         return nullptr;
     }
 
-    if (SkImage::BitDepth::kF16 == bitDepth && !colorSpace->gammaIsLinear()) {
+    if (SkImage::BitDepth::kF16 == bitDepth && (!colorSpace || !colorSpace->gammaIsLinear())) {
         return nullptr;
     }
 
-    if (!colorSpace->gammaCloseToSRGB() && !colorSpace->gammaIsLinear()) {
+    if (colorSpace && (!colorSpace->gammaCloseToSRGB() && !colorSpace->gammaIsLinear())) {
         return nullptr;
     }
 
index f49a2ce285609c4f1bde6bfc9795b5f116480205..66301341d379a1c9fd2a09a2b63738be9fa19d01 100644 (file)
@@ -299,13 +299,11 @@ bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
     return true;
 }
 
-#ifdef SK_USE_LEGACY_MAKE_PICTURE_API
 sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
                                         const SkMatrix* matrix, const SkPaint* paint) {
     return SkImage::MakeFromPicture(std::move(picture), dimensions, matrix, paint, BitDepth::kU8,
-                                    SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
+                                    nullptr);
 }
-#endif
 
 sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
                                         const SkMatrix* matrix, const SkPaint* paint,