MCPcopy Create free account
hub / github.com/Snapchat/Valdi / drawNext

Method drawNext

snap_drawing/src/snap_drawing/cpp/Drawing/DrawOperation.cpp:37–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37Valdi::Result<snap::drawing::GraphicsContext*> DrawOperation::drawNext() {
38 const auto& surfacePresenter = *_current;
39 _current++;
40
41 advance();
42
43 auto drawableSurface = Ref<DrawableSurface>(surfacePresenter.getDrawableSurface());
44
45 if (drawableSurface == nullptr) {
46 return nullptr;
47 }
48
49 // A set-but-empty viewport means nothing is on screen (fully scrolled off); the drawable is
50 // zero-sized, so skip before preparing a canvas that would just fail every frame.
51 if (_displayList->getViewport().isEmpty()) {
52 return nullptr;
53 }
54
55 VALDI_TRACE("SnapDrawing.drawSurface");
56
57 auto canvasResult = drawableSurface->prepareCanvas();
58
59 if (!canvasResult) {
60 return canvasResult.error().rethrow("Failed to prepare canvas on GraphicsContext");
61 }
62
63 // Scale against the viewport (the content sub-rect this drawable covers), not the full content
64 // size, so a drawable sized to just the visible region renders at native resolution and the
65 // translation applied in DisplayList::draw lines the region up. Equals the full-content scale
66 // when no viewport is set.
67 auto viewport = _displayList->getViewport();
68 auto scaleX = static_cast<Scalar>(canvasResult.value().getWidth()) / viewport.width();
69 auto scaleY = static_cast<Scalar>(canvasResult.value().getHeight()) / viewport.height();
70
71 _displayList->draw(canvasResult.value(),
72 surfacePresenter.getDisplayListPlaneIndex(),
73 scaleX,
74 scaleY,
75 /* shouldClearCanvas */ true);

Callers 1

drawOperationsBatchMethod · 0.80

Calls 15

rethrowMethod · 0.80
errorMethod · 0.65
valueMethod · 0.65
drawMethod · 0.65
flushMethod · 0.65
advanceFunction · 0.50
getDrawableSurfaceMethod · 0.45
prepareCanvasMethod · 0.45
getSizeMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected