Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 68 of file debugger_bindings.cpp.

Constructor & Destructor Documentation

◆ SkpDebugPlayer()

SkpDebugPlayer::SkpDebugPlayer ( )
inline

Definition at line 70 of file debugger_bindings.cpp.

70 :
71 udm(UrlDataManager(SkString("/data"))){}

Member Function Documentation

◆ changeFrame()

void SkpDebugPlayer::changeFrame ( int  index)
inline

Definition at line 259 of file debugger_bindings.cpp.

259 {
260 fp = index;
261 }

◆ deleteCommand()

void SkpDebugPlayer::deleteCommand ( int  index)
inline

Definition at line 204 of file debugger_bindings.cpp.

204 {
206 }
void deleteDrawCommandAt(int index)
DebugCanvas * visibleCanvas()

◆ draw()

void SkpDebugPlayer::draw ( SkSurface surface)
inline

Definition at line 135 of file debugger_bindings.cpp.

135 {
136 auto* canvas = surface->getCanvas();
137 canvas->clear(SK_ColorTRANSPARENT);
138 frames[fp]->draw(surface->getCanvas());
139#ifdef CK_ENABLE_WEBGL
141#endif
142 }
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 112 of file debugger_bindings.cpp.

112 {
113 // Set the command within the frame or layer event being drawn.
114 if (fInspectedLayer >= 0) {
115 fLayerManager->setCommand(fInspectedLayer, fp, index);
116 } else {
117 index = constrainFrameCommand(index);
118 }
119
120 auto* canvas = surface->getCanvas();
121 canvas->clear(SK_ColorTRANSPARENT);
122 if (fInspectedLayer >= 0) {
123 // when it's a layer event we're viewing, we use the layer manager to render it.
124 fLayerManager->drawLayerEventTo(surface, fInspectedLayer, fp);
125 } else {
126 // otherwise, its a frame at the top level.
127 frames[fp]->drawTo(surface->getCanvas(), index);
128 }
129#ifdef CK_ENABLE_WEBGL
131#endif
132 }

◆ findCommandByPixel()

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

Definition at line 340 of file debugger_bindings.cpp.

340 {
341 // What color is the pixel now?
342 SkColor finalColor = evaluateCommandColor(surface, commandIndex, x, y);
343
344 int lowerBound = 0;
345 int upperBound = commandIndex;
346
347 while (upperBound - lowerBound > 1) {
348 int command = (upperBound - lowerBound) / 2 + lowerBound;
349 auto c = evaluateCommandColor(surface, command, x, y);
350 if (c == finalColor) {
351 upperBound = command;
352 } else {
353 lowerBound = command;
354 }
355 }
356 // clean up after side effects
357 drawTo(surface, commandIndex);
358 return upperBound;
359 }
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 155 of file debugger_bindings.cpp.

155 {
156 return getBoundsForFrame(fp);
157 }
const SkIRect getBoundsForFrame(int32_t frame)

◆ getBoundsForFrame()

const SkIRect SkpDebugPlayer::getBoundsForFrame ( int32_t  frame)
inline

Definition at line 146 of file debugger_bindings.cpp.

146 {
147 if (fInspectedLayer < 0) {
148 return fBoundsArray[frame];
149 }
150 auto summary = fLayerManager->event(fInspectedLayer, fp);
151 return SkIRect::MakeWH(summary.layerWidth, summary.layerHeight);
152 }
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 217 of file debugger_bindings.cpp.

217 {
218 return frames.size();
219 }

◆ getImageCount()

int SkpDebugPlayer::getImageCount ( )
inline

Definition at line 277 of file debugger_bindings.cpp.

277 {
278 return fImages.size();
279 }

◆ getImageInfo()

ImageInfoNoColorspace SkpDebugPlayer::getImageInfo ( int  index)
inline

Definition at line 282 of file debugger_bindings.cpp.

282 {
283 return toImageInfoNoColorspace(fImages[index]->imageInfo());
284 }
ImageInfoNoColorspace toImageInfoNoColorspace(const SkImageInfo &ii)

◆ getImageResource()

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

Definition at line 267 of file debugger_bindings.cpp.

267 {
268 sk_sp<SkData> pngData = SkPngEncoder::Encode(nullptr, fImages[index].get(), {});
269 size_t len = SkBase64::EncodedSize(pngData->size());
271 dst.resize(len);
272 SkBase64::Encode(pngData->data(), pngData->size(), dst.data());
273 dst.prepend("data:image/png;base64,");
274 return std::string(dst.c_str());
275 }
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 317 of file debugger_bindings.cpp.

317 {
318 JSArray result = emscripten::val::array();
319 for (auto key : fLayerManager->getKeys()) {
320 JSObject item = emscripten::val::object();
321 item.set("frame", key.frame);
322 item.set("nodeId", key.nodeId);
323 result.call<void>("push", item);
324 }
325 return result;
326 }
emscripten::val JSObject
Definition WasmCommon.h:28
emscripten::val JSArray
Definition WasmCommon.h:27
GAsyncResult * result

◆ getLayerSummariesJs()

JSArray SkpDebugPlayer::getLayerSummariesJs ( )
inline

Definition at line 309 of file debugger_bindings.cpp.

309 {
310 JSArray result = emscripten::val::array();
311 for (auto summary : fLayerManager->summarizeLayers(fp)) {
312 result.call<void>("push", summary);
313 }
314 return result;
315 }

◆ getSize()

int SkpDebugPlayer::getSize ( ) const
inline

Definition at line 210 of file debugger_bindings.cpp.

210 {
211 if (fInspectedLayer >=0) {
212 return fLayerManager->event(fInspectedLayer, fp).commandCount;
213 } else {
214 return frames[fp]->getSize();
215 }
216 }

◆ imageUseInfo()

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

Definition at line 290 of file debugger_bindings.cpp.

290 {
291 JSObject result = emscripten::val::object();
292 DebugCanvas* debugCanvas = frames[framenumber].get();
293 if (nodeid >= 0) {
294 debugCanvas = fLayerManager->getEventDebugCanvas(nodeid, framenumber);
295 }
296 const auto& map = debugCanvas->getImageIdToCommandMap(udm);
297 for (auto it = map.begin(); it != map.end(); ++it) {
298 JSArray list = emscripten::val::array();
299 for (const int commandId : it->second) {
300 list.call<void>("push", commandId);
301 }
302 result.set(std::to_string(it->first), list);
303 }
304 return result;
305 }
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

◆ jsonCommandList()

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

Definition at line 222 of file debugger_bindings.cpp.

222 {
225 writer.beginObject(); // root
226 visibleCanvas()->toJSON(writer, udm, surface->getCanvas());
227 writer.endObject(); // root
228 writer.flush();
229 auto skdata = stream.detachAsData();
230 // Convert skdata to string_view, which accepts a length
231 std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
232 // and string_view to string, which emscripten understands.
233 return std::string(data_view);
234 }
void toJSON(SkJSONWriter &writer, UrlDataManager &urlDataManager, SkCanvas *)

◆ lastCommandInfo()

std::string SkpDebugPlayer::lastCommandInfo ( )
inline

Definition at line 237 of file debugger_bindings.cpp.

237 {
240
243 writer.beginObject(); // root
244
245 writer.appendName("ViewMatrix");
247 writer.appendName("ClipRect");
249
250 writer.endObject(); // root
251 writer.flush();
252 auto skdata = stream.detachAsData();
253 // Convert skdata to string_view, which accepts a length
254 std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
255 // and string_view to string, which emscripten understands.
256 return std::string(data_view);
257 }
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
const SkIRect & getCurrentClip()
const SkM44 & getCurrentMatrix()
static void MakeJsonMatrix44(SkJSONWriter &, const SkM44 &)
static void MakeJsonIRect(SkJSONWriter &, const SkIRect &)
Definition SkM44.h:150

◆ loadSkp()

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

Definition at line 85 of file debugger_bindings.cpp.

85 {
86 const uint8_t* data = reinterpret_cast<const uint8_t*>(cptr);
87 // Both traditional and multi-frame skp files have a magic word
89 SkDebugf("make stream at %p, with %d bytes\n",data, length);
90 const bool isMulti = memcmp(data, kMultiMagic, sizeof(kMultiMagic) - 1) == 0;
91
92
93 if (isMulti) {
94 SkDebugf("Try reading as a multi-frame skp\n");
95 const auto& error = loadMultiFrame(&stream);
96 if (!error.empty()) { return error; }
97 } else {
98 SkDebugf("Try reading as single-frame skp\n");
99 // TODO(nifong): Rely on SkPicture's return errors once it provides some.
100 std::unique_ptr<DebugCanvas> canvas = loadSingleFrame(&stream);
101 if (!canvas) {
102 return "Error loading single frame";
103 }
104 frames.push_back(std::move(canvas));
105 }
106 return "";
107 }
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ setAndroidClipViz()

void SkpDebugPlayer::setAndroidClipViz ( bool  on)
inline

Definition at line 191 of file debugger_bindings.cpp.

191 {
192 for (size_t i=0; i < frames.size(); i++) {
193 frames[i]->setAndroidClipViz(on);
194 }
195 // doesn't matter in layers
196 }

◆ setClipVizColor()

void SkpDebugPlayer::setClipVizColor ( JSColor  color)
inline

Definition at line 185 of file debugger_bindings.cpp.

185 {
186 for (size_t i=0; i < frames.size(); i++) {
187 frames[i]->setClipVizColor(SkColor(color));
188 }
189 fLayerManager->setClipVizColor(SkColor(color));
190 }
SkColor4f color

◆ setCommandVisibility()

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

Definition at line 207 of file debugger_bindings.cpp.

207 {
208 visibleCanvas()->toggleCommand(index, visible);
209 }
void toggleCommand(int index, bool toggle)

◆ setGpuOpBounds()

void SkpDebugPlayer::setGpuOpBounds ( bool  on)
inline

Definition at line 179 of file debugger_bindings.cpp.

179 {
180 for (size_t i=0; i < frames.size(); i++) {
181 frames[i]->setDrawGpuOpBounds(on);
182 }
183 fLayerManager->setDrawGpuOpBounds(on);
184 }

◆ setInspectedLayer()

void SkpDebugPlayer::setInspectedLayer ( int  nodeId)
inline

Definition at line 332 of file debugger_bindings.cpp.

332 {
333 fInspectedLayer = nodeId;
334 }

◆ setOriginVisible()

void SkpDebugPlayer::setOriginVisible ( bool  on)
inline

Definition at line 197 of file debugger_bindings.cpp.

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

◆ setOverdrawVis()

void SkpDebugPlayer::setOverdrawVis ( bool  on)
inline

Definition at line 173 of file debugger_bindings.cpp.

173 {
174 for (size_t i=0; i < frames.size(); i++) {
175 frames[i]->setOverdrawViz(on);
176 }
177 fLayerManager->setOverdrawViz(on);
178 }

◆ visibleCanvas()

DebugCanvas * SkpDebugPlayer::visibleCanvas ( )
inline

Definition at line 161 of file debugger_bindings.cpp.

161 {
162 if (fInspectedLayer >=0) {
163 return fLayerManager->getEventDebugCanvas(fInspectedLayer, fp);
164 } else {
165 return frames[fp].get();
166 }
167 }

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