Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ganesh_metal.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10#include "include/core/SkRect.h"
18
20
21int main(int argc, char *argv[]) {
22 if (argc != 2) {
23 printf("Usage: %s <name.jpeg>\n", argv[0]);
24 return 1;
25 }
26
27 SkFILEWStream output(argv[1]);
28 if (!output.isValid()) {
29 printf("Cannot open output file %s\n", argv[1]);
30 return 1;
31 }
32
33 GrMtlBackendContext backendContext = GetMetalContext();
35 if (!ctx) {
36 printf("Could not make metal context\n");
37 return 1;
38 }
39 printf("Context made, now to make the surface\n");
40
41 SkImageInfo imageInfo =
43
46 if (!surface) {
47 printf("Could not make surface from Metal DirectContext\n");
48 return 1;
49 }
50
51 SkCanvas* canvas = surface->getCanvas();
52 canvas->clear(SK_ColorCYAN);
53 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(10, 20, 50, 70), 10, 10);
54
56 paint.setColor(SK_ColorMAGENTA);
57 paint.setAntiAlias(true);
58
59 canvas->drawRRect(rrect, paint);
60
61 ctx->flush();
62
63 printf("Drew to surface, now doing readback\n");
64 sk_sp<SkImage> img = surface->makeImageSnapshot();
65 sk_sp<SkData> jpeg = SkJpegEncoder::Encode(ctx.get(), img.get(), {});
66 if (!jpeg) {
67 printf("Readback of pixels (or encoding) failed\n");
68 return 1;
69 }
70 output.write(jpeg->data(), jpeg->size());
71 output.fsync();
72 return 0;
73}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
char ** argv
Definition library.h:9
GrMtlBackendContext GetMetalContext()
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition main.py:1
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646