Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/codec/SkCodec.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkBitmap.h" |
| 11 | #include "include/core/SkCanvas.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkColorSpace.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkData.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 15 | #include "include/core/SkImageInfo.h" |
| 16 | #include "include/core/SkPaint.h" |
| 17 | #include "include/core/SkPicture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/core/SkPictureRecorder.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 19 | #include "include/core/SkRect.h" |
| 20 | #include "include/core/SkRefCnt.h" |
| 21 | #include "include/core/SkSize.h" |
| 22 | #include "include/core/SkStream.h" |
| 23 | #include "include/core/SkString.h" |
| 24 | #include "include/core/SkTypes.h" |
Adlai Holler | 4caa935 | 2020-07-16 10:58:58 -0400 | [diff] [blame] | 25 | #include "include/gpu/GrDirectContext.h" |
Kevin Lubick | 7a2d1b3 | 2023-04-04 09:50:57 -0400 | [diff] [blame] | 26 | #include "include/gpu/ganesh/SkImageGanesh.h" |
Kevin Lubick | 52904d3 | 2022-06-29 15:34:49 -0400 | [diff] [blame] | 27 | #include "modules/skcms/skcms.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "tools/Resources.h" |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 29 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <memory> |
| 32 | #include <utility> |
| 33 | |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 34 | static const int kWidth = 64; |
| 35 | static const int kHeight = 64; |
| 36 | |
Brian Osman | b1168a7 | 2017-03-20 14:21:18 -0400 | [diff] [blame] | 37 | static sk_sp<SkImage> make_raster_image(SkColorType colorType) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 38 | std::unique_ptr<SkStream> stream(GetResourceAsStream("images/google_chrome.ico")); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 39 | std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream)); |
Hal Canary | baa2a28 | 2018-11-26 15:34:12 -0500 | [diff] [blame] | 40 | if (!codec) { |
| 41 | return nullptr; |
| 42 | } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 43 | |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 44 | SkImageInfo info = codec->getInfo().makeWH(kWidth, kHeight) |
| 45 | .makeColorType(colorType) |
Brian Osman | 6b62296 | 2018-08-27 19:16:02 +0000 | [diff] [blame] | 46 | .makeAlphaType(kPremul_SkAlphaType); |
Mike Reed | 844beb5 | 2021-01-25 15:36:09 -0500 | [diff] [blame] | 47 | return std::get<0>(codec->getImage(info)); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 50 | static sk_sp<SkImage> make_codec_image() { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 51 | sk_sp<SkData> encoded = GetResourceAsData("images/randPixels.png"); |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 52 | return SkImages::DeferredFromEncodedData(encoded); |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void draw_contents(SkCanvas* canvas) { |
| 56 | SkPaint paint; |
| 57 | paint.setStyle(SkPaint::kStroke_Style); |
| 58 | paint.setStrokeWidth(20); |
| 59 | paint.setColor(0xFF800000); |
| 60 | canvas->drawCircle(40, 40, 35, paint); |
| 61 | paint.setColor(0xFF008000); |
| 62 | canvas->drawCircle(50, 50, 35, paint); |
| 63 | paint.setColor(0xFF000080); |
| 64 | canvas->drawCircle(60, 60, 35, paint); |
| 65 | } |
| 66 | |
Matt Sarett | 9df70bb | 2017-02-14 13:50:43 -0500 | [diff] [blame] | 67 | static sk_sp<SkImage> make_picture_image() { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 68 | SkPictureRecorder recorder; |
| 69 | draw_contents(recorder.beginRecording(SkRect::MakeIWH(kWidth, kHeight))); |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 70 | return SkImages::DeferredFromPicture(recorder.finishRecordingAsPicture(), |
| 71 | SkISize::Make(kWidth, kHeight), |
| 72 | nullptr, |
| 73 | nullptr, |
| 74 | SkImages::BitDepth::kU8, |
| 75 | SkColorSpace::MakeSRGB()); |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Matt Sarett | 733340a | 2017-05-02 16:19:51 -0400 | [diff] [blame] | 78 | static sk_sp<SkColorSpace> make_parametric_transfer_fn(const SkColorSpacePrimaries& primaries) { |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 79 | skcms_Matrix3x3 toXYZD50; |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 80 | SkAssertResult(primaries.toXYZD50(&toXYZD50)); |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 81 | skcms_TransferFunction fn = { 1.8f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f }; |
Matt Sarett | 733340a | 2017-05-02 16:19:51 -0400 | [diff] [blame] | 82 | return SkColorSpace::MakeRGB(fn, toXYZD50); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static sk_sp<SkColorSpace> make_wide_gamut() { |
| 86 | // ProPhoto |
| 87 | SkColorSpacePrimaries primaries; |
| 88 | primaries.fRX = 0.7347f; |
| 89 | primaries.fRY = 0.2653f; |
| 90 | primaries.fGX = 0.1596f; |
| 91 | primaries.fGY = 0.8404f; |
| 92 | primaries.fBX = 0.0366f; |
| 93 | primaries.fBY = 0.0001f; |
| 94 | primaries.fWX = 0.34567f; |
| 95 | primaries.fWY = 0.35850f; |
Matt Sarett | 733340a | 2017-05-02 16:19:51 -0400 | [diff] [blame] | 96 | return make_parametric_transfer_fn(primaries); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static sk_sp<SkColorSpace> make_small_gamut() { |
| 100 | SkColorSpacePrimaries primaries; |
| 101 | primaries.fRX = 0.50f; |
| 102 | primaries.fRY = 0.33f; |
| 103 | primaries.fGX = 0.30f; |
| 104 | primaries.fGY = 0.50f; |
| 105 | primaries.fBX = 0.25f; |
| 106 | primaries.fBY = 0.16f; |
| 107 | primaries.fWX = 0.3127f; |
| 108 | primaries.fWY = 0.3290f; |
Matt Sarett | 733340a | 2017-05-02 16:19:51 -0400 | [diff] [blame] | 109 | return make_parametric_transfer_fn(primaries); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 110 | } |
| 111 | |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 112 | static void draw_image(GrDirectContext* dContext, SkCanvas* canvas, SkImage* image, |
| 113 | SkColorType dstColorType, SkAlphaType dstAlphaType, |
| 114 | sk_sp<SkColorSpace> dstColorSpace, SkImage::CachingHint hint) { |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 115 | size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(dstColorType); |
| 116 | sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height()); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 117 | SkImageInfo dstInfo = SkImageInfo::Make(image->width(), image->height(), dstColorType, |
| 118 | dstAlphaType, dstColorSpace); |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 119 | if (!image->readPixels(dContext, dstInfo, data->writable_data(), rowBytes, 0, 0, hint)) { |
Brian Osman | 8915058 | 2017-03-20 16:54:28 -0400 | [diff] [blame] | 120 | memset(data->writable_data(), 0, rowBytes * image->height()); |
| 121 | } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 122 | |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 123 | // Now that we have called readPixels(), dump the raw pixels into an srgb image. |
Brian Osman | 6b62296 | 2018-08-27 19:16:02 +0000 | [diff] [blame] | 124 | sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB(); |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 125 | sk_sp<SkImage> raw = SkImages::RasterFromData(dstInfo.makeColorSpace(srgb), data, rowBytes); |
Mike Reed | 8d29ab6 | 2021-01-23 18:10:39 -0500 | [diff] [blame] | 126 | canvas->drawImage(raw.get(), 0.0f, 0.0f); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | class ReadPixelsGM : public skiagm::GM { |
| 130 | public: |
| 131 | ReadPixelsGM() {} |
| 132 | |
| 133 | protected: |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 134 | SkString getName() const override { return SkString("readpixels"); } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 135 | |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 136 | SkISize getISize() override { return SkISize::Make(6 * kWidth, 9 * kHeight); } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 137 | |
| 138 | void onDraw(SkCanvas* canvas) override { |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 139 | const SkAlphaType alphaTypes[] = { |
| 140 | kUnpremul_SkAlphaType, |
| 141 | kPremul_SkAlphaType, |
| 142 | }; |
| 143 | const SkColorType colorTypes[] = { |
| 144 | kRGBA_8888_SkColorType, |
| 145 | kBGRA_8888_SkColorType, |
| 146 | kRGBA_F16_SkColorType, |
| 147 | }; |
| 148 | const sk_sp<SkColorSpace> colorSpaces[] = { |
| 149 | make_wide_gamut(), |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 150 | SkColorSpace::MakeSRGB(), |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 151 | make_small_gamut(), |
| 152 | }; |
| 153 | |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 154 | for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) { |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 155 | for (SkColorType srcColorType : colorTypes) { |
Brian Osman | b1168a7 | 2017-03-20 14:21:18 -0400 | [diff] [blame] | 156 | canvas->save(); |
| 157 | sk_sp<SkImage> image = make_raster_image(srcColorType); |
Hal Canary | baa2a28 | 2018-11-26 15:34:12 -0500 | [diff] [blame] | 158 | if (!image) { |
| 159 | continue; |
| 160 | } |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 161 | auto dContext = GrAsDirectContext(canvas->recordingContext()); |
| 162 | if (dContext) { |
Kevin Lubick | 7a2d1b3 | 2023-04-04 09:50:57 -0400 | [diff] [blame] | 163 | image = SkImages::TextureFromImage(dContext, image); |
Brian Osman | 8915058 | 2017-03-20 16:54:28 -0400 | [diff] [blame] | 164 | } |
| 165 | if (image) { |
| 166 | for (SkColorType dstColorType : colorTypes) { |
| 167 | for (SkAlphaType dstAlphaType : alphaTypes) { |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 168 | draw_image(dContext, canvas, image.get(), dstColorType, dstAlphaType, |
Brian Osman | 8915058 | 2017-03-20 16:54:28 -0400 | [diff] [blame] | 169 | dstColorSpace, SkImage::kAllow_CachingHint); |
| 170 | canvas->translate((float)kWidth, 0.0f); |
| 171 | } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 172 | } |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 173 | } |
Brian Osman | b1168a7 | 2017-03-20 14:21:18 -0400 | [diff] [blame] | 174 | canvas->restore(); |
| 175 | canvas->translate(0.0f, (float) kHeight); |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 181 | using INHERITED = skiagm::GM; |
Matt Sarett | 909d379 | 2016-12-22 10:52:25 -0500 | [diff] [blame] | 182 | }; |
| 183 | DEF_GM( return new ReadPixelsGM; ) |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 184 | |
| 185 | class ReadPixelsCodecGM : public skiagm::GM { |
| 186 | public: |
| 187 | ReadPixelsCodecGM() {} |
| 188 | |
| 189 | protected: |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 190 | SkString getName() const override { return SkString("readpixelscodec"); } |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 191 | |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 192 | SkISize getISize() override { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 193 | return SkISize::Make(3 * (kEncodedWidth + 1), 12 * (kEncodedHeight + 1)); |
| 194 | } |
| 195 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 196 | DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 197 | if (!canvas->imageInfo().colorSpace()) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 198 | *errorMsg = "This gm is only interesting in color correct modes."; |
| 199 | return DrawResult::kSkip; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | const SkAlphaType alphaTypes[] = { |
| 203 | kUnpremul_SkAlphaType, |
| 204 | kPremul_SkAlphaType, |
| 205 | }; |
| 206 | const SkColorType colorTypes[] = { |
| 207 | kRGBA_8888_SkColorType, |
| 208 | kBGRA_8888_SkColorType, |
| 209 | kRGBA_F16_SkColorType, |
| 210 | }; |
| 211 | const sk_sp<SkColorSpace> colorSpaces[] = { |
| 212 | make_wide_gamut(), |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 213 | SkColorSpace::MakeSRGB(), |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 214 | make_small_gamut(), |
| 215 | }; |
| 216 | const SkImage::CachingHint hints[] = { |
| 217 | SkImage::kAllow_CachingHint, |
| 218 | SkImage::kDisallow_CachingHint, |
| 219 | }; |
| 220 | |
| 221 | sk_sp<SkImage> image = make_codec_image(); |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 222 | for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 223 | canvas->save(); |
| 224 | for (SkColorType dstColorType : colorTypes) { |
| 225 | for (SkAlphaType dstAlphaType : alphaTypes) { |
| 226 | for (SkImage::CachingHint hint : hints) { |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 227 | draw_image(nullptr, canvas, image.get(), dstColorType, dstAlphaType, |
| 228 | dstColorSpace, hint); |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 229 | canvas->translate(0.0f, (float) kEncodedHeight + 1); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | canvas->restore(); |
| 234 | canvas->translate((float) kEncodedWidth + 1, 0.0f); |
| 235 | } |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 236 | return DrawResult::kOk; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | private: |
| 240 | static const int kEncodedWidth = 8; |
| 241 | static const int kEncodedHeight = 8; |
| 242 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 243 | using INHERITED = skiagm::GM; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 244 | }; |
| 245 | DEF_GM( return new ReadPixelsCodecGM; ) |
| 246 | |
| 247 | class ReadPixelsPictureGM : public skiagm::GM { |
| 248 | public: |
| 249 | ReadPixelsPictureGM() {} |
| 250 | |
| 251 | protected: |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 252 | SkString getName() const override { return SkString("readpixelspicture"); } |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 253 | |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 254 | SkISize getISize() override { return SkISize::Make(3 * kWidth, 12 * kHeight); } |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 255 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 256 | DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 257 | if (!canvas->imageInfo().colorSpace()) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 258 | *errorMsg = "This gm is only interesting in color correct modes."; |
| 259 | return DrawResult::kSkip; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | const sk_sp<SkImage> images[] = { |
Matt Sarett | 9df70bb | 2017-02-14 13:50:43 -0500 | [diff] [blame] | 263 | make_picture_image(), |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 264 | }; |
| 265 | const SkAlphaType alphaTypes[] = { |
| 266 | kUnpremul_SkAlphaType, |
| 267 | kPremul_SkAlphaType, |
| 268 | }; |
| 269 | const SkColorType colorTypes[] = { |
| 270 | kRGBA_8888_SkColorType, |
| 271 | kBGRA_8888_SkColorType, |
| 272 | kRGBA_F16_SkColorType, |
| 273 | }; |
| 274 | const sk_sp<SkColorSpace> colorSpaces[] = { |
| 275 | make_wide_gamut(), |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 276 | SkColorSpace::MakeSRGB(), |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 277 | make_small_gamut(), |
| 278 | }; |
| 279 | const SkImage::CachingHint hints[] = { |
| 280 | SkImage::kAllow_CachingHint, |
| 281 | SkImage::kDisallow_CachingHint, |
| 282 | }; |
| 283 | |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 284 | for (const sk_sp<SkImage>& image : images) { |
| 285 | for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) { |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 286 | canvas->save(); |
| 287 | for (SkColorType dstColorType : colorTypes) { |
| 288 | for (SkAlphaType dstAlphaType : alphaTypes) { |
| 289 | for (SkImage::CachingHint hint : hints) { |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 290 | draw_image(nullptr, canvas, image.get(), dstColorType, dstAlphaType, |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 291 | dstColorSpace, hint); |
| 292 | canvas->translate(0.0f, (float) kHeight); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | canvas->restore(); |
| 297 | canvas->translate((float) kWidth, 0.0f); |
| 298 | } |
| 299 | } |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 300 | return DrawResult::kOk; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | private: |
| 304 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 305 | using INHERITED = skiagm::GM; |
Matt Sarett | 34855f9 | 2017-01-10 17:41:53 -0500 | [diff] [blame] | 306 | }; |
| 307 | DEF_GM( return new ReadPixelsPictureGM; ) |