Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
window_surface.h
Go to the documentation of this file.
1// Copyright 2026 The Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3
4#ifndef SYMBIAN_API_DISPLAY_WINDOW_SURFACE_H_
5#define SYMBIAN_API_DISPLAY_WINDOW_SURFACE_H_
6
7#include <cstddef>
8#include <cstdint>
9#include <functional>
10#include <memory>
11#include <optional>
12#include <span>
13#include <string>
14#include <string_view>
15#include <vector>
16
17#include "absl/base/nullability.h"
18#include "absl/status/status.h"
19#include "absl/status/statusor.h"
20
21namespace symbian::api::display {
22
23struct WindowSize {
24 int width = 0;
25 int height = 0;
26};
27
28// Rotation of the current display mode relative to its native orientation.
29enum class DisplayRotation { k0, k90, k180, k270 };
30
42
43enum class WindowKey {
45 kEscape,
47 kLeft,
48 kRight,
49 kUp,
50 kDown,
51 kEnter,
52 kSelect,
53};
54
61
64 std::span<std::byte> pixels;
65 int pitch_bytes = 0;
67};
68
69// The callable runs during one synchronous write. The bitmap view is valid
70// only in the callback; the SDK unlocks it before presentation.
72 std::function<absl::Status(Rgb565Frame)> write;
73};
74
75// A window-local clipping rectangle. Pixels outside it are unchanged.
76struct WindowRect {
77 int x = 0;
78 int y = 0;
79 int width = 0;
80 int height = 0;
81};
82
83// A native-font label drawn over the most recently presented frame.
85 std::u16string_view text;
86 int x = 0;
87 int baseline_y = 0;
88 std::uint32_t rgb = 0xffffff;
89 std::optional<WindowRect> clip;
90};
91
94 std::uint64_t frames = 0;
95 std::uint64_t total_native_ticks = 0;
96 std::uint32_t max_native_ticks = 0;
97};
98
101 // Keep the EGL drawable in physical panel coordinates across display mode
102 // changes. Window layout and pointer events remain in logical coordinates.
103 // This avoids replacing a camera's surface merely to rotate its controls.
105};
106
114class WindowSurface final {
115 public:
116 static absl::StatusOr<WindowSurface> Create(
117 std::string_view task_caption = {}, WindowSurfaceOptions options = {});
118 static absl::StatusOr<std::unique_ptr<WindowSurface>> CreateUnique(
119 std::string_view task_caption = {}, WindowSurfaceOptions options = {});
120 WindowSurface(const WindowSurface&) = delete;
122 WindowSurface(WindowSurface&& other) noexcept;
123 WindowSurface& operator=(WindowSurface&& other) noexcept;
125
126 static absl::StatusOr<WindowSize> PrimarySize();
128 static std::optional<std::uint32_t> PrimaryRefreshRateHz();
130 absl::Status SetAutomaticOrientation(bool enabled);
131 absl::StatusOr<Rgb565Frame> CreateRgb565Frame();
132 absl::Status UpdateRgb565Frame(Rgb565FrameWriter writer);
133 absl::Status Present();
134 // Composes clipped text with explicitly requested grayscale antialiasing
135 // into the bitmap before a single window blit.
136 // Window Server chooses the platform rendering backend; this needs neither
137 // EGL nor a GPU on older devices.
138 absl::Status Present(std::span<const WindowTextLine> lines,
139 int font_height_pixels = 20);
140 // Composes labels into the current RGB565 bitmap and presents it. Replace
141 // the frame's pixels before replacing labels. Redraws replay the composed
142 // bitmap; the caller owns text until this returns.
143 absl::Status DrawTextLines(std::span<const WindowTextLine> lines,
144 int font_height_pixels = 20);
145 // Wraps UTF-16 text to the actual device font metrics, preserving newlines.
146 absl::StatusOr<std::vector<std::u16string>> WrapTextLines(
147 std::u16string_view text, int max_width_pixels,
148 int font_height_pixels = 20) const;
149 absl::StatusOr<std::optional<WindowInput>> PollInput();
150 // Block until input or an exposure redraw is ready without consuming it.
151 // Call PollInput to drain ready events before waiting again.
152 absl::Status WaitForInput();
153 void DestroyFrame();
154 void Close();
155
156 WindowSize size() const;
159 void* absl_nullable NativeWindowHandle() const;
160 void set_measure_frames(bool enabled);
162
163 private:
165 absl::Status Open(std::string_view task_caption,
166 WindowSurfaceOptions options);
167 absl::Status ValidateTextLines(std::span<const WindowTextLine> lines,
168 int font_height_pixels) const;
169 struct Impl;
170 Impl* absl_nullable impl_ = nullptr;
171};
172
173} // namespace symbian::api::display
174
175#endif // SYMBIAN_API_DISPLAY_WINDOW_SURFACE_H_
Owns one Window Server window, its requests and optional RGB565 frame.
Definition window_surface.h:114
DisplayRotation rotation() const
Definition window_surface.cc:885
~WindowSurface()
Definition window_surface.cc:478
absl::Status DrawTextLines(std::span< const WindowTextLine > lines, int font_height_pixels=20)
Definition window_surface.cc:654
static std::optional< std::uint32_t > PrimaryRefreshRateHz()
Physical refresh rate when the display driver reports one.
Definition window_surface.cc:510
void set_measure_frames(bool enabled)
Definition window_surface.cc:896
static absl::StatusOr< WindowSize > PrimarySize()
Definition window_surface.cc:483
absl::StatusOr< std::optional< WindowInput > > PollInput()
Definition window_surface.cc:780
void Close()
Definition window_surface.cc:875
static absl::StatusOr< std::unique_ptr< WindowSurface > > CreateUnique(std::string_view task_caption={}, WindowSurfaceOptions options={})
Definition window_surface.cc:455
absl::StatusOr< std::vector< std::u16string > > WrapTextLines(std::u16string_view text, int max_width_pixels, int font_height_pixels=20) const
Definition window_surface.cc:659
absl::StatusOr< Rgb565Frame > CreateRgb565Frame()
Definition window_surface.cc:696
WindowSurface & operator=(const WindowSurface &)=delete
WindowSize size() const
Definition window_surface.cc:881
absl::Status WaitForInput()
Definition window_surface.cc:860
absl::Status Present()
Definition window_surface.cc:764
WindowFrameMetrics frame_metrics() const
Definition window_surface.cc:902
void *absl_nullable NativeWindowHandle() const
Opaque native window for the SDK EGL compatibility bridge.
Definition window_surface.cc:889
void DestroyFrame()
Definition window_surface.cc:869
absl::Status SetAutomaticOrientation(bool enabled)
Follow the device's automatic display orientation policy.
Definition window_surface.cc:616
absl::Status UpdateRgb565Frame(Rgb565FrameWriter writer)
Definition window_surface.cc:733
WindowSurface(const WindowSurface &)=delete
static absl::StatusOr< WindowSurface > Create(std::string_view task_caption={}, WindowSurfaceOptions options={})
Definition window_surface.cc:445
GLint enabled
Definition gles2_frame_backend.cc:62
Definition display.cc:9
WindowKey
Definition window_surface.h:43
WindowInputKind
Definition window_surface.h:31
DisplayRotation
Definition window_surface.h:29
Definition window_surface.h:71
std::function< absl::Status(Rgb565Frame)> write
Definition window_surface.h:72
A live RGB565 bitmap view owned by its WindowSurface.
Definition window_surface.h:63
WindowSize size
Definition window_surface.h:66
std::span< std::byte > pixels
Definition window_surface.h:64
int pitch_bytes
Definition window_surface.h:65
Optional per-window presentation counters for device comparisons.
Definition window_surface.h:93
std::uint64_t frames
Definition window_surface.h:94
std::uint32_t max_native_ticks
Definition window_surface.h:96
std::uint64_t total_native_ticks
Definition window_surface.h:95
Definition window_surface.h:55
WindowKey key
Definition window_surface.h:59
int y
Definition window_surface.h:58
int x
Definition window_surface.h:57
WindowInputKind kind
Definition window_surface.h:56
Definition window_surface.h:76
int y
Definition window_surface.h:78
int x
Definition window_surface.h:77
int height
Definition window_surface.h:80
int width
Definition window_surface.h:79
Definition window_surface.h:23
int height
Definition window_surface.h:25
int width
Definition window_surface.h:24
Options applied before a native window becomes visible.
Definition window_surface.h:100
bool fixed_egl_orientation
Definition window_surface.h:104
Definition window_surface.cc:142
Definition window_surface.h:84
std::optional< WindowRect > clip
Definition window_surface.h:89
std::u16string_view text
Definition window_surface.h:85
int x
Definition window_surface.h:86
int baseline_y
Definition window_surface.h:87
std::uint32_t rgb
Definition window_surface.h:88