Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | #if 0 // Disabled until updated to use current API. |
| 2 | // Copyright 2019 Google LLC. |
| 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 4 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 5 | // HASH=afc62f38aebc56af8e425297ec67dd37 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 6 | REG_FIDDLE(Image_isValid, 256, 256, false, 5) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 7 | void draw(SkCanvas* canvas) { |
| 8 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 9 | if (nullptr == image) { |
| 10 | return; |
| 11 | } |
| 12 | SkPaint paint; |
| 13 | paint.setAntiAlias(true); |
| 14 | canvas->drawImage(image, 0, 0); |
| 15 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 16 | if (canvas->getGrContext()) { |
| 17 | canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : |
| 18 | "not valid on GPU", 20, image->height() * 5 / 8, paint); |
| 19 | } |
| 20 | canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : |
| 21 | "not valid on CPU", 20, image->height() * 7 / 8, paint); |
| 22 | }; |
| 23 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 24 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 25 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 26 | kOpaque_SkAlphaType, nullptr)); |
| 27 | drawImage(image, "image"); |
| 28 | canvas->translate(image->width(), 0); |
| 29 | drawImage(bitmapImage, "source"); |
| 30 | canvas->translate(-image->width(), image->height()); |
| 31 | drawImage(textureImage, "backEndTexture"); |
| 32 | } |
| 33 | } // END FIDDLE |
| 34 | #endif // Disabled until updated to use current API. |