1 Star 0 Fork 1.4K

licheng_1123 / graphic_standard

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

graphic_standard

简介

Graphic子系统 提供了图形接口能力和窗口管理接口能力,

其主要的结构如下图所示:

Graphic子系统架构图

  • Surface

    图形缓冲区管理接口,负责管理图形缓冲区和高效便捷的轮转缓冲区。

  • Vsync

    垂直同步信号管理接口,负责管理所有垂直同步信号注册和响应。

  • WindowManager

    窗口管理器接口,负责创建和管理窗口。

  • WaylandProtocols

    窗口管理器和合成器的通信协议。

  • Compositor

    合成器,负责合成各个图层。

  • Renderer

    合成器的后端渲染模块。

  • Wayland protocols

    Wayland 进程间通信协议

  • Shell

    提供多窗口能力

  • Input Manger

    多模输入模块,负责接收事件输入

目录

foundation/graphic/standard/
├── frameworks              # 框架代码目录
│   ├── bootanimation       # 开机动画目录
│   ├── surface             # Surface代码
│   ├── vsync               # Vsync代码
│   └── wm                  # WindowManager代码
├── interfaces              # 对外接口存放目录
│   ├── innerkits           # native接口存放目录
│   └── kits                # js/napi接口存放目录
└── utils                   # 小部件存放目录

约束

  • 语言版本
    • C++11或以上

编译构建

可以依赖的接口有:

  • graphic_standard:libwms_client
  • graphic_standard:libsurface
  • graphic_standard:libvsync_client

接口说明

WindowManager

接口名 职责
GetInstance 获取WindowManager的单例指针
GetMaxWidth 获取当前屏幕宽度
GetMaxHeight 获取当前屏幕高度
CreateWindow 创建一个标准窗口
CreateSubWindow 创建一个子窗口
StartShotScreen 截屏操作
StartShotWindow 截取窗口操作
SwitchTop 将指定窗口调整至最上层显示

Window

接口名 职责
Show 显示当前窗口
Hide 隐藏当前窗口
Move 移动当前窗口至指定位置
SwitchTop 将当前窗口调整到最上层显示
ChangeWindowType 更改当前窗口类型
ReSize 调整当前窗口至指定大小
Rotate 旋转当前窗口
RegistPointerButtonCb 注册鼠标Button事件回调
RegistPointerEnterCb 注册鼠标Enter事件回调
RegistPointerLeaveCb 注册鼠标Leave事件回调
RegistPointerMotionCb 注册鼠标Motion事件回调
RegistPointerAxisDiscreteCb 注册鼠标AxisDiscrete事件回调
RegistPointerAxisSourceCb 注册鼠标AxisSource事件回调
RegistPointerAxisStopCb 注册鼠标AxisStop事件回调
RegistPointerAxisCb 注册鼠标Axis事件回调
RegistTouchUpCb 注册TouchUp事件回调
RegistTouchDownCb 注册TouchDown事件回调
RegistTouchEmotionCb 注册TouchEmotion事件回调
RegistTouchFrameCb 注册TouchFrame事件回调
RegistTouchCancelCb 注册TouchCancel事件回调
RegistTouchShapeCb 注册TouchShape事件回调
RegistTouchOrientationCb 注册TouchOrientation事件回调
RegistKeyboardKeyCb 注册键盘Key事件回调
RegistKeyboardKeyMapCb 注册键盘KeyMap事件回调
RegistKeyboardLeaveCb 注册键盘Leave事件回调
RegistKeyboardEnterCb 注册键盘Enter事件回调
RegistKeyboardRepeatInfoCb 注册键盘RepeatInfo事件回调

SubWindow

接口名 职责
Move 移动当前子窗口
SetSubWindowSize 调整当前子窗口位置

Surface

接口名 职责
CreateSurfaceAsConsumer Buffer的消费者来使用该函数创建一个Surface
CreateSurfaceAsProducer Buffer的生产者使用该函数创建一个Surface,只能使用与生产相关的接口
GetProducer 获得一个Surface内部的IBufferProducer对象
RequestBuffer 请求一个待生产的SurfaceBuffer对象
CancelBuffer 取消、归还一个待生产的SurfaceBuffer对象
FlushBuffer 归还一个生产好的SurfaceBuffer对象并携带一些信息
AcquireBuffer 请求一个待消费的SurfaceBuffer对象
ReleaseBuffer 归还一个已消费的SurfaceBuffer对象
GetQueueSize 获得当前同时能并存buffer的数量
SetQueueSize 设置当前同时能并存buffer的数量
SetDefaultWidthAndHeight 设置默认宽和高
GetDefaultWidth 获得默认宽度
GetDefaultHeight 获得默认高度
SetUserData 存贮字符串数据,不随着IPC传递
GetUserData 取出字符串数据
RegisterConsumerListener 注册一个消费监听器,监听Buffer的Flush事件
UnregisterConsumerListener 取消监听

SurfaceBuffer

接口名 职责
GetBufferHandle 获得SurfaceBuffer的BufferHandle指针
GetWidth 获得SurfaceBuffer的宽度
GetHeight 获得SurfaceBuffer的高度
GetFormat 获得SurfaceBuffer的颜色格式
GetUsage 获得SurfaceBuffer的用途
GetPhyAddr 获得SurfaceBuffer的物理地址
GetKey 获得SurfaceBuffer的key
GetVirAddr 获得SurfaceBuffer的虚拟地址
GetSize 获得SurfaceBuffer的文件句柄
SetInt32 获得SurfaceBuffer的缓冲区大小
GetInt32 设置SurfaceBuffer的32位整数
SetInt64 获得SurfaceBuffer的32位整数
GetInt64 设置SurfaceBuffer的64位整数

VsyncHelper

接口名 职责
Current 获取当前runner对应的VsyncHelper
VsyncHelper 用EventHandler对象构造VsyncHelper
RequestFrameCallback 注册一个帧回调

使用说明

具名服务-传递一个生产型Surface

注册

// 拿到一个消费型Surface
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();

// 拿出里面的生产者对象
sptr<IBufferProducer> producer = surface->GetProducer();

// 注册服务
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sm->AddSystemAbility(IPC_SA_ID, producer->AsObject());

客户端获得生产型Surface

// 获得远程对象
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> robj = sm->GetSystemAbility(IPC_SA_ID);

// 构造Surface
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);

匿名服务-传递一个生产型Surface

场景: 在一次IPC过程中

发送

// 拿到一个消费型Surface
sptr<Surface> surface = CreateSurfaceAsConsumer();

// 拿出里面的生产者对象
sptr<IRemoteObject> producer = surface->GetProducer();

// 返回给客户端
parcel.WriteRemoteObject(producer);

接受并获得生产型Surface

// 获得远程对象
sptr<IRemoteObject> remoteObject = parcel.ReadRemoteObject();

// 构造Surface
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);

生产一个SurfaceBuffer

条件: 一个生产型Surface

BufferRequestConfig requestConfig = {
    .width = 1920, // 屏幕宽度
    .height = 1080, // 屏幕高度
    .strideAlignment = 8, // stride对齐字节
    .format = PIXEL_FMT_RGBA_8888, // 颜色格式
    .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // 用法
    .timeout = 0, // 时延
};

sptr<SurfaceBuffer> buffer;
int32_t releaseFence;

SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig);
if (ret != SURFACE_ERROR_OK) {
    // failed
}

BufferFlushConfig flushConfig = {
    .damage = {                   // 重绘区域
        .x = 0,                   // 起点横坐标
        .y = 0,                   // 起点纵坐标
        .w = buffer->GetWidth(),  // 区域宽度
        .h = buffer->GetHeight(), // 区域高度
    },
    .timestamp = 0 // 给消费者看的时间,0为使用当前时间
};

ret = surface->FlushBuffer(buffer, -1, flushConfig);
if (ret != SURFACE_ERROR_OK) {
    // failed
}

消费一个SurfaceBuffer

条件: 一个消费型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
}

给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
}

注册一个Vsync回调事件

用handler构造VsyncHelper

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
}

在handler里用Current

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();

相关仓

  • graphic_standard
  • ace_ace_engine
  • aafwk_standard
  • multimedia_media_standard
  • multimedia_camera_standard
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

Window manager and compositor | 图形窗口合成器 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mminput/graphic_standard.git
git@gitee.com:mminput/graphic_standard.git
mminput
graphic_standard
graphic_standard
master

搜索帮助