Go to file
shiyueeee 98f5dd15f4 Set display size as screen mode changes
Change-Id: I8c49155056aaa161c483941f4a857fcb2614db34
Signed-off-by: shiyueeee <nieshiyue@huawei.com>
2022-02-13 19:09:10 +08:00
dm Set display size as screen mode changes 2022-02-13 19:09:10 +08:00
dmserver Set display size as screen mode changes 2022-02-13 19:09:10 +08:00
figures Enable windowmangaer 2021-12-31 17:40:40 +08:00
interfaces Set display size as screen mode changes 2022-02-13 19:09:10 +08:00
resources !161 单应用分屏支持layout避让 2022-01-25 20:48:28 +08:00
sa_profile 修改dms wms启动优先级,修改死亡监听添加判断 2022-01-19 17:07:15 +08:00
snapshot 修复screenshot max size bug 2022-02-10 12:43:43 +08:00
utils Set display size as screen mode changes 2022-02-13 19:09:10 +08:00
wm ut and st for window effect 2022-02-13 11:20:03 +08:00
wmserver !243 支持物理屏幕的旋转 2022-02-13 07:29:08 +00:00
wmtest fix int32_t displayId to uint64_t 2022-01-26 11:24:24 +08:00
bundle.json move windowStage back to window 2022-02-07 16:51:19 +08:00
LICENSE add LICENSE and OAT.xml 2022-02-12 09:14:42 +08:00
OAT.xml add LICENSE and OAT.xml 2022-02-12 09:14:42 +08:00
README_zh.md update readme 2021-12-31 18:09:58 +08:00
README.md update readme 2021-12-31 18:09:58 +08:00

WidnowManager

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

API

Description

GetInstance

Obtains the pointer to a singleton WindowManager instance.

GetMaxWidth

Obtains the width of the screen.

GetMaxHeight

Obtains the height of the screen.

CreateWindow

Creates a standard window.

CreateSubWindow

Creates a child window.

StartShotScreen

Takes a screenshot.

StartShotWindow

Captures a window.

SwitchTop

Moves the specified window to the top.

Window

API

Description

Show

Displays the current window.

Hide

Hides the current window.

Move

Moves the current window to a specified position.

SwitchTop

Moves the current window to the top.

ChangeWindowType

Changes the type of the current window.

ReSize

Resizes the current window.

Rotate

Rotates the current window.

RegistPointerButtonCb

Registers the callback for Button events of the mouse.

RegistPointerEnterCb

Registers the callback for Enter events of the mouse.

RegistPointerLeaveCb

Registers the callback for Leave events of the mouse.

RegistPointerMotionCb

Registers the callback for Motion events of the mouse.

RegistPointerAxisDiscreteCb

Registers the callback for AxisDiscrete events of the mouse.

RegistPointerAxisSourceCb

Registers the callback for AxisSource events of the mouse.

RegistPointerAxisStopCb

Registers the callback for AxisStop events of the mouse.

RegistPointerAxisCb

Registers the callback for Axis events of the mouse.

RegistTouchUpCb

Registers the callback for TouchUp events.

RegistTouchDownCb

Registers the callback for TouchDown events.

RegistTouchEmotionCb

Registers the callback for TouchEmotion events.

RegistTouchFrameCb

Registers the callback for TouchFrame events.

RegistTouchCancelCb

Registers the callback for TouchCancel events.

RegistTouchShapeCb

Registers the callback for TouchShape events.

RegistTouchOrientationCb

Registers the callback for TouchOrientation events.

RegistKeyboardKeyCb

Registers the callback for Key events of the keyboard.

RegistKeyboardKeyMapCb

Registers the callback for KeyMap events of the keyboard.

RegistKeyboardLeaveCb

Registers the callback for Leave events of the keyboard.

RegistKeyboardEnterCb

Registers the callback for Enter events of the keyboard.

RegistKeyboardRepeatInfoCb

Registers the callback for RepeatInfo events of the keyboard.

SubWindow

API

Description

Move

Moves the current child window.

SetSubWindowSize

Sets the size of the current child window.

Surface

API

Description

CreateSurfaceAsConsumer

Creates a surface for the buffer consumer.

CreateSurfaceAsProducer

Creates a surface for the buffer producer. Only production-related APIs can be used.

GetProducer

Obtains an internal IBufferProducer object of Surface.

RequestBuffer

Requests a SurfaceBuffer object to be produced.

CancelBuffer

Cancels a SurfaceBuffer object to be produced.

FlushBuffer

Flushes a produced SurfaceBuffer object with certain information.

AcquireBuffer

Requests a SurfaceBuffer object to be consumed.

ReleaseBuffer

Returns a consumed SurfaceBuffer object.

GetQueueSize

Obtains the number of concurrent buffers.

SetQueueSize

Sets the number of concurrent buffers.

SetDefaultWidthAndHeight

Sets the default width and height.

GetDefaultWidth

Obtains the default width.

GetDefaultHeight

Obtains the default height.

SetUserData

Stores string data, which will not be transferred through IPC.

GetUserData

Obtains string data.

RegisterConsumerListener

Registers a consumer listener to listen for buffer flush events.

UnregisterConsumerListener

Unregiseters a consumer listener.

SurfaceBuffer

API

Description

GetBufferHandle

Obtains the BufferHandle pointer to the SurfaceBuffer object.

GetWidth

Obtains the width of the SurfaceBuffer object.

GetHeight

Obtains the height of the SurfaceBuffer object.

GetFormat

Obtains the color format of the SurfaceBuffer object.

GetUsage

Obtains the usage of the SurfaceBuffer object.

GetPhyAddr

Obtains the physical address of the SurfaceBuffer object.

GetKey

Obtains the key of the SurfaceBuffer object.

GetVirAddr

Obtains the virtual address of the SurfaceBuffer object.

GetSize

Obtains the size of the SurfaceBuffer object.

SetInt32

Sets the 32-bit integer for the SurfaceBuffer object.

GetInt32

Obtains the 32-bit integer for the SurfaceBuffer object.

SetInt64

Sets the 64-bit integer for the SurfaceBuffer object.

GetInt64

Obtains the 64-bit integer for the SurfaceBuffer object.

VsyncHelper

API

Description

Current

Obtains the VsyncHelper object of the current runner.

VsyncHelper

Constructs a VsyncHelper object using an EventHandler object.

RequestFrameCallback

Registers a frame callback.

Usage

Transferring a Producer Surface

  1. 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);
      
  2. 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;

SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig);
if (ret != SURFACE_ERROR_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 != SURFACE_ERROR_OK) {
    // failed
}

Consuming a SurfaceBuffer

// Prerequisite: a consumer surface
class TestConsumerListener : public IBufferConsumerListener {
public:
    void OnBufferAvailable() override {
        sptr<SurfaceBuffer> buffer;
        int32_t flushFence;
        SurfaceError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage);
        if (ret != SURFACE_ERROR_OK) {
            // failed
        }
        // ...
        ret = surface->ReleaseBuffer(buffer, -1);
        if (ret != SURFACE_ERROR_OK) {
            // failed
        }
    }
};

sptr<IBufferConsumerListener> listener = new TestConsumerListener();
SurfaceError ret = surface->RegisterConsumerListener(listener);
if (ret != SURFACE_ERROR_OK) {
    // failed
}

Adding Custom Data to a SurfaceBuffer

sptr<SurfaceBuffer> buffer;
SurfaceError ret = buffer->SetInt32(1, 3);
if (ret != SURFACE_ERROR_OK) {
// failed
}

int32_t val;
ret = buffer->GetInt32(1, val);
if (ret != SURFACE_ERROR_OK) {
// failed
}

Registering a Vsync Callback Listener

  1. 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) {
        },
    };
    
    VsyncError ret = helper->RequestFrameCallback(cb);
    if (ret != VSYNC_ERROR_OK) {
        // failed
    }
    
  2. 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) {
            },
        };
        VsyncError ret = helper->RequestFrameCallback(cb);
        if (ret != VSYNC_ERROR_OK) {
            // failed
        }
    });
    
    runner->Run();
    

Repositories Involved

Graphics subsystem

graphic_standard

ace_ace_engine

aafwk_L2

multimedia_media_standard

multimedia_camera_standard