1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ci// HASH=f031c2a53f6a57833dc0127e674553da 5cb93a386Sopenharmony_ciREG_FIDDLE(Image_isLazyGenerated_b, 256, 256, false, 5) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci auto dContext = GrAsDirectContext(canvas->recordingContext()); 8cb93a386Sopenharmony_ci if (!dContext) { 9cb93a386Sopenharmony_ci return; 10cb93a386Sopenharmony_ci } 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ci auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { 13cb93a386Sopenharmony_ci if (nullptr == image) { 14cb93a386Sopenharmony_ci return; 15cb93a386Sopenharmony_ci } 16cb93a386Sopenharmony_ci SkPaint paint; 17cb93a386Sopenharmony_ci paint.setAntiAlias(true); 18cb93a386Sopenharmony_ci SkFont font; 19cb93a386Sopenharmony_ci canvas->drawImage(image, 0, 0); 20cb93a386Sopenharmony_ci canvas->drawString(label, 30, image->height() / 4, font, paint); 21cb93a386Sopenharmony_ci canvas->drawString( 22cb93a386Sopenharmony_ci image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", 23cb93a386Sopenharmony_ci 20, image->height() * 3 / 4, font, paint); 24cb93a386Sopenharmony_ci }; 25cb93a386Sopenharmony_ci sk_sp<SkImage> bitmapImage(source.asImage()); 26cb93a386Sopenharmony_ci sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture, 27cb93a386Sopenharmony_ci kTopLeft_GrSurfaceOrigin, 28cb93a386Sopenharmony_ci kRGBA_8888_SkColorType, 29cb93a386Sopenharmony_ci kOpaque_SkAlphaType, nullptr)); 30cb93a386Sopenharmony_ci drawImage(image, "image"); 31cb93a386Sopenharmony_ci canvas->translate(image->width(), 0); 32cb93a386Sopenharmony_ci drawImage(bitmapImage, "source"); 33cb93a386Sopenharmony_ci canvas->translate(-image->width(), image->height()); 34cb93a386Sopenharmony_ci drawImage(textureImage, "backEndTexture"); 35cb93a386Sopenharmony_ci} 36cb93a386Sopenharmony_ci} // END FIDDLE 37