| 35 | } |
| 36 | |
| 37 | Valdi::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); |
no test coverage detected