Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkpDebugPlayer Class Reference

Public Member Functions

 SkpDebugPlayer ()
 
std::string loadSkp (uintptr_t cptr, int length)
 
void drawTo (SkSurface *surface, int32_t index)
 
void draw (SkSurface *surface)
 
const SkIRect getBoundsForFrame (int32_t frame)
 
const SkIRect getBounds ()
 
DebugCanvasvisibleCanvas ()
 
void setOverdrawVis (bool on)
 
void setGpuOpBounds (bool on)
 
void setClipVizColor (JSColor color)
 
void setAndroidClipViz (bool on)
 
void setOriginVisible (bool on)
 
void deleteCommand (int index)
 
void setCommandVisibility (int index, bool visible)
 
int getSize () const
 
int getFrameCount () const
 
std::string jsonCommandList (sk_sp< SkSurface > surface)
 
std::string lastCommandInfo ()
 
void changeFrame (int index)
 
std::string getImageResource (int index)
 
int getImageCount ()
 
ImageInfoNoColorspace getImageInfo (int index)
 
JSObject imageUseInfo (int framenumber, int nodeid)
 
JSArray getLayerSummariesJs ()
 
JSArray getLayerKeys ()
 
void setInspectedLayer (int nodeId)
 
int findCommandByPixel (SkSurface *surface, int x, int y, int commandIndex)
 

Detailed Description

Definition at line 84 of file debugger_bindings.cpp.

Constructor & Destructor Documentation

◆ SkpDebugPlayer()

SkpDebugPlayer::SkpDebugPlayer ( )
inline

Definition at line 86 of file debugger_bindings.cpp.

86 :
87 udm(UrlDataManager(SkString("/data"))){}

Member Function Documentation

◆ changeFrame()

void SkpDebugPlayer::changeFrame ( int  index)
inline

Definition at line 275 of file debugger_bindings.cpp.

275 {
276 fp = index;
277 }

◆ deleteCommand()

void SkpDebugPlayer::deleteCommand ( int  index)
inline

Definition at line 220 of file debugger_bindings.cpp.

220 {
222 }
void deleteDrawCommandAt(int index)
DebugCanvas * visibleCanvas()

◆ draw()

void SkpDebugPlayer::draw ( SkSurface surface)
inline

Definition at line 151 of file debugger_bindings.cpp.

151 {
152 auto* canvas = surface->getCanvas();
153 canvas->clear(SK_ColorTRANSPARENT);
154 frames[fp]->draw(surface->getCanvas());
155#ifdef CK_ENABLE_WEBGL
157#endif
158 }
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
VkSurfaceKHR surface
Definition: main.cc:49
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)

◆ drawTo()

void SkpDebugPlayer::drawTo ( SkSurface surface,
int32_t  index 
)
inline

Definition at line 128 of file debugger_bindings.cpp.

128 {
129 // Set the command within the frame or layer event being drawn.
130 if (fInspectedLayer >= 0) {
131 fLayerManager->setCommand(fInspectedLayer, fp, index);
132 } else {
133 index = constrainFrameCommand(index);
134 }
135
136 auto* canvas = surface->getCanvas();
137 canvas->clear(SK_ColorTRANSPARENT);
138 if (fInspectedLayer >= 0) {
139 // when it's a layer event we're viewing, we use the layer manager to render it.
140 fLayerManager->drawLayerEventTo(surface, fInspectedLayer, fp);
141 } else {
142 // otherwise, its a frame at the top level.
143 frames[fp]->drawTo(surface->getCanvas(), index);
144 }
145#ifdef CK_ENABLE_WEBGL
147#endif
148 }

◆ findCommandByPixel()

int SkpDebugPlayer::findCommandByPixel ( SkSurface surface,
int  x,
int  y,
int  commandIndex 
)
inline

Definition at line 356 of file debugger_bindings.cpp.

356 {
357 // What color is the pixel now?
358 SkColor finalColor = evaluateCommandColor(surface, commandIndex, x, y);
359
360 int lowerBound = 0;
361 int upperBound = commandIndex;
362
363 while (upperBound - lowerBound > 1) {
364 int command = (upperBound - lowerBound) / 2 + lowerBound;
365 auto c = evaluateCommandColor(surface, command, x, y);
366 if (c == finalColor) {
367 upperBound = command;
368 } else {
369 lowerBound = command;
370 }
371 }
372 // clean up after side effects
373 drawTo(surface, commandIndex);
374 return upperBound;
375 }
uint32_t SkColor
Definition: SkColor.h:37
void drawTo(SkSurface *surface, int32_t index)
double y
double x
list command
Definition: valgrind.py:24

◆ getBounds()

const SkIRect SkpDebugPlayer::getBounds ( )
inline

Definition at line 171 of file debugger_bindings.cpp.

171 {
172 return getBoundsForFrame(fp);
173 }
const SkIRect getBoundsForFrame(int32_t frame)

◆ getBoundsForFrame()

const SkIRect SkpDebugPlayer::getBoundsForFrame ( int32_t  frame)
inline

Definition at line 162 of file debugger_bindings.cpp.

162 {
163 if (fInspectedLayer < 0) {
164 return fBoundsArray[frame];
165 }
166 auto summary = fLayerManager->event(fInspectedLayer, fp);
167 return SkIRect::MakeWH(summary.layerWidth, summary.layerHeight);
168 }
double frame
Definition: examples.cpp:31
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56

◆ getFrameCount()

int SkpDebugPlayer::getFrameCount ( ) const
inline

Definition at line 233 of file debugger_bindings.cpp.

233 {
234 return frames.size();
235 }

◆ getImageCount()

int SkpDebugPlayer::getImageCount ( )
inline

Definition at line 293 of file debugger_bindings.cpp.

293 {
294 return fImages.size();
295 }

◆ getImageInfo()

ImageInfoNoColorspace SkpDebugPlayer::getImageInfo ( int  index)
inline

Definition at line 298 of file debugger_bindings.cpp.

298 {
299 return toImageInfoNoColorspace(fImages[index]->imageInfo());
300 }
ImageInfoNoColorspace toImageInfoNoColorspace(const SkImageInfo &ii)

◆ getImageResource()

std::string SkpDebugPlayer::getImageResource ( int  index)
inline

Definition at line 283 of file debugger_bindings.cpp.

283 {
284 sk_sp<SkData> pngData = SkPngEncoder::Encode(nullptr, fImages[index].get(), {});
285 size_t len = SkBase64::EncodedSize(pngData->size());
287 dst.resize(len);
288 SkBase64::Encode(pngData->data(), pngData->size(), dst.data());
289 dst.prepend("data:image/png;base64,");
290 return std::string(dst.c_str());
291 }
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
dst
Definition: cp.py:12
const myers::Point & get(const myers::Segment &)
static size_t EncodedSize(size_t srcDataLength)
Definition: SkBase64.h:40
static size_t Encode(const void *src, size_t length, void *dst, const char *encode=nullptr)
Definition: SkBase64.cpp:113

◆ getLayerKeys()

JSArray SkpDebugPlayer::getLayerKeys ( )
inline

Definition at line 333 of file debugger_bindings.cpp.

333 {
334 JSArray result = emscripten::val::array();
335 for (auto key : fLayerManager->getKeys()) {
336 JSObject item = emscripten::val::object();
337 item.set("frame", key.frame);
338 item.set("nodeId", key.nodeId);
339 result.call<void>("push", item);
340 }
341 return result;
342 }
emscripten::val JSObject
Definition: WasmCommon.h:28
emscripten::val JSArray
Definition: WasmCommon.h:27
GAsyncResult * result

◆ getLayerSummariesJs()

JSArray SkpDebugPlayer::getLayerSummariesJs ( )
inline

Definition at line 325 of file debugger_bindings.cpp.

325 {
326 JSArray result = emscripten::val::array();
327 for (auto summary : fLayerManager->summarizeLayers(fp)) {
328 result.call<void>("push", summary);
329 }
330 return result;
331 }

◆ getSize()

int SkpDebugPlayer::getSize ( ) const
inline

Definition at line 226 of file debugger_bindings.cpp.

226 {
227 if (fInspectedLayer >=0) {
228 return fLayerManager->event(fInspectedLayer, fp).commandCount;
229 } else {
230 return frames[fp]->getSize();
231 }
232 }

◆ imageUseInfo()

JSObject SkpDebugPlayer::imageUseInfo ( int  framenumber,
int  nodeid 
)
inline

Definition at line 306 of file debugger_bindings.cpp.

306 {
307 JSObject result = emscripten::val::object();
308 DebugCanvas* debugCanvas = frames[framenumber].get();
309 if (nodeid >= 0) {
310 debugCanvas = fLayerManager->getEventDebugCanvas(nodeid, framenumber);
311 }
312 const auto& map = debugCanvas->getImageIdToCommandMap(udm);
313 for (auto it = map.begin(); it != map.end(); ++it) {
314 JSArray list = emscripten::val::array();
315 for (const int commandId : it->second) {
316 list.call<void>("push", commandId);
317 }
318 result.set(std::to_string(it->first), list);
319 }
320 return result;
321 }
std::map< int, std::vector< int > > getImageIdToCommandMap(UrlDataManager &udm) const
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ jsonCommandList()

std::string SkpDebugPlayer::jsonCommandList ( sk_sp< SkSurface surface)
inline

Definition at line 238 of file debugger_bindings.cpp.

238 {
241 writer.beginObject(); // root
242 visibleCanvas()->toJSON(writer, udm, surface->getCanvas());
243 writer.endObject(); // root
244 writer.flush();
245 auto skdata = stream.detachAsData();
246 // Convert skdata to string_view, which accepts a length
247 std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
248 // and string_view to string, which emscripten understands.
249 return std::string(data_view);
250 }
void toJSON(SkJSONWriter &writer, UrlDataManager &urlDataManager, SkCanvas *)

◆ lastCommandInfo()

std::string SkpDebugPlayer::lastCommandInfo ( )
inline

Definition at line 253 of file debugger_bindings.cpp.

253 {
256
259 writer.beginObject(); // root
260
261 writer.appendName("ViewMatrix");
263 writer.appendName("ClipRect");
265
266 writer.endObject(); // root
267 writer.flush();
268 auto skdata = stream.detachAsData();
269 // Convert skdata to string_view, which accepts a length
270 std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
271 // and string_view to string, which emscripten understands.
272 return std::string(data_view);
273 }
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
const SkIRect & getCurrentClip()
Definition: DebugCanvas.h:116
const SkM44 & getCurrentMatrix()
Definition: DebugCanvas.h:111
static void MakeJsonMatrix44(SkJSONWriter &, const SkM44 &)
static void MakeJsonIRect(SkJSONWriter &, const SkIRect &)
Definition: SkM44.h:150
Definition: SkRect.h:32

◆ loadSkp()

std::string SkpDebugPlayer::loadSkp ( uintptr_t  cptr,
int  length 
)
inline

Definition at line 101 of file debugger_bindings.cpp.

101 {
102 const uint8_t* data = reinterpret_cast<const uint8_t*>(cptr);
103 // Both traditional and multi-frame skp files have a magic word
105 SkDebugf("make stream at %p, with %d bytes\n",data, length);
106 const bool isMulti = memcmp(data, kMultiMagic, sizeof(kMultiMagic) - 1) == 0;
107
108
109 if (isMulti) {
110 SkDebugf("Try reading as a multi-frame skp\n");
111 const auto& error = loadMultiFrame(&stream);
112 if (!error.empty()) { return error; }
113 } else {
114 SkDebugf("Try reading as single-frame skp\n");
115 // TODO(nifong): Rely on SkPicture's return errors once it provides some.
116 std::unique_ptr<DebugCanvas> canvas = loadSingleFrame(&stream);
117 if (!canvas) {
118 return "Error loading single frame";
119 }
120 frames.push_back(std::move(canvas));
121 }
122 return "";
123 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static constexpr char kMultiMagic[]
const uint8_t uint32_t uint32_t GError ** error
size_t length
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ setAndroidClipViz()

void SkpDebugPlayer::setAndroidClipViz ( bool  on)
inline

Definition at line 207 of file debugger_bindings.cpp.

207 {
208 for (size_t i=0; i < frames.size(); i++) {
209 frames[i]->setAndroidClipViz(on);
210 }
211 // doesn't matter in layers
212 }

◆ setClipVizColor()

void SkpDebugPlayer::setClipVizColor ( JSColor  color)
inline

Definition at line 201 of file debugger_bindings.cpp.

201 {
202 for (size_t i=0; i < frames.size(); i++) {
203 frames[i]->setClipVizColor(SkColor(color));
204 }
205 fLayerManager->setClipVizColor(SkColor(color));
206 }
DlColor color

◆ setCommandVisibility()

void SkpDebugPlayer::setCommandVisibility ( int  index,
bool  visible 
)
inline

Definition at line 223 of file debugger_bindings.cpp.

223 {
224 visibleCanvas()->toggleCommand(index, visible);
225 }
void toggleCommand(int index, bool toggle)

◆ setGpuOpBounds()

void SkpDebugPlayer::setGpuOpBounds ( bool  on)
inline

Definition at line 195 of file debugger_bindings.cpp.

195 {
196 for (size_t i=0; i < frames.size(); i++) {
197 frames[i]->setDrawGpuOpBounds(on);
198 }
199 fLayerManager->setDrawGpuOpBounds(on);
200 }

◆ setInspectedLayer()

void SkpDebugPlayer::setInspectedLayer ( int  nodeId)
inline

Definition at line 348 of file debugger_bindings.cpp.

348 {
349 fInspectedLayer = nodeId;
350 }

◆ setOriginVisible()

void SkpDebugPlayer::setOriginVisible ( bool  on)
inline

Definition at line 213 of file debugger_bindings.cpp.

213 {
214 for (size_t i=0; i < frames.size(); i++) {
215 frames[i]->setOriginVisible(on);
216 }
217 }

◆ setOverdrawVis()

void SkpDebugPlayer::setOverdrawVis ( bool  on)
inline

Definition at line 189 of file debugger_bindings.cpp.

189 {
190 for (size_t i=0; i < frames.size(); i++) {
191 frames[i]->setOverdrawViz(on);
192 }
193 fLayerManager->setOverdrawViz(on);
194 }

◆ visibleCanvas()

DebugCanvas * SkpDebugPlayer::visibleCanvas ( )
inline

Definition at line 177 of file debugger_bindings.cpp.

177 {
178 if (fInspectedLayer >=0) {
179 return fLayerManager->getEventDebugCanvas(fInspectedLayer, fp);
180 } else {
181 return frames[fp].get();
182 }
183 }

The documentation for this class was generated from the following file: