6df181a022
Change-Id: Idd66418b0e47d5fa0ac8f1d7cc46ea9cd5fe69f1 Signed-off-by: zengqingyu <zengqingyu3@huawei.com> |
||
---|---|---|
figures | ||
frameworks | ||
interfaces | ||
rosen | ||
utils | ||
.gitattributes | ||
BUILD.gn | ||
bundle.json | ||
default.scss | ||
graphic_config.gni | ||
graphic.cfg | ||
graphic.rc | ||
LICENSE | ||
OAT.xml | ||
README_zh.md | ||
README.md |
Graphics
Introduction
The Graphics subsystem provides graphics and window management capabilities, which can be invoked by using Java or JS APIs. It can be used for UI development for all standard-system devices.
The following figure shows the architecture of the Graphics subsystem.
-
Surface
Provides APIs for managing the graphics buffer and the efficient and convenient rotation buffer.
-
Vsync
Provides APIs for managing registration and response of all vertical sync signals.
-
WindowManager
Provides APIs for creating and managing windows.
-
WaylandProtocols
Provides the communication protocols between the window manager and synthesizer.
-
Compositor
Implements synthesis of layers.
-
Renderer
Functions as the back-end rendering module of the synthesizer.
-
Wayland protocols
Provides Wayland inter-process communication protocols.
-
Shell
Provides multi-window capabilities.
-
Input Manger
Functions as the multimodal input module that receives input events.
Directory Structure
foundation/graphic/standard/
├── frameworks # Framework code
│ ├── bootanimation # Boot Animation code
│ ├── surface # Surface code
│ ├── vsync # Vsync code
│ └── wm # WindowManager code
├── interfaces # External APIs
│ ├── innerkits # Native APIs
│ └── kits # JS APIs and NAPIs
└── utils # Utilities
Constraints
- Language version: C++ 11 or later
Compilation and Building
The dependent APIs include the following:
- graphic_standard:libwms_client
- graphic_standard:libsurface
- graphic_standard:libvsync_client
Available APIs
WindowManager
Window
SubWindow
Surface
SurfaceBuffer
Obtains the BufferHandle pointer to the SurfaceBuffer object. |
|
VsyncHelper
Constructs a VsyncHelper object using an EventHandler object. |
|
Usage
Transferring a Producer Surface
-
Named service
-
Service registration:
// Obtain a consumer surface. sptr<Surface> surface = Surface::CreateSurfaceAsConsumer(); // Extract the producer object. sptr<IBufferProducer> producer = surface->GetProducer(); // Register the service. auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sm->AddSystemAbility(IPC_SA_ID, producer->AsObject());
-
Construction of a producer surface:
// Obtain a producer object. auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr<IRemoteObject> robj = sm->GetSystemAbility(IPC_SA_ID); // Construct a surface. sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj); sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
-
-
Anonymous service
-
Sending of a surface:
// Obtain a consumer surface. sptr<Surface> surface = CreateSurfaceAsConsumer(); // Extract the producer object. sptr<IRemoteObject> producer = surface->GetProducer(); // Return the producer object to the client. parcel.WriteRemoteObject(producer);
-
Creating a Producer Surface
// Obtain a producer object.
sptr<IRemoteObject> remoteObject = parcel.ReadRemoteObject();
// Construct a surface.
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
Producing a SurfaceBuffer
// Prerequisite: a producer surface
BufferRequestConfig requestConfig = {
.width = 1920, // Screen width
.height = 1080, // Screen height
.strideAlignment = 8, // Stride alignment byte
.format = PIXEL_FMT_RGBA_8888, // Color format
.usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // Usage
.timeout = 0, // Delay
};
sptr<SurfaceBuffer> buffer;
int32_t releaseFence;
GSError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig);
if (ret != GSERROR_OK) {
// failed
}
BufferFlushConfig flushConfig = {
.damage = { // Redrawing buffer zone
.x = 0, // Horizontal coordinate of the start point
.y = 0, // Vertical coordinate of the start point
.w = buffer->GetWidth(), // Width of the buffer zone
.h = buffer->GetHeight(), // Height of the buffer zone
},
.timestamp = 0 // Time displayed to consumers. Value 0 indicates the current time.
};
ret = surface->FlushBuffer(buffer, -1, flushConfig);
if (ret != GSERROR_OK) {
// failed
}
Consuming a SurfaceBuffer
// Prerequisite: a consumer surface
class TestConsumerListener : public IBufferConsumerListener {
public:
void OnBufferAvailable() override {
sptr<SurfaceBuffer> buffer;
int32_t flushFence;
GSError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage);
if (ret != GSERROR_OK) {
// failed
}
// ...
ret = surface->ReleaseBuffer(buffer, -1);
if (ret != GSERROR_OK) {
// failed
}
}
};
sptr<IBufferConsumerListener> listener = new TestConsumerListener();
GSError ret = surface->RegisterConsumerListener(listener);
if (ret != GSERROR_OK) {
// failed
}
Adding Custom Data to a SurfaceBuffer
sptr<SurfaceBuffer> buffer;
GSError ret = buffer->SetInt32(1, 3);
if (ret != GSERROR_OK) {
// failed
}
int32_t val;
ret = buffer->GetInt32(1, val);
if (ret != GSERROR_OK) {
// failed
}
Registering a Vsync Callback Listener
-
Construct a VsyncHelper object using handler.
auto runner = AppExecFwk::EventRunner::Create(true); auto handler = std::make_shared<AppExecFwk::EventHandler>(runner); auto helper = new VsyncHelper(handler); runner->Run(); struct FrameCallback cb = { .timestamp_ = 0, .userdata_ = nullptr, .callback_ = [](int64_t timestamp, void* userdata) { }, }; GSError ret = helper->RequestFrameCallback(cb); if (ret != GSERROR_OK) { // failed }
-
Use Current in handler.
auto runner = AppExecFwk::EventRunner::Create(true); auto handler = std::make_shared<AppExecFwk::EventHandler>(runner); handler->PostTask([]() { auto helper = VsyncHelper::Current(); struct FrameCallback cb = { .timestamp_ = 0, .userdata_ = nullptr, .callback_ = [](int64_t timestamp, void* userdata) { }, }; GSError ret = helper->RequestFrameCallback(cb); if (ret != GSERROR_OK) { // failed } }); runner->Run();
Repositories Involved
Graphics subsystem
graphic_standard
ace_ace_engine
aafwk_L2
multimedia_media_standard
multimedia_camera_standard