2019-03-15 18:22:51 +00:00
|
|
|
// Copyright 2019 Google LLC.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/fiddle/examples.h"
|
2019-03-15 18:22:51 +00:00
|
|
|
// HASH=640321e8ecfb3f9329f3bc6e1f02485f
|
2019-03-18 20:06:34 +00:00
|
|
|
REG_FIDDLE(Surface_MakeRenderTarget_2, 256, 256, false, 0) {
|
2019-03-15 18:22:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
auto test_draw = [](SkCanvas* surfaceCanvas) -> void {
|
2020-07-10 20:20:53 +00:00
|
|
|
SkFont font(nullptr, 32);
|
|
|
|
|
2019-03-15 18:22:51 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2020-07-10 20:20:53 +00:00
|
|
|
// TODO: where did this setting go?
|
|
|
|
//paint.setLCDRenderText(true);
|
2019-03-15 18:22:51 +00:00
|
|
|
paint.setColor(0xFFBBBBBB);
|
2020-07-10 20:20:53 +00:00
|
|
|
|
2019-03-15 18:22:51 +00:00
|
|
|
surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
2020-07-10 20:20:53 +00:00
|
|
|
surfaceCanvas->drawString("Text", 0, 25, font, paint);
|
2019-03-15 18:22:51 +00:00
|
|
|
};
|
2020-07-10 20:20:53 +00:00
|
|
|
auto context = canvas->recordingContext();
|
2019-03-15 18:22:51 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType);
|
|
|
|
int y = 0;
|
|
|
|
for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry,
|
|
|
|
kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) {
|
|
|
|
SkSurfaceProps props(0, geometry);
|
2020-07-10 20:20:53 +00:00
|
|
|
sk_sp<SkSurface> surface = context
|
|
|
|
? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props)
|
|
|
|
: SkSurface::MakeRaster(info, &props);
|
2019-03-15 18:22:51 +00:00
|
|
|
test_draw(surface->getCanvas());
|
2021-01-06 13:43:51 +00:00
|
|
|
surface->draw(canvas, 0, y);
|
2019-03-15 18:22:51 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->scale(8, 8);
|
|
|
|
canvas->drawImage(image, 12, y / 8);
|
|
|
|
y += 64;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // END FIDDLE
|