Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
gles2_texture.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_GLES2_TEXTURE_H_
5#define SYMBIAN_API_DISPLAY_GLES2_TEXTURE_H_
6
7#include <cstdint>
8#include <memory>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12
13namespace symbian::api::display {
14
15// Owns a four-byte-per-pixel GLES2 texture in the current context. Destruction must
16// occur while its context is current on the creating thread.
17class Gles2Texture final {
18 public:
19 static absl::StatusOr<Gles2Texture> Create(int width, int height);
20 static absl::StatusOr<std::unique_ptr<Gles2Texture>> CreateUnique(int width,
21 int height);
22 Gles2Texture(const Gles2Texture&) = delete;
24 Gles2Texture(Gles2Texture&& other) noexcept;
25 Gles2Texture& operator=(Gles2Texture&& other) noexcept;
27
28 absl::Status Resize(int width, int height);
29 void Close();
30
31 std::uintptr_t handle() const { return texture_; }
32
33 int width() const { return width_; }
34
35 int height() const { return height_; }
36
37 private:
38 Gles2Texture() = default;
39 unsigned int texture_ = 0;
40 int width_ = 0;
41 int height_ = 0;
42};
43
45 int x = 0;
46 int y = 0;
47 int width = 0;
48 int height = 0;
49};
50
51// Scale an image to cover a surface without stretching it. The centered
52// viewport may extend beyond the surface; GLES clips the excess pixels.
53absl::StatusOr<Gles2Viewport> AspectFillViewport(int surface_width,
54 int surface_height,
55 int image_width,
56 int image_height);
57
58// Preserve the complete image inside a surface, leaving unused bands when
59// their aspect ratios differ.
60absl::StatusOr<Gles2Viewport> AspectFitViewport(int surface_width,
61 int surface_height,
62 int image_width,
63 int image_height);
64
65// Describes byte order, row origin and a presentation rotation. Rotation is
66// applied in the shader without changing the uploaded texture.
68
70 bool blue_first = false;
71 bool top_down = false;
73 // Normalized source bounds with a top-left origin. Full texture by default.
74 float source_left = 0.0f;
75 float source_top = 0.0f;
76 float source_right = 1.0f;
77 float source_bottom = 1.0f;
78};
79
80// Draws any RGBA8888 texture into the current GLES2 framebuffer. Calls use
81// an exclusive context: this helper changes its GL state and does not restore
82// it. The caller owns context activation and swap timing.
84 public:
85 static absl::StatusOr<Gles2TexturePresenter> Create();
86 static absl::StatusOr<std::unique_ptr<Gles2TexturePresenter>> CreateUnique();
92
93 absl::Status Clear(int width, int height, float red, float green, float blue);
94 absl::Status Draw(const Gles2Texture& texture, Gles2Viewport viewport,
95 Gles2TextureSampling sampling = {});
96 void Close();
97
98 private:
99 Gles2TexturePresenter() = default;
100 absl::Status Open();
101 unsigned int program_ = 0;
102 int sampler_ = -1;
103 int blue_first_ = -1;
104 int top_down_ = -1;
105 int rotation_ = -1;
106 int source_rect_ = -1;
107};
108
109} // namespace symbian::api::display
110
111#endif // SYMBIAN_API_DISPLAY_GLES2_TEXTURE_H_
unsigned green
Definition frame.cc:423
unsigned blue
Definition frame.cc:424
unsigned red
Definition frame.cc:422
Gles2TexturePresenter(const Gles2TexturePresenter &)=delete
void Close()
Definition gles2_texture.cc:328
static absl::StatusOr< std::unique_ptr< Gles2TexturePresenter > > CreateUnique()
Definition gles2_texture.cc:223
~Gles2TexturePresenter()
Definition gles2_texture.cc:234
static absl::StatusOr< Gles2TexturePresenter > Create()
Definition gles2_texture.cc:216
absl::Status Draw(const Gles2Texture &texture, Gles2Viewport viewport, Gles2TextureSampling sampling={})
Definition gles2_texture.cc:293
Gles2TexturePresenter & operator=(const Gles2TexturePresenter &)=delete
absl::Status Clear(int width, int height, float red, float green, float blue)
Definition gles2_texture.cc:279
Definition gles2_texture.h:17
absl::Status Resize(int width, int height)
Definition gles2_texture.cc:158
Gles2Texture(const Gles2Texture &)=delete
static absl::StatusOr< std::unique_ptr< Gles2Texture > > CreateUnique(int width, int height)
Definition gles2_texture.cc:142
int height() const
Definition gles2_texture.h:35
void Close()
Definition gles2_texture.cc:184
static absl::StatusOr< Gles2Texture > Create(int width, int height)
Definition gles2_texture.cc:136
Gles2Texture & operator=(const Gles2Texture &)=delete
int width() const
Definition gles2_texture.h:33
std::uintptr_t handle() const
Definition gles2_texture.h:31
~Gles2Texture()
Definition gles2_texture.cc:154
GLint viewport[4]
Definition gles2_frame_backend.cc:93
AttributeState texture
Definition gles2_frame_backend.cc:107
Definition display.cc:9
absl::StatusOr< Gles2Viewport > AspectFillViewport(int surface_width, int surface_height, int image_width, int image_height)
Definition gles2_texture.cc:66
TextureRotation
Definition gles2_texture.h:67
absl::StatusOr< Gles2Viewport > AspectFitViewport(int surface_width, int surface_height, int image_width, int image_height)
Definition gles2_texture.cc:95
Definition gles2_texture.h:69
float source_bottom
Definition gles2_texture.h:77
float source_left
Definition gles2_texture.h:74
float source_right
Definition gles2_texture.h:76
float source_top
Definition gles2_texture.h:75
bool top_down
Definition gles2_texture.h:71
bool blue_first
Definition gles2_texture.h:70
TextureRotation rotation
Definition gles2_texture.h:72
Definition gles2_texture.h:44
int height
Definition gles2_texture.h:48
int x
Definition gles2_texture.h:45
int width
Definition gles2_texture.h:47
int y
Definition gles2_texture.h:46
std::uint32_t height
Definition window_surface.cc:109
std::uint32_t width
Definition window_surface.cc:108