| 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 |
REG_FIDDLE(Image_BorrowTextureFrom_2, 256, 256, false, 4) { |
| 5 |
void draw(SkCanvas* canvas) { |
| 6 |
auto dContext = GrAsDirectContext(canvas->recordingContext()); |
| 7 |
if (!dContext) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
auto releaseCallback = [](SkImages::ReleaseContext releaseContext) -> void { |
| 12 |
*((int*)releaseContext) += 128; |
| 13 |
}; |
| 14 |
int x = 0, y = 0; |
| 15 |
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 16 |
sk_sp<SkImage> image = SkImages::BorrowTextureFrom(dContext, |
| 17 |
backEndTexture, |
| 18 |
origin, |
| 19 |
kRGBA_8888_SkColorType, |
| 20 |
kOpaque_SkAlphaType, |
| 21 |
nullptr, |
| 22 |
releaseCallback, |
| 23 |
&x); |
| 24 |
canvas->drawImage(image, x, y); |
| 25 |
y += 128; |
| 26 |
} |
| 27 |
} |
| 28 |
} // END FIDDLE |