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 7d282da..9ecfb27 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 3a4749b..762654a 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 f49a2ce..6630134 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,