mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 09:10:54 +00:00
Decoupling lidrm fence
Signed-off-by: h00574155 <hujunjian1@huawei.com> Change-Id: Iddeefafd76ee95ee8d881705e4fa0c4c60f40d37
This commit is contained in:
parent
c34b7c6f66
commit
c31e3c0b02
1
BUILD.gn
1
BUILD.gn
@ -21,7 +21,6 @@ group("default") {
|
|||||||
"frameworks/dumper:gdumper",
|
"frameworks/dumper:gdumper",
|
||||||
"frameworks/dumper:gdumper.ini",
|
"frameworks/dumper:gdumper.ini",
|
||||||
"frameworks/dumper:graphic_dumper_server",
|
"frameworks/dumper:graphic_dumper_server",
|
||||||
"frameworks/vsync:vsync_server",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if (graphic_standard_feature_bootanimation_enable) {
|
if (graphic_standard_feature_bootanimation_enable) {
|
||||||
|
14
bundle.json
14
bundle.json
@ -45,8 +45,7 @@
|
|||||||
"bytrace_core"
|
"bytrace_core"
|
||||||
],
|
],
|
||||||
"third_party": [
|
"third_party": [
|
||||||
"libz",
|
"libz"
|
||||||
"libdrm"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
@ -135,17 +134,6 @@
|
|||||||
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/composer"
|
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/composer"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "so",
|
|
||||||
"name": "//foundation/graphic/graphic_2d/frameworks/vsync:libvsync_module",
|
|
||||||
"header": {
|
|
||||||
"header_files": [
|
|
||||||
"vsync_module.h",
|
|
||||||
"vsync_module_c.h"
|
|
||||||
],
|
|
||||||
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "so",
|
"type": "so",
|
||||||
"name": "//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
"name": "//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||||
|
@ -53,7 +53,6 @@ ohos_executable("bootanimation") {
|
|||||||
"//base/global/resource_management/frameworks/resmgr:global_resmgr",
|
"//base/global/resource_management/frameworks/resmgr:global_resmgr",
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libsurface",
|
"//foundation/graphic/graphic_2d:libsurface",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src/platform:platform",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src/platform:platform",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include <display_type.h>
|
#include <display_type.h>
|
||||||
#include <display_manager.h>
|
#include <display_manager.h>
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include "boot_animation.h"
|
#include "boot_animation.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include <securec.h>
|
#include <securec.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <include/codec/SkCodec.h>
|
#include <include/codec/SkCodec.h>
|
||||||
|
@ -59,10 +59,7 @@ ohos_shared_library("surface") {
|
|||||||
"src/surface_utils.cpp",
|
"src/surface_utils.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
configs = [
|
configs = [ ":surface_config" ]
|
||||||
":surface_config",
|
|
||||||
"//third_party/libdrm:libdrm_public_config",
|
|
||||||
]
|
|
||||||
|
|
||||||
public_configs = [
|
public_configs = [
|
||||||
":surface_public_config",
|
":surface_public_config",
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
"bytrace_core"
|
"bytrace_core"
|
||||||
],
|
],
|
||||||
"third_party": [
|
"third_party": [
|
||||||
"libz",
|
"libz"
|
||||||
"libdrm"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_SURFACE_INCLUDE_EGL_DATA_IMPL_H
|
|
||||||
#define FRAMEWORKS_SURFACE_INCLUDE_EGL_DATA_IMPL_H
|
|
||||||
|
|
||||||
#include <egl_data.h>
|
|
||||||
#include <surface_buffer.h>
|
|
||||||
#include <surface_type.h>
|
|
||||||
|
|
||||||
#include "egl_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
class EglDataImpl : public EglData {
|
|
||||||
public:
|
|
||||||
EglDataImpl();
|
|
||||||
virtual ~EglDataImpl() override;
|
|
||||||
|
|
||||||
GSError CreateEglData(const sptr<SurfaceBuffer> &buffer);
|
|
||||||
virtual uint32_t GetFrameBufferObj() const override;
|
|
||||||
virtual uint32_t GetTexture() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
sptr<EglManager> eglManager_ = nullptr;
|
|
||||||
void *eglImage_ = nullptr;
|
|
||||||
uint32_t glTexture_ = 0;
|
|
||||||
uint32_t glFbo_ = 0;
|
|
||||||
};
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_SURFACE_INCLUDE_EGL_DATA_IMPL_H
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_SURFACE_INCLUDE_EGL_MANAGER_H
|
|
||||||
#define FRAMEWORKS_SURFACE_INCLUDE_EGL_MANAGER_H
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
#include <EGL/eglext.h>
|
|
||||||
#include <GLES2/gl2.h>
|
|
||||||
#include <GLES2/gl2ext.h>
|
|
||||||
#include <refbase.h>
|
|
||||||
#include "surface_type.h"
|
|
||||||
|
|
||||||
using EglCreateImageFunc = PFNEGLCREATEIMAGEKHRPROC;
|
|
||||||
using EglDestroyImageFunc = PFNEGLDESTROYIMAGEKHRPROC;
|
|
||||||
using EglImageTargetTexture2DFunc = PFNGLEGLIMAGETARGETTEXTURE2DOESPROC;
|
|
||||||
using EglCreateSyncFunc = PFNEGLCREATESYNCKHRPROC;
|
|
||||||
using EglDestroySyncFunc = PFNEGLDESTROYSYNCKHRPROC;
|
|
||||||
using EglClientWaitSyncFunc = PFNEGLCLIENTWAITSYNCKHRPROC;
|
|
||||||
using EglDupNativeFenceFdFunc = PFNEGLDUPNATIVEFENCEFDANDROIDPROC;
|
|
||||||
using EglWaitSyncFunc = PFNEGLWAITSYNCKHRPROC;
|
|
||||||
using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
class EglManager : public RefBase {
|
|
||||||
public:
|
|
||||||
static sptr<EglManager> GetInstance();
|
|
||||||
|
|
||||||
EGLDisplay GetEGLDisplay() const;
|
|
||||||
EGLContext GetEGLContext() const;
|
|
||||||
|
|
||||||
EGLImageKHR EglCreateImage(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attribList);
|
|
||||||
EGLImageKHR EglCreateImage(EGLenum target, EGLClientBuffer buffer, const EGLint *attribList);
|
|
||||||
EGLBoolean EglDestroyImage(EGLImageKHR image);
|
|
||||||
void EglImageTargetTexture2D(GLenum target, GLeglImageOES image);
|
|
||||||
EGLSyncKHR EglCreateSync(EGLenum type, const EGLint *attribList);
|
|
||||||
EGLint EglWaitSync(EGLSyncKHR sync, EGLint flags);
|
|
||||||
EGLint EglClientWaitSync(EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
|
|
||||||
EGLBoolean EglDestroySync(EGLSyncKHR sync);
|
|
||||||
EGLint EglDupNativeFenceFd(EGLSyncKHR sync);
|
|
||||||
EGLBoolean EglMakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx);
|
|
||||||
EGLBoolean EglMakeCurrent(EGLSurface draw, EGLSurface read);
|
|
||||||
EGLBoolean EglMakeCurrent();
|
|
||||||
|
|
||||||
GSError Init(EGLContext ctx = EGL_NO_CONTEXT);
|
|
||||||
bool IsInit() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
EglManager();
|
|
||||||
virtual ~EglManager();
|
|
||||||
void Deinit();
|
|
||||||
GSError GbmInit();
|
|
||||||
GSError EglInit(EGLContext ctx = EGL_NO_CONTEXT);
|
|
||||||
GSError EglCheckExt();
|
|
||||||
GSError EglFuncInit();
|
|
||||||
|
|
||||||
thread_local static inline sptr<EglManager> instance_ = nullptr;
|
|
||||||
bool initFlag_ = false;
|
|
||||||
int drmFd_ = -1;
|
|
||||||
void *device_ = nullptr;
|
|
||||||
|
|
||||||
EGLDisplay display_ = EGL_NO_DISPLAY;
|
|
||||||
EGLContext context_ = EGL_NO_CONTEXT;
|
|
||||||
|
|
||||||
std::map<uint32_t, EGLContext> sharedContextCache;
|
|
||||||
|
|
||||||
bool ctxReleaseFlg_ = false;
|
|
||||||
EGLConfig conf_ = NULL;
|
|
||||||
EglCreateImageFunc createImage_ = nullptr;
|
|
||||||
EglDestroyImageFunc destroyImage_ = nullptr;
|
|
||||||
EglImageTargetTexture2DFunc imageTargetTexture2d_ = nullptr;
|
|
||||||
EglCreateSyncFunc createSync_ = nullptr;
|
|
||||||
EglDestroySyncFunc destroySync_ = nullptr;
|
|
||||||
EglWaitSyncFunc waitSync_ = nullptr;
|
|
||||||
EglClientWaitSyncFunc clientWaitSync_ = nullptr;
|
|
||||||
EglDupNativeFenceFdFunc dupNativeFenceFd_ = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_SURFACE_INCLUDE_EGL_MANAGER_H
|
|
@ -22,7 +22,6 @@
|
|||||||
#include <egl_surface.h>
|
#include <egl_surface.h>
|
||||||
#include <ibuffer_producer.h>
|
#include <ibuffer_producer.h>
|
||||||
|
|
||||||
#include "egl_manager.h"
|
|
||||||
#include "surface_buffer.h"
|
#include "surface_buffer.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
#include "buffer_log.h"
|
#include "buffer_log.h"
|
||||||
|
|
||||||
#include "buffer_queue_producer.h"
|
#include "buffer_queue_producer.h"
|
||||||
#include "egl_data_impl.h"
|
|
||||||
#include "egl_manager.h"
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
EglConsumerSurface::EglConsumerSurface(const std::string &name, bool isShared)
|
EglConsumerSurface::EglConsumerSurface(const std::string &name, bool isShared)
|
||||||
: ConsumerSurface(name, isShared)
|
: ConsumerSurface(name, isShared)
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "egl_data_impl.h"
|
|
||||||
|
|
||||||
#include <display_gralloc.h>
|
|
||||||
#include <drm_fourcc.h>
|
|
||||||
|
|
||||||
#include "buffer_log.h"
|
|
||||||
#include "egl_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
EglDataImpl::EglDataImpl()
|
|
||||||
{
|
|
||||||
BLOGD("ctor");
|
|
||||||
eglManager_ = EglManager::GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
EglDataImpl::~EglDataImpl()
|
|
||||||
{
|
|
||||||
BLOGD("dtor");
|
|
||||||
if (glFbo_) {
|
|
||||||
glDeleteFramebuffers(1, &glFbo_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glTexture_) {
|
|
||||||
glDeleteTextures(1, &glTexture_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglImage_) {
|
|
||||||
EglManager::GetInstance()->EglDestroyImage(eglImage_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint EglDataImpl::GetFrameBufferObj() const
|
|
||||||
{
|
|
||||||
return glFbo_;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint EglDataImpl::GetTexture() const
|
|
||||||
{
|
|
||||||
return glTexture_;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
bool PixelFormatToDrmFormat(int32_t pixelFormat, uint32_t &drmFormat)
|
|
||||||
{
|
|
||||||
constexpr struct {
|
|
||||||
int32_t pixelFormat;
|
|
||||||
uint32_t drmFormat;
|
|
||||||
} formatTable[] = {
|
|
||||||
{ PIXEL_FMT_RGB_565, DRM_FORMAT_RGB565 },
|
|
||||||
{ PIXEL_FMT_RGBX_4444, DRM_FORMAT_RGBX4444 },
|
|
||||||
{ PIXEL_FMT_RGBA_4444, DRM_FORMAT_RGBA4444 },
|
|
||||||
{ PIXEL_FMT_RGBX_5551, DRM_FORMAT_RGBX5551 },
|
|
||||||
{ PIXEL_FMT_RGBA_5551, DRM_FORMAT_RGBA5551 },
|
|
||||||
{ PIXEL_FMT_RGBX_8888, DRM_FORMAT_RGBX8888 },
|
|
||||||
{ PIXEL_FMT_RGBA_8888, DRM_FORMAT_ABGR8888 },
|
|
||||||
{ PIXEL_FMT_RGB_888, DRM_FORMAT_RGB888 },
|
|
||||||
{ PIXEL_FMT_BGR_565, DRM_FORMAT_BGR565 },
|
|
||||||
{ PIXEL_FMT_BGRX_4444, DRM_FORMAT_BGRX4444 },
|
|
||||||
{ PIXEL_FMT_BGRA_4444, DRM_FORMAT_BGRA4444 },
|
|
||||||
{ PIXEL_FMT_BGRX_5551, DRM_FORMAT_BGRX5551 },
|
|
||||||
{ PIXEL_FMT_BGRA_5551, DRM_FORMAT_BGRA5551 },
|
|
||||||
{ PIXEL_FMT_BGRX_8888, DRM_FORMAT_BGRX8888 },
|
|
||||||
{ PIXEL_FMT_BGRA_8888, DRM_FORMAT_BGRA8888 },
|
|
||||||
{ PIXEL_FMT_YUV_422_I, DRM_FORMAT_YUV422 },
|
|
||||||
{ PIXEL_FMT_YUYV_422_PKG, DRM_FORMAT_YUYV },
|
|
||||||
{ PIXEL_FMT_UYVY_422_PKG, DRM_FORMAT_UYVY },
|
|
||||||
{ PIXEL_FMT_YVYU_422_PKG, DRM_FORMAT_YVYU },
|
|
||||||
{ PIXEL_FMT_VYUY_422_PKG, DRM_FORMAT_VYUY },
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto &fmt : formatTable) {
|
|
||||||
if (fmt.pixelFormat == pixelFormat) {
|
|
||||||
drmFormat = fmt.drmFormat;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
GSError EglDataImpl::CreateEglData(const sptr<SurfaceBuffer> &buffer)
|
|
||||||
{
|
|
||||||
if (!EglManager::GetInstance()->IsInit()) {
|
|
||||||
EglManager::GetInstance()->Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferHandle *handle = buffer->GetBufferHandle();
|
|
||||||
if (!handle) {
|
|
||||||
BLOGE("Failed to GetBufferHandle");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t drmFormat;
|
|
||||||
if (PixelFormatToDrmFormat(handle->format, drmFormat) == false) {
|
|
||||||
BLOGE("PixelFormatToDrmFormat failed");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint attribs[] = {
|
|
||||||
EGL_WIDTH, handle->width,
|
|
||||||
EGL_HEIGHT, handle->height,
|
|
||||||
EGL_LINUX_DRM_FOURCC_EXT, drmFormat,
|
|
||||||
EGL_DMA_BUF_PLANE0_FD_EXT, handle->fd,
|
|
||||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
|
|
||||||
EGL_DMA_BUF_PLANE0_PITCH_EXT, handle->stride,
|
|
||||||
EGL_NONE,
|
|
||||||
};
|
|
||||||
eglImage_ = EglManager::GetInstance()->EglCreateImage(EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs);
|
|
||||||
if (eglImage_ == EGL_NO_IMAGE_KHR) {
|
|
||||||
BLOGE("##createImage failed.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
EglManager::GetInstance()->EglMakeCurrent();
|
|
||||||
|
|
||||||
glGenTextures(1, &glTexture_);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, glTexture_);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
EglManager::GetInstance()->EglImageTargetTexture2D(GL_TEXTURE_2D, eglImage_);
|
|
||||||
|
|
||||||
glGenFramebuffers(1, &glFbo_);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, glFbo_);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glTexture_, 0);
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
||||||
BLOGE("FBO creation failed");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace OHOS
|
|
@ -1,460 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "egl_manager.h"
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <scoped_bytrace.h>
|
|
||||||
#include <mutex>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "buffer_log.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace {
|
|
||||||
constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
|
|
||||||
constexpr char CHARACTER_WHITESPACE = ' ';
|
|
||||||
constexpr const char *CHARACTER_STRING_WHITESPACE = " ";
|
|
||||||
constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
|
|
||||||
constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
|
|
||||||
constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
|
|
||||||
constexpr const char *EGL_EXT_IMAGE_DMA_BUF_IMPORT = "EGL_EXT_image_dma_buf_import";
|
|
||||||
constexpr const char *EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
|
|
||||||
constexpr const char *EGL_KHR_NO_CONFIG_CONTEXT = "EGL_KHR_no_config_context";
|
|
||||||
constexpr const char *EGL_CREATE_IMAGE_KHR = "eglCreateImageKHR";
|
|
||||||
constexpr const char *EGL_DESTROY_IMAGE_KHR = "eglDestroyImageKHR";
|
|
||||||
constexpr const char *EGL_IMAGE_TARGET_TEXTURE2DOES = "glEGLImageTargetTexture2DOES";
|
|
||||||
constexpr const char *EGL_KHR_FENCE_SYNC = "EGL_KHR_fence_sync";
|
|
||||||
constexpr const char *EGL_CREATE_SYNC_KHR = "eglCreateSyncKHR";
|
|
||||||
constexpr const char *EGL_DESTROY_SYNC_KHR = "eglDestroySyncKHR";
|
|
||||||
constexpr const char *EGL_CLIENT_WAIT_SYNC_KHR = "eglClientWaitSyncKHR";
|
|
||||||
constexpr const char *EGL_DUP_NATIVE_FENCE_FD_ANDROID = "eglDupNativeFenceFDANDROID";
|
|
||||||
constexpr const char *EGL_KHR_WAIT_SYNC = "EGL_KHR_wait_sync";
|
|
||||||
constexpr const char *EGL_WAIT_SYNC_KHR = "eglWaitSyncKHR";
|
|
||||||
constexpr const char *GL_OES_EGL_IMAGE = "GL_OES_EGL_image";
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
EglManager::EglManager()
|
|
||||||
{
|
|
||||||
BLOGD("EglManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
EglManager::~EglManager()
|
|
||||||
{
|
|
||||||
BLOGD("~EglManager");
|
|
||||||
Deinit();
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<EglManager> EglManager::GetInstance()
|
|
||||||
{
|
|
||||||
if (instance_ == nullptr) {
|
|
||||||
static std::mutex mutex;
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
|
||||||
if (instance_ == nullptr) {
|
|
||||||
instance_ = new EglManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EglManager::IsInit() const
|
|
||||||
{
|
|
||||||
return initFlag_;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError EglManager::Init(EGLContext context)
|
|
||||||
{
|
|
||||||
ScopedBytrace eGLManagerInit("EGLManagerInit");
|
|
||||||
if (initFlag_) {
|
|
||||||
BLOGW("already init, eglMakeCurrent");
|
|
||||||
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_);
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GbmInit() != GSERROR_OK) {
|
|
||||||
BLOGE("GbmInit failed.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EglInit(context) != GSERROR_OK) {
|
|
||||||
BLOGE("EglInit failed.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
initFlag_ = true;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError EglManager::GbmInit()
|
|
||||||
{
|
|
||||||
device_ = EGL_DEFAULT_DISPLAY;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
static bool CheckEglExtension(const char *extensions, const char *extension)
|
|
||||||
{
|
|
||||||
size_t extlen = strlen(extension);
|
|
||||||
const char *end = extensions + strlen(extensions);
|
|
||||||
|
|
||||||
while (extensions < end) {
|
|
||||||
size_t n = 0;
|
|
||||||
|
|
||||||
/* Skip whitespaces, if any */
|
|
||||||
if (*extensions == CHARACTER_WHITESPACE) {
|
|
||||||
extensions++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = strcspn(extensions, CHARACTER_STRING_WHITESPACE);
|
|
||||||
/* Compare strings */
|
|
||||||
if (n == extlen && strncmp(extension, extensions, n) == 0) {
|
|
||||||
return true; /* Found */
|
|
||||||
}
|
|
||||||
extensions += n;
|
|
||||||
}
|
|
||||||
/* Not found */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static EGLDisplay GetPlatformEglDisplay(EGLenum platform, EGLDisplay native_display, const EGLint *attrib_list)
|
|
||||||
{
|
|
||||||
static GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL;
|
|
||||||
|
|
||||||
if (!eglGetPlatformDisplayExt) {
|
|
||||||
const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
|
||||||
if (extensions &&
|
|
||||||
(CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) ||
|
|
||||||
CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) {
|
|
||||||
eglGetPlatformDisplayExt =
|
|
||||||
(GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglGetPlatformDisplayExt) {
|
|
||||||
return eglGetPlatformDisplayExt(platform, native_display, attrib_list);
|
|
||||||
}
|
|
||||||
return eglGetDisplay((EGLNativeDisplayType) native_display);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError EglManager::EglCheckExt()
|
|
||||||
{
|
|
||||||
const char *eglExtensions = eglQueryString(display_, EGL_EXTENSIONS);
|
|
||||||
if (eglExtensions == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CheckEglExtension(eglExtensions, EGL_EXT_IMAGE_DMA_BUF_IMPORT)) {
|
|
||||||
BLOGE("EGL_EXT_image_dma_buf_import not supported");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CheckEglExtension(eglExtensions, EGL_KHR_SURFACELESS_CONTEXT)) {
|
|
||||||
BLOGE("EGL_KHR_surfaceless_context not supported");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckEglExtension(eglExtensions, EGL_KHR_NO_CONFIG_CONTEXT)) {
|
|
||||||
conf_ = EGL_NO_CONFIG_KHR;
|
|
||||||
} else {
|
|
||||||
BLOGW("EGL_KHR_no_config_context not supported");
|
|
||||||
EGLint count;
|
|
||||||
EGLint config_attribs[] = {
|
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
||||||
EGL_RED_SIZE, 1,
|
|
||||||
EGL_GREEN_SIZE, 1,
|
|
||||||
EGL_BLUE_SIZE, 1,
|
|
||||||
EGL_ALPHA_SIZE, 1,
|
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
EGLBoolean ret = eglChooseConfig(display_, config_attribs, &conf_, 1, &count);
|
|
||||||
if (!(ret && count >= 1)) {
|
|
||||||
BLOGE("Failed to eglChooseConfig");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError EglManager::EglFuncInit()
|
|
||||||
{
|
|
||||||
const char *eglExtensions = eglQueryString(display_, EGL_EXTENSIONS);
|
|
||||||
if (eglExtensions == nullptr) {
|
|
||||||
BLOGE("param eglExtensions is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
createImage_ = (EglCreateImageFunc)eglGetProcAddress(EGL_CREATE_IMAGE_KHR);
|
|
||||||
if (createImage_ == nullptr) {
|
|
||||||
BLOGE("param createImage_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
destroyImage_ = (EglDestroyImageFunc)eglGetProcAddress(EGL_DESTROY_IMAGE_KHR);
|
|
||||||
if (destroyImage_ == nullptr) {
|
|
||||||
BLOGE("param destroyImage_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
imageTargetTexture2d_ = (EglImageTargetTexture2DFunc)eglGetProcAddress(EGL_IMAGE_TARGET_TEXTURE2DOES);
|
|
||||||
if (imageTargetTexture2d_ == nullptr) {
|
|
||||||
BLOGE("param imageTargetTexture2d_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckEglExtension(eglExtensions, EGL_KHR_FENCE_SYNC)) {
|
|
||||||
createSync_ = (EglCreateSyncFunc)eglGetProcAddress(EGL_CREATE_SYNC_KHR);
|
|
||||||
if (createSync_ == nullptr) {
|
|
||||||
BLOGE("param createSync_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
destroySync_ = (EglDestroySyncFunc)eglGetProcAddress(EGL_DESTROY_SYNC_KHR);
|
|
||||||
if (destroySync_ == nullptr) {
|
|
||||||
BLOGE("param destroySync_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
clientWaitSync_ = (EglClientWaitSyncFunc)eglGetProcAddress(EGL_CLIENT_WAIT_SYNC_KHR);
|
|
||||||
if (clientWaitSync_ == nullptr) {
|
|
||||||
BLOGE("param clientWaitSync_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dupNativeFenceFd_ = (EglDupNativeFenceFdFunc)eglGetProcAddress(EGL_DUP_NATIVE_FENCE_FD_ANDROID);
|
|
||||||
if (dupNativeFenceFd_ == nullptr) {
|
|
||||||
BLOGE("param dupNativeFenceFd_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckEglExtension(eglExtensions, EGL_KHR_WAIT_SYNC)) {
|
|
||||||
waitSync_ = (EglWaitSyncFunc)eglGetProcAddress(EGL_WAIT_SYNC_KHR);
|
|
||||||
if (waitSync_ == nullptr) {
|
|
||||||
BLOGE("param waitSync_ is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError EglManager::EglInit(EGLContext ctx)
|
|
||||||
{
|
|
||||||
ScopedBytrace func(__func__);
|
|
||||||
display_ = GetPlatformEglDisplay(EGL_PLATFORM_GBM_KHR, device_, NULL);
|
|
||||||
if (display_ == EGL_NO_DISPLAY) {
|
|
||||||
BLOGE("Failed to create EGLDisplay");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint major, minor;
|
|
||||||
if (eglInitialize(display_, &major, &minor) == EGL_FALSE) {
|
|
||||||
BLOGE("Failed to initialize EGLDisplay");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
|
||||||
BLOGE("Failed to bind OpenGL ES API");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EglCheckExt() != GSERROR_OK) {
|
|
||||||
BLOGE("EglCheckExt failed");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const EGLint context_attribs[] = {
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ctx == EGL_NO_CONTEXT) {
|
|
||||||
context_ = eglCreateContext(display_, conf_, EGL_NO_CONTEXT, context_attribs);
|
|
||||||
if (context_ == EGL_NO_CONTEXT) {
|
|
||||||
BLOGE("Failed to create EGLContext");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
ctxReleaseFlg_ = true;
|
|
||||||
} else {
|
|
||||||
context_ = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_);
|
|
||||||
|
|
||||||
const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
|
|
||||||
if (glExtensions == nullptr) {
|
|
||||||
BLOGE("param glExtensions is nullptr.");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CheckEglExtension(glExtensions, GL_OES_EGL_IMAGE)) {
|
|
||||||
BLOGE("GL_OES_EGL_image not supported");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EglFuncInit() != GSERROR_OK) {
|
|
||||||
BLOGE("EglFuncInit failed");
|
|
||||||
return GSERROR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EglManager::Deinit()
|
|
||||||
{
|
|
||||||
initFlag_ = false;
|
|
||||||
|
|
||||||
if (drmFd_ >= 0) {
|
|
||||||
close(drmFd_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context_ != EGL_NO_CONTEXT && ctxReleaseFlg_) {
|
|
||||||
eglDestroyContext(display_, context_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (display_ != EGL_NO_DISPLAY) {
|
|
||||||
eglTerminate(display_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLDisplay EglManager::GetEGLDisplay() const
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_NO_DISPLAY;
|
|
||||||
}
|
|
||||||
return display_;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLContext EglManager::GetEGLContext() const
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_NO_CONTEXT;
|
|
||||||
}
|
|
||||||
return context_;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLImageKHR EglManager::EglCreateImage(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attribList)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_NO_IMAGE;
|
|
||||||
}
|
|
||||||
return createImage_(display_, ctx, target, buffer, attribList);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLImageKHR EglManager::EglCreateImage(EGLenum target, EGLClientBuffer buffer, const EGLint *attribList)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_NO_IMAGE;
|
|
||||||
}
|
|
||||||
return createImage_(display_, context_, target, buffer, attribList);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean EglManager::EglDestroyImage(EGLImageKHR image)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return destroyImage_(display_, image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EglManager::EglImageTargetTexture2D(GLenum target, GLeglImageOES image)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return imageTargetTexture2d_(target, image);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLSyncKHR EglManager::EglCreateSync(EGLenum type, const EGLint *attribList)
|
|
||||||
{
|
|
||||||
if (createSync_ == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return EGL_NO_SYNC_KHR;
|
|
||||||
}
|
|
||||||
return createSync_(display_, type, attribList);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint EglManager::EglWaitSync(EGLSyncKHR sync, EGLint flags)
|
|
||||||
{
|
|
||||||
if (waitSync_ == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return waitSync_(display_, sync, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint EglManager::EglClientWaitSync(EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout)
|
|
||||||
{
|
|
||||||
if (clientWaitSync_ == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return clientWaitSync_(display_, sync, flags, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean EglManager::EglDestroySync(EGLSyncKHR sync)
|
|
||||||
{
|
|
||||||
if (destroySync_ == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return destroySync_(display_, sync);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint EglManager::EglDupNativeFenceFd(EGLSyncKHR sync)
|
|
||||||
{
|
|
||||||
if (dupNativeFenceFd_ == nullptr) {
|
|
||||||
BLOGE("param is nullptr.");
|
|
||||||
return EGL_DONT_CARE;
|
|
||||||
}
|
|
||||||
return dupNativeFenceFd_(display_, sync);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean EglManager::EglMakeCurrent()
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean EglManager::EglMakeCurrent(EGLSurface draw, EGLSurface read)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return eglMakeCurrent(display_, draw, read, context_);
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean EglManager::EglMakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx)
|
|
||||||
{
|
|
||||||
if (!initFlag_) {
|
|
||||||
BLOGE("EglManager is not init.");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
return eglMakeCurrent(display_, draw, read, ctx);
|
|
||||||
}
|
|
||||||
} // namespace OHOS
|
|
@ -20,8 +20,6 @@
|
|||||||
#include <scoped_bytrace.h>
|
#include <scoped_bytrace.h>
|
||||||
|
|
||||||
#include "buffer_log.h"
|
#include "buffer_log.h"
|
||||||
#include "buffer_manager.h"
|
|
||||||
#include "egl_data_impl.h"
|
|
||||||
#include "buffer_extra_data_impl.h"
|
#include "buffer_extra_data_impl.h"
|
||||||
#include "sync_fence.h"
|
#include "sync_fence.h"
|
||||||
|
|
||||||
|
@ -67,92 +67,4 @@ ohos_shared_library("libvsync_client") {
|
|||||||
part_name = "graphic_standard"
|
part_name = "graphic_standard"
|
||||||
subsystem_name = "graphic"
|
subsystem_name = "graphic"
|
||||||
}
|
}
|
||||||
|
|
||||||
## Build libvsync_client.so }}}
|
## Build libvsync_client.so }}}
|
||||||
|
|
||||||
## Build libvsync_module.z.so {{{
|
|
||||||
config("libvsync_module_config") {
|
|
||||||
visibility = [ ":*" ]
|
|
||||||
|
|
||||||
include_dirs = [
|
|
||||||
"include",
|
|
||||||
"//utils/system/safwk/native/include",
|
|
||||||
]
|
|
||||||
|
|
||||||
cflags = [
|
|
||||||
"-Wall",
|
|
||||||
"-Werror",
|
|
||||||
"-g3",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
config("libvsync_module_public_config") {
|
|
||||||
include_dirs = [
|
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
ohos_shared_library("libvsync_module") {
|
|
||||||
sources = [
|
|
||||||
"src/drm_module.cpp",
|
|
||||||
"src/return_value_tester.cpp",
|
|
||||||
"src/vsync_callback_death_recipient.cpp",
|
|
||||||
"src/vsync_callback_proxy.cpp",
|
|
||||||
"src/vsync_manager.cpp",
|
|
||||||
"src/vsync_module.cpp",
|
|
||||||
"src/vsync_module_c.cpp",
|
|
||||||
"src/vsync_module_impl.cpp",
|
|
||||||
]
|
|
||||||
|
|
||||||
configs = [ ":libvsync_module_config" ]
|
|
||||||
|
|
||||||
public_configs = [ ":libvsync_module_public_config" ]
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
|
||||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
|
||||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
|
||||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
|
||||||
"//third_party/libdrm:libdrm",
|
|
||||||
]
|
|
||||||
|
|
||||||
public_deps = [
|
|
||||||
"//commonlibrary/c_utils/base:utils",
|
|
||||||
"//foundation/graphic/graphic_2d/utils:semaphore",
|
|
||||||
]
|
|
||||||
|
|
||||||
part_name = "graphic_standard"
|
|
||||||
subsystem_name = "graphic"
|
|
||||||
}
|
|
||||||
|
|
||||||
## Build libvsync_module.z.so }}}
|
|
||||||
|
|
||||||
## Build vsync_server {{{
|
|
||||||
ohos_executable("vsync_server") {
|
|
||||||
install_enable = false
|
|
||||||
|
|
||||||
sources = [ "src/module_main.cpp" ]
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
":libvsync_module",
|
|
||||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
part_name = "graphic_standard"
|
|
||||||
subsystem_name = "graphic"
|
|
||||||
}
|
|
||||||
|
|
||||||
## Build vsync_server }}}
|
|
||||||
|
|
||||||
## Build vsync_test {{{
|
|
||||||
ohos_executable("vsync_test") {
|
|
||||||
install_enable = false
|
|
||||||
|
|
||||||
sources = [ "test/nativetest/main.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":libvsync_client" ]
|
|
||||||
|
|
||||||
part_name = "graphic_standard"
|
|
||||||
subsystem_name = "graphic"
|
|
||||||
}
|
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_INCLUDE_DRM_MODULE_H
|
|
||||||
#define FRAMEWORKS_VSYNC_INCLUDE_DRM_MODULE_H
|
|
||||||
|
|
||||||
#include <refbase.h>
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
#include <xf86drm.h>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class DrmModule : public RefBase {
|
|
||||||
public:
|
|
||||||
static sptr<DrmModule> GetInstance();
|
|
||||||
static void SetInstance(sptr<DrmModule>& mockInstance);
|
|
||||||
|
|
||||||
virtual sptr<ISystemAbilityManager> GetSystemAbilityManager();
|
|
||||||
virtual sptr<IRemoteObject> GetSystemAbility(sptr<ISystemAbilityManager>& sm, int32_t systemAbilityId);
|
|
||||||
virtual int DrmOpen(std::string name, std::string busid);
|
|
||||||
virtual int DrmClose(int32_t drmFd_);
|
|
||||||
virtual int DrmWaitBlank(int32_t drmFd, drmVBlank vblank);
|
|
||||||
|
|
||||||
private:
|
|
||||||
DrmModule() = default;
|
|
||||||
virtual ~DrmModule() = default;
|
|
||||||
static inline sptr<DrmModule> instance = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_INCLUDE_DRM_MODULE_H
|
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_DEATH_RECIPIENT_H
|
|
||||||
#define FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_DEATH_RECIPIENT_H
|
|
||||||
|
|
||||||
#include <iremote_object.h>
|
|
||||||
|
|
||||||
#include "vsync_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class VsyncCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
|
|
||||||
public:
|
|
||||||
VsyncCallbackDeathRecipient(VsyncManager *vm);
|
|
||||||
virtual ~VsyncCallbackDeathRecipient() = default;
|
|
||||||
|
|
||||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
VsyncManager *manager = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_DEATH_RECIPIENT_H
|
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_PROXY_H
|
|
||||||
#define FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_PROXY_H
|
|
||||||
|
|
||||||
#include <iremote_proxy.h>
|
|
||||||
|
|
||||||
#include "ivsync_callback.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class VsyncCallbackProxy : public IRemoteProxy<IVsyncCallback> {
|
|
||||||
public:
|
|
||||||
VsyncCallbackProxy(const sptr<IRemoteObject>& impl);
|
|
||||||
virtual ~VsyncCallbackProxy() = default;
|
|
||||||
|
|
||||||
GSError OnVsync(int64_t timestamp) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline BrokerDelegator<VsyncCallbackProxy> delegator_;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_INCLUDE_VSYNC_CALLBACK_PROXY_H
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MANAGER_H
|
|
||||||
#define FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MANAGER_H
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include <iremote_stub.h>
|
|
||||||
#include <message_parcel.h>
|
|
||||||
#include <message_option.h>
|
|
||||||
|
|
||||||
#include "ivsync_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class VsyncCallbackDeathRecipient;
|
|
||||||
class VsyncManager : public IRemoteStub<IVsyncManager> {
|
|
||||||
friend class VsyncCallbackDeathRecipient;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data,
|
|
||||||
MessageParcel &reply, MessageOption &option) override;
|
|
||||||
|
|
||||||
virtual GSError ListenVsync(sptr<IVsyncCallback>& cb, int32_t &cbid) override;
|
|
||||||
virtual GSError RemoveVsync(int32_t cbid) override;
|
|
||||||
virtual GSError GetVsyncFrequency(uint32_t &freq) override;
|
|
||||||
|
|
||||||
virtual void Callback(int64_t timestamp);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<int32_t, sptr<IVsyncCallback>> callbacks_;
|
|
||||||
std::mutex callbacksMutex_;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MANAGER_H
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MODULE_IMPL_H
|
|
||||||
#define FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MODULE_IMPL_H
|
|
||||||
|
|
||||||
#include <queue>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include <local_semaphore.h>
|
|
||||||
#include <vsync_module.h>
|
|
||||||
|
|
||||||
#include "drm_module.h"
|
|
||||||
#include "vsync_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class VsyncModuleImpl : public VsyncModule {
|
|
||||||
public:
|
|
||||||
static sptr<VsyncModuleImpl> GetInstance();
|
|
||||||
|
|
||||||
virtual GSError Start() override;
|
|
||||||
virtual GSError Trigger() override;
|
|
||||||
virtual GSError Stop() override;
|
|
||||||
virtual bool IsRunning() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual GSError InitSA();
|
|
||||||
GSError InitSA(int32_t vsyncSystemAbilityId);
|
|
||||||
|
|
||||||
private:
|
|
||||||
VsyncModuleImpl() = default;
|
|
||||||
virtual ~VsyncModuleImpl() override;
|
|
||||||
static inline sptr<VsyncModuleImpl> instance = nullptr;
|
|
||||||
|
|
||||||
int64_t WaitNextVsync();
|
|
||||||
void VsyncMainThread();
|
|
||||||
bool RegisterSystemAbility();
|
|
||||||
void UnregisterSystemAbility();
|
|
||||||
|
|
||||||
LocalSemaphore promisesSem_;
|
|
||||||
std::mutex promisesMutex_;
|
|
||||||
std::queue<int64_t> promises_;
|
|
||||||
std::unique_ptr<std::thread> vsyncThread_ = nullptr;
|
|
||||||
bool vsyncThreadRunning_ = false;
|
|
||||||
int32_t vsyncSystemAbilityId_ = 0;
|
|
||||||
bool isRegisterSA_ = false;
|
|
||||||
VsyncManager vsyncManager_;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_INCLUDE_VSYNC_MODULE_IMPL_H
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "drm_module.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
sptr<DrmModule> DrmModule::GetInstance()
|
|
||||||
{
|
|
||||||
if (instance == nullptr) {
|
|
||||||
static std::mutex mutex;
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
|
||||||
if (instance == nullptr) {
|
|
||||||
instance = new DrmModule();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmModule::SetInstance(sptr<DrmModule> &mockInstance)
|
|
||||||
{
|
|
||||||
instance = mockInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<ISystemAbilityManager> DrmModule::GetSystemAbilityManager()
|
|
||||||
{
|
|
||||||
return SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<IRemoteObject> DrmModule::GetSystemAbility(sptr<ISystemAbilityManager>& sm, int32_t systemAbilityId)
|
|
||||||
{
|
|
||||||
return sm->GetSystemAbility(systemAbilityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
int DrmModule::DrmOpen(std::string name, std::string busid)
|
|
||||||
{
|
|
||||||
return drmOpen(name.data(), busid.data());
|
|
||||||
}
|
|
||||||
int DrmModule::DrmClose(int32_t drmFd_)
|
|
||||||
{
|
|
||||||
return drmClose(drmFd_);
|
|
||||||
}
|
|
||||||
int DrmModule::DrmWaitBlank(int32_t drmFd, drmVBlank vblank)
|
|
||||||
{
|
|
||||||
return drmWaitVBlank(drmFd, &vblank);
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ipc_skeleton.h>
|
|
||||||
#include <vsync_module.h>
|
|
||||||
|
|
||||||
using namespace OHOS;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
auto ret = VsyncModule::GetInstance()->Start();
|
|
||||||
if (ret != 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPCSkeleton::JoinWorkThread();
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_callback_death_recipient.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
VsyncCallbackDeathRecipient::VsyncCallbackDeathRecipient(VsyncManager *vm)
|
|
||||||
{
|
|
||||||
manager = vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(manager->callbacksMutex_);
|
|
||||||
for (auto it = manager->callbacks_.begin(); it != manager->callbacks_.end(); it++) {
|
|
||||||
if (it->second->AsObject() == remote.promote()) {
|
|
||||||
manager->callbacks_.erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_callback_proxy.h"
|
|
||||||
|
|
||||||
#include "return_value_tester.h"
|
|
||||||
#include "vsync_log.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
namespace {
|
|
||||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "VsyncCallbackProxy" };
|
|
||||||
}
|
|
||||||
|
|
||||||
VsyncCallbackProxy::VsyncCallbackProxy(const sptr<IRemoteObject>& impl)
|
|
||||||
: IRemoteProxy<IVsyncCallback>(impl)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncCallbackProxy::OnVsync(int64_t timestamp)
|
|
||||||
{
|
|
||||||
MessageOption opt(MessageOption::TF_ASYNC);
|
|
||||||
MessageParcel arg;
|
|
||||||
MessageParcel ret;
|
|
||||||
|
|
||||||
auto reval = arg.WriteInterfaceToken(GetDescriptor());
|
|
||||||
if (!ReturnValueTester::Get<bool>(reval)) {
|
|
||||||
VLOGE("write interface token failed");
|
|
||||||
return GSERROR_INVALID_ARGUMENTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool retval = arg.WriteInt64(timestamp);
|
|
||||||
if (!ReturnValueTester::Get<bool>(retval)) {
|
|
||||||
VLOGE("arg.WriteInt64 failed");
|
|
||||||
return GSERROR_INVALID_ARGUMENTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int res = Remote()->SendRequest(IVSYNC_CALLBACK_ON_VSYNC, arg, ret, opt);
|
|
||||||
if (ReturnValueTester::Get<int>(res)) {
|
|
||||||
VLOG_ERROR_API(res, SendRequest);
|
|
||||||
return GSERROR_BINDER;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError err = (GSError)ReturnValueTester::Get<int>(GSERROR_OK);
|
|
||||||
if (err != GSERROR_OK) {
|
|
||||||
VLOG_FAILURE_NO(err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,134 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_manager.h"
|
|
||||||
|
|
||||||
#include <scoped_bytrace.h>
|
|
||||||
|
|
||||||
#include "vsync_callback_death_recipient.h"
|
|
||||||
#include "vsync_callback_proxy.h"
|
|
||||||
#include "vsync_log.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
namespace {
|
|
||||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "VsyncManager" };
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t VsyncManager::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
|
||||||
MessageParcel &reply, MessageOption &option)
|
|
||||||
{
|
|
||||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
|
||||||
if (GetDescriptor() != remoteDescriptor) {
|
|
||||||
VLOG_FAILURE("descriptor is invalid");
|
|
||||||
return ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (code) {
|
|
||||||
case IVSYNC_MANAGER_LISTEN_VSYNC: {
|
|
||||||
auto remoteObject = data.ReadRemoteObject();
|
|
||||||
if (remoteObject == nullptr) {
|
|
||||||
reply.WriteInt32(GSERROR_INVALID_ARGUMENTS);
|
|
||||||
VLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto cb = iface_cast<IVsyncCallback>(remoteObject);
|
|
||||||
int32_t cbid = -1;
|
|
||||||
GSError ret = ListenVsync(cb, cbid);
|
|
||||||
reply.WriteInt32(cbid);
|
|
||||||
reply.WriteInt32(ret);
|
|
||||||
if (ret != GSERROR_OK) {
|
|
||||||
VLOG_FAILURE_NO(ret);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IVSYNC_MANAGER_REMOVE_VSYNC: {
|
|
||||||
auto cbid = data.ReadInt32();
|
|
||||||
auto ret = RemoveVsync(cbid);
|
|
||||||
reply.WriteInt32(ret);
|
|
||||||
if (ret != GSERROR_OK) {
|
|
||||||
VLOG_FAILURE_NO(ret);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IVSYNC_MANAGER_GET_VSYNC_FREQUENCY: {
|
|
||||||
uint32_t freq = 0;
|
|
||||||
GSError ret = GetVsyncFrequency(freq);
|
|
||||||
reply.WriteInt32(ret);
|
|
||||||
reply.WriteUint32(freq);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
VLOG_FAILURE("code %{public}d cannot process", code);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncManager::ListenVsync(sptr<IVsyncCallback>& cb, int32_t &cbid)
|
|
||||||
{
|
|
||||||
if (cb == nullptr) {
|
|
||||||
VLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
|
||||||
return GSERROR_INVALID_ARGUMENTS;
|
|
||||||
}
|
|
||||||
VLOGI("add callbacks %{public}d", GetCallingPid());
|
|
||||||
|
|
||||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = new VsyncCallbackDeathRecipient(this);
|
|
||||||
if (cb->AsObject()->AddDeathRecipient(deathRecipient) == false) {
|
|
||||||
VLOGW("Failed to add death recipient");
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedBytrace bytrace(__func__);
|
|
||||||
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
||||||
static int32_t callbackID = 0;
|
|
||||||
cbid = callbackID++;
|
|
||||||
callbacks_[cbid] = cb;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncManager::RemoveVsync(int32_t cbid)
|
|
||||||
{
|
|
||||||
ScopedBytrace bytrace(__func__);
|
|
||||||
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
||||||
callbacks_.erase(cbid);
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncManager::GetVsyncFrequency(uint32_t &freq)
|
|
||||||
{
|
|
||||||
constexpr uint32_t defaultVsyncFrequency = 60;
|
|
||||||
freq = defaultVsyncFrequency;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManager::Callback(int64_t timestamp)
|
|
||||||
{
|
|
||||||
ScopedBytrace bytrace("callback");
|
|
||||||
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
||||||
std::vector<int> ids;
|
|
||||||
for (const auto &[id, cb] : callbacks_) {
|
|
||||||
if (cb->OnVsync(timestamp) == GSERROR_BINDER) {
|
|
||||||
ids.push_back(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto id : ids) {
|
|
||||||
callbacks_.erase(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <vsync_module.h>
|
|
||||||
|
|
||||||
#include "vsync_module_impl.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
sptr<VsyncModule> VsyncModule::GetInstance()
|
|
||||||
{
|
|
||||||
return Vsync::VsyncModuleImpl::GetInstance();
|
|
||||||
}
|
|
||||||
} // namespace OHOS
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <vsync_module.h>
|
|
||||||
|
|
||||||
#include "vsync_module_c.h"
|
|
||||||
|
|
||||||
using namespace OHOS;
|
|
||||||
|
|
||||||
int VsyncModuleStart(void)
|
|
||||||
{
|
|
||||||
return VsyncModule::GetInstance()->Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
int VsyncModuleStop(void)
|
|
||||||
{
|
|
||||||
return VsyncModule::GetInstance()->Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
int VsyncModuleTrigger(void)
|
|
||||||
{
|
|
||||||
return VsyncModule::GetInstance()->Trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
int VsyncModuleIsRunning(void)
|
|
||||||
{
|
|
||||||
return VsyncModule::GetInstance()->IsRunning() ? 1 : 0;
|
|
||||||
}
|
|
@ -1,185 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <scoped_bytrace.h>
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
#include <system_ability_definition.h>
|
|
||||||
|
|
||||||
#include "vsync_log.h"
|
|
||||||
#include "vsync_module_impl.h"
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
namespace {
|
|
||||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "VsyncModuleImpl" };
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<VsyncModuleImpl> VsyncModuleImpl::GetInstance()
|
|
||||||
{
|
|
||||||
if (instance == nullptr) {
|
|
||||||
static std::mutex mutex;
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
|
||||||
if (instance == nullptr) {
|
|
||||||
instance = new VsyncModuleImpl();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncModuleImpl::Start()
|
|
||||||
{
|
|
||||||
VLOGI("Start");
|
|
||||||
GSError ret = InitSA();
|
|
||||||
if (ret != GSERROR_OK) {
|
|
||||||
VLOG_FAILURE("Start");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
vsyncThreadRunning_ = true;
|
|
||||||
vsyncThread_ = std::make_unique<std::thread>(std::bind(&VsyncModuleImpl::VsyncMainThread, this));
|
|
||||||
VLOG_SUCCESS("Start");
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncModuleImpl::Trigger()
|
|
||||||
{
|
|
||||||
if (IsRunning() == false) {
|
|
||||||
VLOG_FAILURE("Trigger");
|
|
||||||
return GSERROR_INVALID_OPERATING;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t occurTimestamp = std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(promisesMutex_);
|
|
||||||
constexpr int32_t overwriteTop = 10;
|
|
||||||
if (promises_.size() < overwriteTop) {
|
|
||||||
promisesSem_.Inc();
|
|
||||||
} else {
|
|
||||||
promises_.pop();
|
|
||||||
}
|
|
||||||
promises_.push(occurTimestamp);
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncModuleImpl::Stop()
|
|
||||||
{
|
|
||||||
VLOGI("Stop");
|
|
||||||
if (vsyncThreadRunning_ == false) {
|
|
||||||
VLOG_FAILURE_RET(GSERROR_INVALID_OPERATING);
|
|
||||||
}
|
|
||||||
|
|
||||||
vsyncThreadRunning_ = false;
|
|
||||||
vsyncThread_->join();
|
|
||||||
vsyncThread_.reset();
|
|
||||||
|
|
||||||
if (isRegisterSA_ == true) {
|
|
||||||
UnregisterSystemAbility();
|
|
||||||
}
|
|
||||||
VLOG_SUCCESS("Stop");
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VsyncModuleImpl::IsRunning()
|
|
||||||
{
|
|
||||||
return vsyncThreadRunning_;
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncModuleImpl::InitSA()
|
|
||||||
{
|
|
||||||
return InitSA(VSYNC_MANAGER_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncModuleImpl::InitSA(int32_t vsyncSystemAbilityId)
|
|
||||||
{
|
|
||||||
vsyncSystemAbilityId_ = vsyncSystemAbilityId;
|
|
||||||
|
|
||||||
int tryCount = 0;
|
|
||||||
while (!RegisterSystemAbility()) {
|
|
||||||
constexpr int retryTimes = 5;
|
|
||||||
if (tryCount++ >= retryTimes) {
|
|
||||||
VLOGE("RegisterSystemAbility failed after %{public}d tries!!!", retryTimes);
|
|
||||||
return GSERROR_SERVER_ERROR;
|
|
||||||
} else {
|
|
||||||
VLOGE("RegisterSystemAbility failed, try again:%{public}d", tryCount);
|
|
||||||
std::this_thread::sleep_for(100ms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
VsyncModuleImpl::~VsyncModuleImpl()
|
|
||||||
{
|
|
||||||
VLOGI("~VsyncModuleImpl");
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t VsyncModuleImpl::WaitNextVsync()
|
|
||||||
{
|
|
||||||
promisesSem_.Dec();
|
|
||||||
std::lock_guard<std::mutex> lock(promisesMutex_);
|
|
||||||
const auto &ret = promises_.front();
|
|
||||||
promises_.pop();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncModuleImpl::VsyncMainThread()
|
|
||||||
{
|
|
||||||
while (IsRunning()) {
|
|
||||||
int64_t timestamp = WaitNextVsync();
|
|
||||||
if (timestamp < 0) {
|
|
||||||
VLOGE("WaitNextVsync return negative time");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ScopedBytrace vsyncSending("VsyncSending");
|
|
||||||
vsyncManager_.Callback(timestamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VsyncModuleImpl::RegisterSystemAbility()
|
|
||||||
{
|
|
||||||
if (isRegisterSA_ == true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auto sam = DrmModule::GetInstance()->GetSystemAbilityManager();
|
|
||||||
if (sam) {
|
|
||||||
if (sam->AddSystemAbility(vsyncSystemAbilityId_, &vsyncManager_) != ERR_OK) {
|
|
||||||
VLOGW("AddSystemAbility failed");
|
|
||||||
} else {
|
|
||||||
isRegisterSA_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isRegisterSA_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncModuleImpl::UnregisterSystemAbility()
|
|
||||||
{
|
|
||||||
auto sam = DrmModule::GetInstance()->GetSystemAbilityManager();
|
|
||||||
if (sam) {
|
|
||||||
sam->RemoveSystemAbility(vsyncSystemAbilityId_);
|
|
||||||
isRegisterSA_ = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,18 +0,0 @@
|
|||||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
group("test") {
|
|
||||||
testonly = true
|
|
||||||
|
|
||||||
deps = [ "unittest:unittest" ]
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
import("//build/test.gni")
|
|
||||||
|
|
||||||
module_out_path = "graphic_standard/vsync"
|
|
||||||
|
|
||||||
group("unittest") {
|
|
||||||
testonly = true
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
":vsync_helper_impl_test",
|
|
||||||
":vsync_remote_callback_stub_test",
|
|
||||||
":vsync_remote_callback_test",
|
|
||||||
":vsync_remote_manager_proxy_test",
|
|
||||||
":vsync_remote_manager_stub_test",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_helper_impl_test {{{
|
|
||||||
ohos_unittest("vsync_helper_impl_test") {
|
|
||||||
module_out_path = module_out_path
|
|
||||||
|
|
||||||
sources = [ "vsync_helper_impl_test.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":vsync_test_common" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_helper_impl_test }}}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_callback_stub_test {{{
|
|
||||||
ohos_unittest("vsync_remote_callback_stub_test") {
|
|
||||||
module_out_path = module_out_path
|
|
||||||
|
|
||||||
sources = [ "vsync_remote_callback_stub_test.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":vsync_test_common" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_callback_stub_test }}}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_callback_test {{{
|
|
||||||
ohos_unittest("vsync_remote_callback_test") {
|
|
||||||
module_out_path = module_out_path
|
|
||||||
|
|
||||||
sources = [ "vsync_remote_callback_test.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":vsync_test_common" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_callback_test }}}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_manager_proxy_test {{{
|
|
||||||
ohos_unittest("vsync_remote_manager_proxy_test") {
|
|
||||||
module_out_path = module_out_path
|
|
||||||
|
|
||||||
sources = [ "vsync_remote_manager_proxy_test.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":vsync_test_common" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_manager_proxy_test }}}
|
|
||||||
|
|
||||||
## UnitTest vsync_remote_manager_stub_test {{{
|
|
||||||
ohos_unittest("vsync_remote_manager_stub_test") {
|
|
||||||
module_out_path = module_out_path
|
|
||||||
|
|
||||||
sources = [ "vsync_remote_manager_stub_test.cpp" ]
|
|
||||||
|
|
||||||
deps = [ ":vsync_test_common" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
## UnitTest vsync_helper_impl_test }}}
|
|
||||||
|
|
||||||
## Build vsync_test_common.a {{{
|
|
||||||
config("vsync_test_common_public_config") {
|
|
||||||
include_dirs = [
|
|
||||||
"../../include",
|
|
||||||
"//utils/system/safwk/native/include",
|
|
||||||
"//commonlibrary/c_utils/base/include",
|
|
||||||
]
|
|
||||||
|
|
||||||
cflags = [
|
|
||||||
"-Wall",
|
|
||||||
"-Werror",
|
|
||||||
"-g3",
|
|
||||||
"-Dprivate=public",
|
|
||||||
"-Dprotected=public",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
ohos_static_library("vsync_test_common") {
|
|
||||||
testonly = true
|
|
||||||
|
|
||||||
visibility = [ ":*" ]
|
|
||||||
|
|
||||||
public_configs = [ ":vsync_test_common_public_config" ]
|
|
||||||
|
|
||||||
public_deps = [
|
|
||||||
"../..:libvsync_client",
|
|
||||||
"../..:libvsync_module",
|
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
|
||||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
|
||||||
"//commonlibrary/c_utils/base:utils",
|
|
||||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
|
||||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
|
||||||
"//third_party/googletest:gmock",
|
|
||||||
"//third_party/libdrm:libdrm",
|
|
||||||
]
|
|
||||||
subsystem_name = "graphic"
|
|
||||||
part_name = "graphic_standard"
|
|
||||||
}
|
|
||||||
## Build vsync_test_common.a }}}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_DRM_MODULE_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_DRM_MODULE_H
|
|
||||||
|
|
||||||
#include "drm_module.h"
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class MockDrmModule : public DrmModule {
|
|
||||||
public:
|
|
||||||
MOCK_METHOD0(GetSystemAbilityManager, sptr<ISystemAbilityManager>());
|
|
||||||
MOCK_METHOD2(GetSystemAbility, sptr<IRemoteObject>(sptr<ISystemAbilityManager>& sm, int32_t systemAbilityId));
|
|
||||||
MOCK_METHOD2(DrmOpen, int(std::string name, std::string busid));
|
|
||||||
MOCK_METHOD1(DrmClose, int(int32_t drmFd_));
|
|
||||||
MOCK_METHOD2(DrmWaitBlank, int(int32_t drmFd, drmVBlank vblank));
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_DRM_MODULE_H
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_STATIC_CALL_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_STATIC_CALL_H
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
|
||||||
|
|
||||||
#include "static_call.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class MockStaticCall : public StaticCall {
|
|
||||||
public:
|
|
||||||
MOCK_METHOD0(GetSystemAbilityManager, sptr<ISystemAbilityManager>());
|
|
||||||
MOCK_METHOD2(GetSystemAbility, sptr<IRemoteObject>(sptr<ISystemAbilityManager>& sm, int32_t systemAbilityId));
|
|
||||||
MOCK_METHOD1(GetCast, sptr<IVsyncManager>(sptr<IRemoteObject>& remoteObject));
|
|
||||||
MOCK_METHOD2(GetVsyncFrequency, GSError(sptr<IVsyncManager>& server, uint32_t &freq));
|
|
||||||
MOCK_METHOD3(ListenVsync, GSError(sptr<IVsyncManager>& server, sptr<IVsyncCallback>& cb, int32_t &cbid));
|
|
||||||
MOCK_METHOD0(Current, std::shared_ptr<AppExecFwk::EventHandler>());
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_MOCK_MOCK_STATIC_CALL_H
|
|
@ -1,176 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_helper_impl_test.h"
|
|
||||||
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
#include <system_ability_definition.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "mock/mock_static_call.h"
|
|
||||||
#include "vsync_helper_impl.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
void VsyncHelperImplTest::SetUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncHelperImplTest::TearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncHelperImplTest::SetUpTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncHelperImplTest::TearDownTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbilityManager())
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(nullptr));
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_CONNOT_CONNECT_SAMGR);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
auto sm =SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbilityManager())
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(sm));
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbility(testing::_, testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(nullptr));
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_SERVER_ERROR);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
auto sm =SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
auto remoteObject = sm->GetSystemAbility(VSYNC_MANAGER_ID);
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbilityManager())
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(sm));
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbility(testing::_, testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(remoteObject));
|
|
||||||
EXPECT_CALL(*mockInstance, GetCast(testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(nullptr));
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_PROXY_NOT_INCLUDE);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init4, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
auto sm =SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
auto remoteObject = sm->GetSystemAbility(VSYNC_MANAGER_ID);
|
|
||||||
auto service = iface_cast<IVsyncManager>(remoteObject);
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbilityManager())
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(sm));
|
|
||||||
EXPECT_CALL(*mockInstance, GetSystemAbility(testing::_, testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(remoteObject));
|
|
||||||
EXPECT_CALL(*mockInstance, GetCast(testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(service));
|
|
||||||
EXPECT_CALL(*mockInstance, GetVsyncFrequency(testing::_, testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(GSERROR_INVALID_OPERATING));
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_OPERATING);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init5, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
auto sm =SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
auto remoteObject = sm->GetSystemAbility(VSYNC_MANAGER_ID);
|
|
||||||
auto service = iface_cast<IVsyncManager>(remoteObject);
|
|
||||||
EXPECT_CALL(*mockInstance, GetVsyncFrequency(testing::_, testing::_))
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(GSERROR_OK));
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_INTERNAL);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Init7, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
auto ret = client->Init();
|
|
||||||
ASSERT_EQ(ret, GSERROR_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, RequestFrameCallback1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
FrameCallback cb;
|
|
||||||
auto ret = client->RequestFrameCallback(cb);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, RequestFrameCallback2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
FrameCallback cb;
|
|
||||||
cb.callback_ = std::bind(&StaticCall::Sync, StaticCall::GetInstance(), SYNC_FUNC_ARG);
|
|
||||||
cb.frequency_ = 31;
|
|
||||||
auto ret = client->RequestFrameCallback(cb);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncHelperImplTest, Current, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<VsyncHelperImpl> helper =new VsyncHelperImpl(handler);
|
|
||||||
sptr<MockStaticCall> mockInstance = new MockStaticCall();
|
|
||||||
sptr<VsyncClient> client = VsyncClient::GetInstance();
|
|
||||||
sptr<StaticCall> staticCall = mockInstance;
|
|
||||||
auto origin = StaticCall::GetInstance();
|
|
||||||
StaticCall::SetInstance(staticCall);
|
|
||||||
EXPECT_CALL(*mockInstance, Current())
|
|
||||||
.Times(1).WillRepeatedly(testing::Return(nullptr));
|
|
||||||
auto ret = helper->Current();
|
|
||||||
ASSERT_EQ(ret, nullptr);
|
|
||||||
StaticCall::SetInstance(origin);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_HELPER_IMPL_TEST_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_HELPER_IMPL_TEST_H
|
|
||||||
|
|
||||||
#include <event_handler.h>
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
class VsyncHelperImplTest : public testing::Test {
|
|
||||||
public:
|
|
||||||
static void SetUpTestCase();
|
|
||||||
static void TearDownTestCase();
|
|
||||||
virtual void SetUp() override;
|
|
||||||
virtual void TearDown() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_HELPER_IMPL_TEST_H
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_remote_callback_stub_test.h"
|
|
||||||
#include "return_value_tester.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
void VsyncCallbackStubTest::SetUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackStubTest::TearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackStubTest::SetUpTestCase()
|
|
||||||
{
|
|
||||||
vc_ = new VsyncCallback();
|
|
||||||
ASSERT_NE(vc_, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackStubTest::TearDownTestCase()
|
|
||||||
{
|
|
||||||
vc_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
HWTEST_F(VsyncCallbackStubTest, OnRemoteRequest1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(u"DaDaDa");
|
|
||||||
auto ret = vc_->OnRemoteRequest(IVsyncCallback::IVSYNC_CALLBACK_ON_VSYNC, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, ERR_INVALID_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackStubTest, OnRemoteRequest2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncCallback::GetDescriptor());
|
|
||||||
auto ret = vc_->OnRemoteRequest(4, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackStubTest, OnRemoteRequest3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncCallback::GetDescriptor());
|
|
||||||
auto ret = vc_->OnRemoteRequest(IVsyncCallback::IVSYNC_CALLBACK_ON_VSYNC, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackStubTest, OnRemoteRequest4, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncCallback::GetDescriptor());
|
|
||||||
data.WriteInt64(12);
|
|
||||||
auto ret = vc_->OnRemoteRequest(IVsyncCallback::IVSYNC_CALLBACK_ON_VSYNC, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, 0);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
GSError VsyncCallback::OnVsync(int64_t timestamp)
|
|
||||||
{
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_STUB_TEST_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_STUB_TEST_H
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "ivsync_callback.h"
|
|
||||||
#include "vsync_callback_proxy.h"
|
|
||||||
#include "vsync_callback_stub.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
constexpr int32_t IPC_VSYNCCALLBACK_SAID = 564321;
|
|
||||||
class VsyncCallbackStubTest : public testing::Test {
|
|
||||||
public:
|
|
||||||
static void SetUpTestCase();
|
|
||||||
static void TearDownTestCase();
|
|
||||||
virtual void SetUp() override;
|
|
||||||
virtual void TearDown() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline pid_t pid_;
|
|
||||||
static inline int pipeFd[2];
|
|
||||||
static inline sptr<IRemoteObject> robj_;
|
|
||||||
static inline sptr<VsyncCallbackStub> vc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VsyncCallback : public VsyncCallbackStub {
|
|
||||||
public:
|
|
||||||
virtual GSError OnVsync(int64_t timestamp) override;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_STUB_TEST_H
|
|
@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_remote_callback_test.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
|
|
||||||
#include "return_value_tester.h"
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
void VsyncCallbackTest::SetUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackTest::TearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackTest::SetUpTestCase()
|
|
||||||
{
|
|
||||||
pipe(pipeFd);
|
|
||||||
|
|
||||||
pid_ = fork();
|
|
||||||
if (pid_ < 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid_ == 0) {
|
|
||||||
std::this_thread::sleep_for(50ms);
|
|
||||||
sptr<VsyncCallback> vcqp = new VsyncCallback();
|
|
||||||
ASSERT_NE(vcqp, nullptr);
|
|
||||||
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
sam->AddSystemAbility(IPC_VSYNCCALLBACK_SAID, vcqp);
|
|
||||||
char buf[10] = "start";
|
|
||||||
write(pipeFd[1], buf, sizeof(buf));
|
|
||||||
sleep(0);
|
|
||||||
|
|
||||||
read(pipeFd[0], buf, sizeof(buf));
|
|
||||||
|
|
||||||
sam->RemoveSystemAbility(IPC_VSYNCCALLBACK_SAID);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
} else {
|
|
||||||
char buf[10];
|
|
||||||
read(pipeFd[0], buf, sizeof(buf));
|
|
||||||
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
robj_ = sam->GetSystemAbility(IPC_VSYNCCALLBACK_SAID);
|
|
||||||
vc_ = iface_cast<IVsyncCallback>(robj_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncCallbackTest::TearDownTestCase()
|
|
||||||
{
|
|
||||||
robj_ = nullptr;
|
|
||||||
vc_ = nullptr;
|
|
||||||
|
|
||||||
char buf[10] = "over";
|
|
||||||
write(pipeFd[1], buf, sizeof(buf));
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
do {
|
|
||||||
waitpid(pid_, nullptr, 0);
|
|
||||||
} while (ret == -1 && errno == EINTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
HWTEST_F(VsyncCallbackTest, IsProxy, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
ASSERT_TRUE(robj_->IsProxyObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackTest, OnVsync1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t timestamp = (int64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
ReturnValueTester::Set<bool>(0, false);
|
|
||||||
auto ret = vc_->OnVsync(timestamp);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackTest, OnVsync2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t timestamp = (int64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
ReturnValueTester::Set<bool>(1, false);
|
|
||||||
auto ret = vc_->OnVsync(timestamp);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackTest, OnVsync3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t timestamp = (int64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
ReturnValueTester::Set<int>(2, GSERROR_BINDER);
|
|
||||||
auto ret = vc_->OnVsync(timestamp);
|
|
||||||
ASSERT_EQ(ret, GSERROR_BINDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncCallbackTest, OnVsync4, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t timestamp = (int64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
ReturnValueTester::Set<int>(3, GSERROR_API_FAILED);
|
|
||||||
auto ret = vc_->OnVsync(timestamp);
|
|
||||||
ASSERT_EQ(ret, GSERROR_API_FAILED);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
GSError VsyncCallback::OnVsync(int64_t timestamp)
|
|
||||||
{
|
|
||||||
(void)timestamp;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_TEST_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_TEST_H
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "vsync_callback_proxy.h"
|
|
||||||
#include "vsync_callback_stub.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
constexpr int32_t IPC_VSYNCCALLBACK_SAID = 564321;
|
|
||||||
class VsyncCallbackTest : public testing::Test {
|
|
||||||
public:
|
|
||||||
static void SetUpTestCase();
|
|
||||||
static void TearDownTestCase();
|
|
||||||
virtual void SetUp() override;
|
|
||||||
virtual void TearDown() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline pid_t pid_;
|
|
||||||
static inline int pipeFd[2];
|
|
||||||
static inline sptr<IRemoteObject> robj_;
|
|
||||||
static inline sptr<IVsyncCallback> vc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VsyncCallback : public VsyncCallbackStub {
|
|
||||||
public:
|
|
||||||
virtual GSError OnVsync(int64_t timestamp) override;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_CALLBACK_TEST_H
|
|
@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_remote_manager_proxy_test.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
|
|
||||||
#include "return_value_tester.h"
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
void VsyncManagerTest::SetUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerTest::TearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerTest::SetUpTestCase()
|
|
||||||
{
|
|
||||||
pipe(pipeFd);
|
|
||||||
|
|
||||||
pid_ = fork();
|
|
||||||
if (pid_ < 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid_ == 0) {
|
|
||||||
std::this_thread::sleep_for(50ms);
|
|
||||||
sptr<VsyncManager> vcqp = new VsyncManager();
|
|
||||||
ASSERT_NE(vcqp, nullptr);
|
|
||||||
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
sam->AddSystemAbility(IPC_VSYNCMANAGER_SAID, vcqp);
|
|
||||||
char buf[10] = "start";
|
|
||||||
write(pipeFd[1], buf, sizeof(buf));
|
|
||||||
sleep(0);
|
|
||||||
|
|
||||||
read(pipeFd[0], buf, sizeof(buf));
|
|
||||||
|
|
||||||
sam->RemoveSystemAbility(IPC_VSYNCMANAGER_SAID);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
} else {
|
|
||||||
char buf[10];
|
|
||||||
read(pipeFd[0], buf, sizeof(buf));
|
|
||||||
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
|
||||||
robj_ = sam->GetSystemAbility(IPC_VSYNCMANAGER_SAID);
|
|
||||||
vc_ = iface_cast<IVsyncManager>(robj_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerTest::TearDownTestCase()
|
|
||||||
{
|
|
||||||
robj_ = nullptr;
|
|
||||||
vc_ = nullptr;
|
|
||||||
|
|
||||||
char buf[10] = "over";
|
|
||||||
write(pipeFd[1], buf, sizeof(buf));
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
do {
|
|
||||||
waitpid(pid_, nullptr, 0);
|
|
||||||
} while (ret == -1 && errno == EINTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
HWTEST_F(VsyncManagerTest, IsProxy, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
ASSERT_TRUE(robj_->IsProxyObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, ListenVsync1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<IVsyncCallback> cb = nullptr;
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_ ->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, ListenVsync2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback();
|
|
||||||
ReturnValueTester::Set<bool>(0, false);
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_ ->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, ListenVsync3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback();
|
|
||||||
ReturnValueTester::Set<int>(1, GSERROR_BINDER);
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_ ->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_BINDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, ListenVsync4, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback();
|
|
||||||
ReturnValueTester::Set<int>(2, GSERROR_API_FAILED);
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_ ->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_API_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, GetVsyncFrequency1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
ReturnValueTester::Set<bool>(0, false);
|
|
||||||
uint32_t freq= 30;
|
|
||||||
auto ret = vc_ ->GetVsyncFrequency(freq);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, GetVsyncFrequency2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
ReturnValueTester::Set<int>(1, GSERROR_BINDER);
|
|
||||||
uint32_t freq= 30;
|
|
||||||
auto ret = vc_ ->GetVsyncFrequency(freq);
|
|
||||||
ASSERT_EQ(ret, GSERROR_BINDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerTest, GetVsyncFrequency3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
ReturnValueTester::Set<int>(2, GSERROR_API_FAILED);
|
|
||||||
uint32_t freq= 30;
|
|
||||||
auto ret = vc_ ->GetVsyncFrequency(freq);
|
|
||||||
ASSERT_EQ(ret, GSERROR_API_FAILED);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
GSError VsyncCallback::OnVsync(int64_t timestamp)
|
|
||||||
{
|
|
||||||
(void)timestamp;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_PROXY_TEST_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_PROXY_TEST_H
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "vsync_callback_stub.h"
|
|
||||||
#include "vsync_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
constexpr int32_t IPC_VSYNCMANAGER_SAID = 664321;
|
|
||||||
|
|
||||||
class VsyncManagerTest : public testing::Test {
|
|
||||||
public:
|
|
||||||
static void SetUpTestCase();
|
|
||||||
static void TearDownTestCase();
|
|
||||||
virtual void SetUp() override;
|
|
||||||
virtual void TearDown() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline pid_t pid_;
|
|
||||||
static inline int pipeFd[2];
|
|
||||||
static inline sptr<IRemoteObject> robj_;
|
|
||||||
static inline sptr<IVsyncManager> vc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VsyncCallback : public VsyncCallbackStub {
|
|
||||||
public:
|
|
||||||
virtual GSError OnVsync(int64_t timestamp) override;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_PROXY_TEST_H
|
|
@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vsync_remote_manager_stub_test.h"
|
|
||||||
|
|
||||||
#include <iservice_registry.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "return_value_tester.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
void VsyncManagerStubTest::SetUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerStubTest::TearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerStubTest::SetUpTestCase()
|
|
||||||
{
|
|
||||||
vc_ = new VsyncManager();
|
|
||||||
ASSERT_NE(vc_, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VsyncManagerStubTest::TearDownTestCase()
|
|
||||||
{
|
|
||||||
vc_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
HWTEST_F(VsyncManagerStubTest, OnRemoteRequest1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(u"DaDaDa");
|
|
||||||
auto ret = vc_->OnRemoteRequest(IVsyncManager::IVSYNC_MANAGER_LISTEN_VSYNC, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, ERR_INVALID_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, OnRemoteRequest2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncManager::GetDescriptor());
|
|
||||||
auto ret = vc_->OnRemoteRequest(3, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, OnRemoteRequest3, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncManager::GetDescriptor());
|
|
||||||
data.WriteRemoteObject(nullptr);
|
|
||||||
vc_->OnRemoteRequest(IVsyncManager::IVSYNC_MANAGER_LISTEN_VSYNC, data, reply, opt);
|
|
||||||
GSError err = (GSError)reply.ReadInt32();
|
|
||||||
ASSERT_EQ(err, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, OnRemoteRequest4, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
MessageOption opt;
|
|
||||||
MessageParcel data;
|
|
||||||
MessageParcel reply;
|
|
||||||
data.WriteInterfaceToken(IVsyncManager::GetDescriptor());
|
|
||||||
int count = 0;
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback(count);
|
|
||||||
data.WriteRemoteObject(cb->AsObject());
|
|
||||||
auto ret = vc_->OnRemoteRequest(IVsyncManager::IVSYNC_MANAGER_LISTEN_VSYNC, data, reply, opt);
|
|
||||||
ASSERT_EQ(ret, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, ListenVsync1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
sptr<IVsyncCallback> cb = nullptr;
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
|
|
||||||
vc_->RemoveVsync(cbid);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, ListenVsync2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback(count);
|
|
||||||
int32_t cbid;
|
|
||||||
auto ret = vc_->ListenVsync(cb, cbid);
|
|
||||||
ASSERT_EQ(ret, GSERROR_OK);
|
|
||||||
vc_->RemoveVsync(cbid);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, GetVsyncFrequency, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
uint32_t freq = 30;
|
|
||||||
vc_->GetVsyncFrequency(freq);
|
|
||||||
int result = static_cast<int>(freq);
|
|
||||||
ASSERT_EQ(result, 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, Callback1, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback(count);
|
|
||||||
int32_t cbid;
|
|
||||||
vc_->ListenVsync(cb, cbid);
|
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
int64_t timestamp = (int64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
|
||||||
vc_->Callback(timestamp);
|
|
||||||
ASSERT_EQ(count, 1);
|
|
||||||
vc_->RemoveVsync(cbid);
|
|
||||||
}
|
|
||||||
|
|
||||||
HWTEST_F(VsyncManagerStubTest, Callback2, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
sptr<IVsyncCallback> cb = new VsyncCallback(count);
|
|
||||||
int32_t cbid;
|
|
||||||
vc_->ListenVsync(cb, cbid);
|
|
||||||
vc_->Callback(0);
|
|
||||||
ASSERT_EQ(count, 0);
|
|
||||||
vc_->RemoveVsync(cbid);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
VsyncCallback::VsyncCallback(int &count) : count_(&count)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GSError VsyncCallback::OnVsync(int64_t timestamp)
|
|
||||||
{
|
|
||||||
if (timestamp <= 0) {
|
|
||||||
return GSERROR_BINDER;
|
|
||||||
}
|
|
||||||
*count_ = *count_ + 1;
|
|
||||||
return GSERROR_OK;
|
|
||||||
}
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_STUB_TEST_H
|
|
||||||
#define FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_STUB_TEST_H
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "vsync_callback_stub.h"
|
|
||||||
#include "vsync_manager.h"
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
namespace Vsync {
|
|
||||||
constexpr int32_t IPC_VSYNCMANAGER_SAID = 664321;
|
|
||||||
class VsyncManagerStubTest : public testing::Test {
|
|
||||||
public:
|
|
||||||
static void SetUpTestCase();
|
|
||||||
static void TearDownTestCase();
|
|
||||||
virtual void SetUp() override;
|
|
||||||
virtual void TearDown() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline sptr<VsyncManager> vc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VsyncCallback : public VsyncCallbackStub {
|
|
||||||
public:
|
|
||||||
explicit VsyncCallback(int &count);
|
|
||||||
virtual ~VsyncCallback() = default;
|
|
||||||
virtual GSError OnVsync(int64_t timestamp) override;
|
|
||||||
private:
|
|
||||||
int *count_ = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace Vsync
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // FRAMEWORKS_VSYNC_TEST_UNITTEST_VSYNC_REMOTE_MANAGER_STUB_TEST_H
|
|
@ -11,11 +11,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
service vsync_server /system/bin/vsync_server
|
|
||||||
class weston
|
|
||||||
disabled
|
|
||||||
seclabel u:r:wms_service:s0
|
|
||||||
|
|
||||||
service graphic_dumper_server /system/bin/graphic_dumper_server
|
service graphic_dumper_server /system/bin/graphic_dumper_server
|
||||||
class weston
|
class weston
|
||||||
disabled
|
disabled
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_H
|
|
||||||
#define INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_H
|
|
||||||
|
|
||||||
#include <refbase.h>
|
|
||||||
|
|
||||||
#include <graphic_common.h>
|
|
||||||
|
|
||||||
namespace OHOS {
|
|
||||||
static const char *DrmModuleNames[] = {
|
|
||||||
"hisilicon",
|
|
||||||
"sprd",
|
|
||||||
"imx-drm",
|
|
||||||
"rockchip",
|
|
||||||
};
|
|
||||||
|
|
||||||
class VsyncModule : public RefBase {
|
|
||||||
public:
|
|
||||||
static sptr<VsyncModule> GetInstance();
|
|
||||||
|
|
||||||
virtual GSError Start() = 0;
|
|
||||||
virtual GSError Trigger() = 0;
|
|
||||||
virtual GSError Stop() = 0;
|
|
||||||
virtual bool IsRunning() = 0;
|
|
||||||
};
|
|
||||||
} // namespace OHOS
|
|
||||||
|
|
||||||
#endif // INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_H
|
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_C_H
|
|
||||||
#define INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_C_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
int VsyncModuleStart(void);
|
|
||||||
int VsyncModuleTrigger(void);
|
|
||||||
int VsyncModuleStop(void);
|
|
||||||
int VsyncModuleIsRunning(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif // INTERFACES_INNERKITS_VSYNC_MODULE_VSYNC_MODULE_C_H
|
|
@ -439,7 +439,6 @@ template("flutter_engine_shell") {
|
|||||||
public_deps = [ "//foundation/graphic/graphic_2d:libgl" ]
|
public_deps = [ "//foundation/graphic/graphic_2d:libgl" ]
|
||||||
}
|
}
|
||||||
deps += [
|
deps += [
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
"//foundation/window/window_manager/wm:libwm",
|
"//foundation/window/window_manager/wm:libwm",
|
||||||
]
|
]
|
||||||
|
@ -30,7 +30,6 @@ config("composer_public_config") {
|
|||||||
include_dirs = [
|
include_dirs = [
|
||||||
"//foundation/graphic/graphic_2d/rosen/include/common",
|
"//foundation/graphic/graphic_2d/rosen/include/common",
|
||||||
"//drivers/peripheral/display/interfaces/include",
|
"//drivers/peripheral/display/interfaces/include",
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include",
|
||||||
@ -63,7 +62,6 @@ ohos_shared_library("libcomposer") {
|
|||||||
deps = [
|
deps = [
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libsurface",
|
"//foundation/graphic/graphic_2d:libsurface",
|
||||||
"//foundation/graphic/graphic_2d/frameworks/vsync:libvsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "hdi_screen.h"
|
#include "hdi_screen.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "hdi_log.h"
|
#include "hdi_log.h"
|
||||||
#include "vsync_module.h"
|
|
||||||
#include "vsync_sampler.h"
|
#include "vsync_sampler.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
@ -256,11 +255,6 @@ int32_t HdiScreen::GetSupportedMetaDataKey(std::vector<HDRMetadataKey> &keys) co
|
|||||||
|
|
||||||
void HdiScreen::Destroy()
|
void HdiScreen::Destroy()
|
||||||
{
|
{
|
||||||
// stop vsync
|
|
||||||
OHOS::VsyncError ret = VsyncModule::GetInstance()->Stop();
|
|
||||||
if (ret != OHOS::VSYNC_ERROR_OK) {
|
|
||||||
HLOGE("vsync Stop failed, ret is %{public}d", ret);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Rosen
|
} // namespace Rosen
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "refbase.h"
|
#include "refbase.h"
|
||||||
#include "rs_render_engine.h"
|
#include "rs_render_engine.h"
|
||||||
#include "vsync_distributor.h"
|
#include "vsync_distributor.h"
|
||||||
#include "vsync_helper.h"
|
#include <event_handler.h>
|
||||||
#include "vsync_receiver.h"
|
#include "vsync_receiver.h"
|
||||||
|
|
||||||
#include "command/rs_command.h"
|
#include "command/rs_command.h"
|
||||||
|
@ -77,7 +77,6 @@ ohos_source_set("rosen_ohos_sources") {
|
|||||||
public_deps = [
|
public_deps = [
|
||||||
"//commonlibrary/c_utils/base:utils",
|
"//commonlibrary/c_utils/base:utils",
|
||||||
"//foundation/graphic/graphic_2d:libsurface",
|
"//foundation/graphic/graphic_2d:libsurface",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync:libvsync",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync:libvsync",
|
||||||
"//foundation/graphic/graphic_2d/utils:sync_fence",
|
"//foundation/graphic/graphic_2d/utils:sync_fence",
|
||||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include "vsync_receiver.h"
|
#include "vsync_receiver.h"
|
||||||
|
|
||||||
#include "platform/drawing/rs_vsync_client.h"
|
#include "platform/drawing/rs_vsync_client.h"
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
|
|
||||||
#include "common/rs_thread_handler.h"
|
#include "common/rs_thread_handler.h"
|
||||||
#include "common/rs_thread_looper.h"
|
#include "common/rs_thread_looper.h"
|
||||||
|
@ -35,7 +35,6 @@ ohos_executable("render_service_client_rs_demo") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
@ -163,7 +162,6 @@ ohos_executable("surface_capture_demo") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
@ -195,7 +193,6 @@ ohos_executable("mirror_display_demo") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
@ -292,7 +289,6 @@ ohos_executable("render_service_display_mode_demo") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
|
@ -55,7 +55,6 @@ ohos_executable("drawing_engine_sample") {
|
|||||||
"drawing_engine",
|
"drawing_engine",
|
||||||
"drawing_engine/drawing_surface",
|
"drawing_engine/drawing_surface",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/utils/sync_fence/export",
|
"//foundation/graphic/graphic_2d/utils/sync_fence/export",
|
||||||
"//foundation/graphic/graphic_2d/rosen/include/common",
|
"//foundation/graphic/graphic_2d/rosen/include/common",
|
||||||
]
|
]
|
||||||
@ -75,8 +74,6 @@ ohos_executable("drawing_engine_sample") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//foundation/graphic/graphic_2d:libsurface",
|
"//foundation/graphic/graphic_2d:libsurface",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/frameworks/vsync:libvsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer:libcomposer",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer:libcomposer",
|
||||||
"//foundation/graphic/graphic_2d/utils:sync_fence",
|
"//foundation/graphic/graphic_2d/utils:sync_fence",
|
||||||
"//third_party/flutter/build/skia:ace_skia_ohos",
|
"//third_party/flutter/build/skia:ace_skia_ohos",
|
||||||
@ -110,13 +107,11 @@ ohos_executable("drawing_sample_rs") {
|
|||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client",
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/include/common",
|
"//foundation/graphic/graphic_2d/rosen/include/common",
|
||||||
"//foundation/window/window_manager/interfaces/innerkits/wm",
|
"//foundation/window/window_manager/interfaces/innerkits/wm",
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||||
@ -142,7 +137,6 @@ ohos_executable("drawing_sample_canvaskit0310") {
|
|||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
|
||||||
"//drivers/peripheral/display/interfaces/include",
|
"//drivers/peripheral/display/interfaces/include",
|
||||||
"//foundation/graphic/graphic_2d/rosen/include/common",
|
"//foundation/graphic/graphic_2d/rosen/include/common",
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/vsync_module",
|
|
||||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include",
|
||||||
@ -151,7 +145,6 @@ ohos_executable("drawing_sample_canvaskit0310") {
|
|||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//foundation/graphic/graphic_2d:libsurface",
|
"//foundation/graphic/graphic_2d:libsurface",
|
||||||
"//foundation/graphic/graphic_2d:libvsync_client",
|
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics_canvaskit0310",
|
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics_canvaskit0310",
|
||||||
"//foundation/graphic/graphic_2d/rosen/modules/composer:libcomposer",
|
"//foundation/graphic/graphic_2d/rosen/modules/composer:libcomposer",
|
||||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <vsync_generator.h>
|
#include <vsync_generator.h>
|
||||||
#include <vsync_controller.h>
|
#include <vsync_controller.h>
|
||||||
#include <vsync_distributor.h>
|
#include <vsync_distributor.h>
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include <vsync_receiver.h>
|
#include <vsync_receiver.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <sync_fence.h>
|
#include <sync_fence.h>
|
||||||
|
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include <display_type.h>
|
#include <display_type.h>
|
||||||
#include <surface.h>
|
#include <surface.h>
|
||||||
#include "hdi_backend.h"
|
#include "hdi_backend.h"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include <securec.h>
|
#include <securec.h>
|
||||||
#include <vsync_helper.h>
|
#include <event_handler.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace OHOS;
|
using namespace OHOS;
|
||||||
|
@ -30,7 +30,6 @@ config("sync_fence_public_config") {
|
|||||||
include_dirs = [
|
include_dirs = [
|
||||||
"export",
|
"export",
|
||||||
"//commonlibrary/c_utils/base/include",
|
"//commonlibrary/c_utils/base/include",
|
||||||
"//third_party/libdrm",
|
|
||||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits",
|
"//base/hiviewdfx/hilog/interfaces/native/innerkits",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ private:
|
|||||||
FenceStatus GetStatus();
|
FenceStatus GetStatus();
|
||||||
|
|
||||||
UniqueFd fenceFd_;
|
UniqueFd fenceFd_;
|
||||||
|
static int SyncMerge(const char *name, int fd1, int fd2);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <securec.h>
|
#include <securec.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
#include <linux/sync_file.h>
|
#include <linux/sync_file.h>
|
||||||
#include <libsync.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include "sw_sync.h"
|
#include "sw_sync.h"
|
||||||
#include "hilog/log.h"
|
#include "hilog/log.h"
|
||||||
|
|
||||||
@ -106,27 +105,67 @@ SyncFence::~SyncFence()
|
|||||||
|
|
||||||
int32_t SyncFence::Wait(uint32_t timeout)
|
int32_t SyncFence::Wait(uint32_t timeout)
|
||||||
{
|
{
|
||||||
|
int retCode = -1;
|
||||||
if (fenceFd_ < 0) {
|
if (fenceFd_ < 0) {
|
||||||
return 0;
|
HiLog::Error(LABEL, "The fence id is invalid.");
|
||||||
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t err = sync_wait(fenceFd_, timeout);
|
struct pollfd pollfds = {0};
|
||||||
return err < 0 ? -errno : 0;
|
pollfds.fd = fenceFd_;
|
||||||
|
pollfds.events = POLLIN;
|
||||||
|
|
||||||
|
do {
|
||||||
|
retCode = poll(&pollfds, 1, timeout);
|
||||||
|
} while (retCode == -1 && (errno == EINTR || errno == EAGAIN));
|
||||||
|
|
||||||
|
if (retCode == 0) {
|
||||||
|
retCode = -1;
|
||||||
|
errno = ETIME;
|
||||||
|
} else if (retCode > 0) {
|
||||||
|
if (pollfds.revents & (POLLERR | POLLNVAL)) {
|
||||||
|
retCode = -1;
|
||||||
|
errno = EINVAL;
|
||||||
|
}
|
||||||
|
retCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retCode < 0 ? -errno : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SyncFence::SyncMerge(const char *name, int fd1, int fd2)
|
||||||
|
{
|
||||||
|
int retCode = -1;
|
||||||
|
struct sync_merge_data syncMergeData = {0};
|
||||||
|
syncMergeData.fd2 = fd2;
|
||||||
|
if (strcpy_s(syncMergeData.name, sizeof(syncMergeData.name), name)) {
|
||||||
|
HiLog::Error(LABEL, "SyncMerge ctrcpy fence name failed.");
|
||||||
|
return retCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
retCode = ioctl(fd1, SYNC_IOC_MERGE, &syncMergeData);
|
||||||
|
if (retCode < 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
HiLog::Error(LABEL, "Fence merge failed, errno is %{public}d.", errno);
|
||||||
|
return retCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return syncMergeData.fence;
|
||||||
}
|
}
|
||||||
|
|
||||||
sptr<SyncFence> SyncFence::MergeFence(const std::string &name,
|
sptr<SyncFence> SyncFence::MergeFence(const std::string &name,
|
||||||
const sptr<SyncFence>& fence1, const sptr<SyncFence>& fence2)
|
const sptr<SyncFence>& fence1, const sptr<SyncFence>& fence2)
|
||||||
{
|
{
|
||||||
int32_t newFenceFd = INVALID_FD;
|
int32_t newFenceFd = INVALID_FD;
|
||||||
int32_t fenceFd1 = fence1->fenceFd_;
|
int32_t fenceFd1 = fence1->fenceFd_;
|
||||||
int32_t fenceFd2 = fence2->fenceFd_;
|
int32_t fenceFd2 = fence2->fenceFd_;
|
||||||
|
|
||||||
if (fenceFd1 >= 0 && fenceFd2 >= 0) {
|
if (fenceFd1 >= 0 && fenceFd2 >= 0) {
|
||||||
newFenceFd = sync_merge(name.c_str(), fenceFd1, fenceFd2);
|
newFenceFd = SyncFence::SyncMerge(name.c_str(), fenceFd1, fenceFd2);
|
||||||
} else if (fenceFd1 >= 0) {
|
} else if (fenceFd1 >= 0) {
|
||||||
newFenceFd = sync_merge(name.c_str(), fenceFd1, fenceFd1);
|
newFenceFd = SyncFence::SyncMerge(name.c_str(), fenceFd1, fenceFd1);
|
||||||
} else if (fenceFd2 >= 0) {
|
} else if (fenceFd2 >= 0) {
|
||||||
newFenceFd = sync_merge(name.c_str(), fenceFd2, fenceFd2);
|
newFenceFd = SyncFence::SyncMerge(name.c_str(), fenceFd2, fenceFd2);
|
||||||
} else {
|
} else {
|
||||||
return INVALID_FENCE;
|
return INVALID_FENCE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user