1// Copyright 2019 Google LLC. 2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3#include "tools/fiddle/examples.h" 4// HASH=2b1e46354d823dbb53fa6af570135329 5REG_FIDDLE(Image_MakeFromTexture_2, 256, 256, false, 4) { 6void draw(SkCanvas* canvas) { 7 auto dContext = GrAsDirectContext(canvas->recordingContext()); 8 if (!dContext) { 9 return; 10 } 11 12 auto releaseCallback = [](SkImage::ReleaseContext releaseContext) -> void { 13 *((int *) releaseContext) += 128; 14 }; 15 int x = 0, y = 0; 16 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { 17 sk_sp<SkImage> image = SkImage::MakeFromTexture(dContext, backEndTexture, 18 origin, kRGBA_8888_SkColorType, 19 kOpaque_SkAlphaType, nullptr, 20 releaseCallback, &x); 21 canvas->drawImage(image, x, y); 22 y += 128; 23 } 24} 25} // END FIDDLE 26