| 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_refEncodedData, 256, 256, false, 3) { |
| 5 |
void draw(SkCanvas* canvas) { |
| 6 |
auto dContext = GrAsDirectContext(canvas->recordingContext()); |
| 7 |
if (!dContext) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
struct { |
| 12 |
const char* name; |
| 13 |
sk_sp<SkImage> image; |
| 14 |
} tests[] = {{"image", image}, |
| 15 |
{"bitmap", source.asImage()}, |
| 16 |
{"texture", |
| 17 |
SkImages::BorrowTextureFrom(dContext, |
| 18 |
backEndTexture, |
| 19 |
kTopLeft_GrSurfaceOrigin, |
| 20 |
kRGBA_8888_SkColorType, |
| 21 |
kOpaque_SkAlphaType, |
| 22 |
nullptr)}}; |
| 23 |
SkString string; |
| 24 |
SkPaint paint; |
| 25 |
SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {})); |
| 26 |
|
| 27 |
for (const auto& test : tests ) { |
| 28 |
if (!test.image) { |
| 29 |
string.printf("no %s", test.name); |
| 30 |
} else { |
| 31 |
string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name); |
| 32 |
} |
| 33 |
canvas->drawString(string, 10, 20, font, paint); |
| 34 |
canvas->translate(0, 20); |
| 35 |
} |
| 36 |
} |
| 37 |
} // END FIDDLE |