Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Request Struct Reference

#include <Request.h>

Public Member Functions

 Request (SkString rootUrl)
 
 ~Request ()
 
sk_sp< SkDatadrawToPng (int n, int m=-1)
 
sk_sp< SkDatawriteOutSkp ()
 
SkCanvasgetCanvas ()
 
bool enableGPU (bool enable)
 
bool setOverdraw (bool enable)
 
bool setColorMode (int mode)
 
bool hasPicture () const
 
int getLastOp () const
 
bool initPictureFromStream (SkStream *)
 
sk_sp< SkDatagetJsonOps ()
 
sk_sp< SkDatagetJsonOpsTask ()
 
sk_sp< SkDatagetJsonInfo (int n)
 
SkColor getPixel (int x, int y)
 

Public Attributes

UploadContextfUploadContext
 
std::unique_ptr< DebugCanvasfDebugCanvas
 
UrlDataManager fUrlDataManager
 

Detailed Description

Definition at line 34 of file Request.h.

Constructor & Destructor Documentation

◆ Request()

Request::Request ( SkString  rootUrl)

Definition at line 29 of file Request.cpp.

30 : fUploadContext(nullptr)
31 , fUrlDataManager(rootUrl)
32 , fGPUEnabled(false)
33 , fOverdraw(false)
34 , fColorMode(0) {
35 // create surface
37 fContextFactory = new GrContextFactory(grContextOpts);
38}
GrContextOptions grContextOpts
UploadContext * fUploadContext
Definition Request.h:62
UrlDataManager fUrlDataManager
Definition Request.h:64

◆ ~Request()

Request::~Request ( )

Definition at line 40 of file Request.cpp.

40 {
41 if (fContextFactory) {
42 delete fContextFactory;
43 }
44}

Member Function Documentation

◆ drawToPng()

sk_sp< SkData > Request::drawToPng ( int  n,
int  m = -1 
)

Definition at line 81 of file Request.cpp.

81 {
82 //fDebugCanvas->setOverdrawViz(true);
83 auto* canvas = this->getCanvas();
84 canvas->clear(SK_ColorTRANSPARENT);
85 fDebugCanvas->drawTo(canvas, n, m);
86 //fDebugCanvas->setOverdrawViz(false);
87 return writeCanvasToPng(this->getCanvas());
88}
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
SkCanvas * getCanvas()
Definition Request.cpp:58
std::unique_ptr< DebugCanvas > fDebugCanvas
Definition Request.h:63

◆ enableGPU()

bool Request::enableGPU ( bool  enable)

Definition at line 181 of file Request.cpp.

181 {
182 if (enable) {
183 SkSurface* surface = this->createGPUSurface();
184 if (surface) {
185 fSurface.reset(surface);
186 fGPUEnabled = true;
187
188 // When we switch to GPU, there seems to be some mystery draws in the canvas. So we
189 // draw once to flush the pipe
190 // TODO understand what is actually happening here
191 if (fDebugCanvas) {
192 fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp());
193 this->directContext()->flush(fSurface.get());
194 }
195
196 return true;
197 }
198 return false;
199 }
200 fSurface.reset(this->createCPUSurface());
201 fGPUEnabled = false;
202 return true;
203}
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
T * get() const
Definition SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
VkSurfaceKHR surface
Definition main.cc:49
int getLastOp() const
Definition Request.h:46

◆ getCanvas()

SkCanvas * Request::getCanvas ( )

Definition at line 58 of file Request.cpp.

58 {
59#ifdef SK_GL
60 GrContextFactory* factory = fContextFactory;
61 GLTestContext* gl = factory->getContextInfo(skgpu::ContextType::kGL,
62 GrContextFactory::ContextOverrides::kNone).glContext();
63 if (!gl) {
64 gl = factory->getContextInfo(skgpu::ContextType::kGLES,
65 GrContextFactory::ContextOverrides::kNone).glContext();
66 }
67 if (gl) {
68 gl->makeCurrent();
69 }
70#endif
72
73 // create the appropriate surface if necessary
74 if (!fSurface) {
75 this->enableGPU(fGPUEnabled);
76 }
77 SkCanvas* target = fSurface->getCanvas();
78 return target;
79}
#define SkASSERT(cond)
Definition SkAssert.h:116
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
uint32_t * target
bool enableGPU(bool enable)
Definition Request.cpp:181

◆ getJsonInfo()

sk_sp< SkData > Request::getJsonInfo ( int  n)

Definition at line 255 of file Request.cpp.

255 {
256 // drawTo
257 sk_sp<SkSurface> surface(this->createCPUSurface());
258 SkCanvas* canvas = surface->getCanvas();
259
260 // TODO this is really slow and we should cache the matrix and clip
261 fDebugCanvas->drawTo(canvas, n);
262
263 // make some json
266
267 SkM44 vm = fDebugCanvas->getCurrentMatrix();
268 SkIRect clip = fDebugCanvas->getCurrentClip();
269
270 writer.beginObject(); // root
271 writer.appendName("ViewMatrix");
273 writer.appendName("ClipRect");
275 writer.endObject(); // root
276
277 // TODO: Old code explicitly avoided the null terminator in the returned data. Important?
278 writer.flush();
279 return stream.detachAsData();
280}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
static void MakeJsonMatrix44(SkJSONWriter &, const SkM44 &)
static void MakeJsonIRect(SkJSONWriter &, const SkIRect &)
Definition SkM44.h:150

◆ getJsonOps()

sk_sp< SkData > Request::getJsonOps ( )

Definition at line 227 of file Request.cpp.

227 {
228 SkCanvas* canvas = this->getCanvas();
231 writer.beginObject(); // root
232
233 writer.appendCString("mode", fGPUEnabled ? "gpu" : "cpu");
234 writer.appendBool("drawGpuOpBounds", fDebugCanvas->getDrawGpuOpBounds());
235 writer.appendS32("colorMode", fColorMode);
236 fDebugCanvas->toJSON(writer, fUrlDataManager, canvas);
237
238 writer.endObject(); // root
239 writer.flush();
240 return stream.detachAsData();
241}

◆ getJsonOpsTask()

sk_sp< SkData > Request::getJsonOpsTask ( )

Definition at line 243 of file Request.cpp.

243 {
244 SkCanvas* canvas = this->getCanvas();
245 SkASSERT(fGPUEnabled);
248
249 fDebugCanvas->toJSONOpsTask(writer, canvas);
250
251 writer.flush();
252 return stream.detachAsData();
253}

◆ getLastOp()

int Request::getLastOp ( ) const
inline

Definition at line 46 of file Request.h.

46{ return fDebugCanvas->getSize() - 1; }

◆ getPixel()

SkColor Request::getPixel ( int  x,
int  y 
)

Definition at line 282 of file Request.cpp.

282 {
283 SkBitmap bmp;
284 bmp.allocPixels(this->getCanvas()->imageInfo().makeWH(1, 1));
285 SkAssertResult(this->getCanvas()->readPixels(bmp, x, y));
286 return bmp.getColor(0, 0);
287}
#define SkAssertResult(cond)
Definition SkAssert.h:123
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
double y
double x

◆ hasPicture()

bool Request::hasPicture ( ) const
inline

Definition at line 45 of file Request.h.

45{ return SkToBool(fPicture.get()); }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ initPictureFromStream()

bool Request::initPictureFromStream ( SkStream stream)

Definition at line 205 of file Request.cpp.

205 {
206 // parse picture from stream
207 fPicture = SkPicture::MakeFromStream(stream);
208 if (!fPicture) {
209 fprintf(stderr, "Could not create picture from stream.\n");
210 return false;
211 }
212
213 // reinitialize canvas with the new picture dimensions
214 this->enableGPU(fGPUEnabled);
215
216 // pour picture into debug canvas
217 SkIRect bounds = this->getBounds();
218 fDebugCanvas = std::make_unique<DebugCanvas>(bounds.width(), bounds.height());
219 fDebugCanvas->drawPicture(fPicture);
220
221 // for some reason we need to 'flush' the debug canvas by drawing all of the ops
222 fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp());
223 this->directContext()->flush(fSurface.get());
224 return true;
225}
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ setColorMode()

bool Request::setColorMode ( int  mode)

Definition at line 176 of file Request.cpp.

176 {
177 fColorMode = mode;
178 return enableGPU(fGPUEnabled);
179}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228

◆ setOverdraw()

bool Request::setOverdraw ( bool  enable)

Definition at line 171 of file Request.cpp.

171 {
172 fOverdraw = enable;
173 return true;
174}

◆ writeOutSkp()

sk_sp< SkData > Request::writeOutSkp ( )

Definition at line 90 of file Request.cpp.

90 {
91 // Playback into picture recorder
92 SkIRect bounds = this->getBounds();
93 SkPictureRecorder recorder;
94 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bounds.width()),
95 SkIntToScalar(bounds.height()));
96
97 fDebugCanvas->draw(canvas);
98
99 return recorder.finishRecordingAsPicture()->serialize();
100}
#define SkIntToScalar(x)
Definition SkScalar.h:57
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const

Member Data Documentation

◆ fDebugCanvas

std::unique_ptr<DebugCanvas> Request::fDebugCanvas

Definition at line 63 of file Request.h.

◆ fUploadContext

UploadContext* Request::fUploadContext

Definition at line 62 of file Request.h.

◆ fUrlDataManager

UrlDataManager Request::fUrlDataManager

Definition at line 64 of file Request.h.


The documentation for this struct was generated from the following files: