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=9cf5c62a3d2243e6577ae563f360ea9d 5cb93a386Sopenharmony_ciREG_FIDDLE(Image_isTextureBacked, 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(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", 22cb93a386Sopenharmony_ci 20, image->height() * 3 / 4, font, paint); 23cb93a386Sopenharmony_ci }; 24cb93a386Sopenharmony_ci sk_sp<SkImage> bitmapImage(source.asImage()); 25cb93a386Sopenharmony_ci sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture, 26cb93a386Sopenharmony_ci kTopLeft_GrSurfaceOrigin, 27cb93a386Sopenharmony_ci kRGBA_8888_SkColorType, 28cb93a386Sopenharmony_ci kOpaque_SkAlphaType, nullptr)); 29cb93a386Sopenharmony_ci drawImage(image, "image"); 30cb93a386Sopenharmony_ci canvas->translate(image->width(), 0); 31cb93a386Sopenharmony_ci drawImage(bitmapImage, "source"); 32cb93a386Sopenharmony_ci canvas->translate(-image->width(), image->height()); 33cb93a386Sopenharmony_ci drawImage(textureImage, "backEndTexture"); 34cb93a386Sopenharmony_ci} 35cb93a386Sopenharmony_ci} // END FIDDLE 36