Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ganesh_gl.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/gpu/ganesh/gl/GrGLDirectContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#include "include/encode/SkWebpEncoder.h"
#include <cstdio>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 101 of file ganesh_gl.cpp.

101 {
102 if (argc != 2) {
103 printf("Usage: %s <name.webp>\n", argv[0]);
104 return 1;
105 }
106
107 SkFILEWStream output(argv[1]);
108 if (!output.isValid()) {
109 printf("Cannot open output file %s\n", argv[1]);
110 return 1;
111 }
112
113 GrContextOptions opts;
114 opts.fSuppressPrints = true;
115#if defined(__linux__)
116 if (!initialize_gl_linux()) {
117 return 1;
118 }
120#elif defined(__APPLE__) && TARGET_OS_MAC == 1
121 if (!initialize_gl_mac()) {
122 return 1;
123 }
125#endif
126 if (!interface) {
127 printf("Could not make GL interface\n");
128 return 1;
129 }
130
132 if (!ctx) {
133 printf("Could not make GrDirectContext\n");
134 return 1;
135 }
136 printf("Context made, now to make the surface\n");
137
138 SkImageInfo imageInfo =
140
143 if (!surface) {
144 printf("Could not make surface from GL DirectContext\n");
145 return 1;
146 }
147
148 SkCanvas* canvas = surface->getCanvas();
149 canvas->clear(SK_ColorRED);
150 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(10, 20, 50, 70), 10, 10);
151
153 paint.setColor(SK_ColorBLUE);
154 paint.setAntiAlias(true);
155
156 canvas->drawRRect(rrect, paint);
157
158 ctx->flush();
159
160 printf("Drew to surface, now doing readback\n");
161 sk_sp<SkImage> img = surface->makeImageSnapshot();
162 sk_sp<SkData> webp = SkWebpEncoder::Encode(ctx.get(), img.get(), {});
163 if (!webp) {
164 printf("Readback of pixels (or encoding) failed\n");
165 return 1;
166 }
167 output.write(webp->data(), webp->size());
168 output.fsync();
169
170 return 0;
171}
@ 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_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
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
bool initialize_gl_mac()
SK_API sk_sp< GrDirectContext > MakeGL()
SK_API sk_sp< const GrGLInterface > MakeMac()
SK_API sk_sp< const GrGLInterface > MakeGLX()
SkRRect rrect
Definition SkRecords.h:232
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
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)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
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