← 블로그 목록

[Core2026] ETC - Viewport

Core2026 › Engine › CPU Engine › ETC

@Nor-s
  • #ThorVG
  • #Core
  • #CPU
  • #Viewport
목차

Overview

Canvas::viewport(x, y, w, h)

One avatar Scene follows Canvas::viewport, RenderRegion, per-task clipBox, image bounds and Shape RLE, draw(false)/draw(true), and accumulated drawing. Each section loops locally; the final result stays fixed.
0:00
코드 보기: 뷰포트 예제와 소스

지정한 뷰포트로 사진과 배지의 렌더 영역을 제한합니다.

// Canvas target: 16 × 12 ABGR8888 pixels, initialized to 0xfff0eae5.
// photoPixels: decoded opaque 16 × 12 ABGR8888 pixels.
auto avatar = Scene::gen();
auto photo = Picture::gen();
photo->load(photoPixels, 16, 12, ColorSpace::ABGR8888, true);
auto badge = Shape::gen();
badge->appendCircle(12, 8.5, 2, 2);
badge->fill(35, 160, 100);
avatar->add(photo);
avatar->add(badge);
canvas->add(avatar);
canvas->viewport(4, 2, 8, 7);
canvas->update();
canvas->draw(false);
canvas->sync();
  • [4,12) × [2,9)inprepareCommon()| | PhotoSwImageTask|curBox, SwImage image| Direct image rendering uses bounded coordinates;image.rle = nullptr| | BadgeSwShapeTask|SwShape shape|shape.rlecontains only spans withinclipBox` |

Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h) stores the region and marks the Canvas damaged when it changes. SceneImpl::update() traverses the photo and badge; prepareCommon() captures the renderer viewport for each task. The Picture keeps its original pixel coordinates, and the Shape keeps its original coverage at included coordinates.

The blue boundary represents the viewport. RLE glyphs use a shaded starting pixel for coverage and a line to the last included pixel center for length; len = 1 has no line.

The clear-policy comparison uses two independent first draws on the same initialized target. draw(false) retains pixels outside the viewport. draw(true) clears the entire target before drawing inside the viewport. Later partial updates have their own dirty-region clearing behavior.

Native CPU execution at 4d5810cf verifies both task clipBoxes, direct-image bounds, the null image RLE, badge spans, intermediate photo output, final output, and zero compositor buffers. A second fixture moves the viewport’s x origin from 4 to 5 while preserving the input pixels and geometry. The last section shows successive states of one Main Surface; the result remains fixed.

Mask · Clipping