fix animation_service

Change-Id: I8b33df69c5da7b241bca3b47080786b628d5981f
Signed-off-by: lizheng <lizheng2@huawei.com>
This commit is contained in:
lizheng 2021-12-16 15:01:58 +08:00
parent 1df8d59f9a
commit 224ef1c289
7 changed files with 43 additions and 10 deletions

View File

@ -56,6 +56,7 @@ private:
VsyncError RequestNextVsync();
std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
sptr<VsyncHelper> vhelper = nullptr;
sptr<Window> window = nullptr;
sptr<EglRenderSurface> eglSurface = nullptr;

View File

@ -17,6 +17,8 @@
#include <cassert>
#include <chrono>
#include <fstream>
#include <sys/time.h>
#include <securec.h>
#include <gslogger.h>
@ -41,6 +43,7 @@ GSError AnimationServer::StartRotationAnimation(int32_t did, int32_t degree)
GSError AnimationServer::Init()
{
handler = AppExecFwk::EventHandler::Current();
vhelper = VsyncHelper::FromHandler(handler);
auto wm = WindowManager::GetInstance();
auto wret = wm->Init();
if (wret != WM_OK) {
@ -71,6 +74,7 @@ void AnimationServer::StartAnimation(struct Animation &animation)
isAnimationRunning = true;
GSLOG2HI(INFO) << "Animation Start";
window->Hide();
auto wm = WindowManager::GetInstance();
screenshotPromise = new Promise<struct AnimationScreenshotInfo>();
wm->ListenNextScreenShot(0, this);
@ -78,6 +82,7 @@ void AnimationServer::StartAnimation(struct Animation &animation)
if (asinfo.wmimage.wret) {
GSLOG2HI(ERROR) << "OnScreenShot failed: " << WMErrorStr(asinfo.wmimage.wret);
animation.retval->Resolve(static_cast<enum GSError>(asinfo.wmimage.wret));
isAnimationRunning = false;
return;
}
@ -87,7 +92,9 @@ void AnimationServer::StartAnimation(struct Animation &animation)
auto sret = eglSurface->InitContext();
if (sret != SURFACE_ERROR_OK) {
GSLOG2HI(ERROR) << "EGLSurface InitContext failed: " << sret;
animation.retval->Resolve(static_cast<enum GSError>(sret));
isAnimationRunning = false;
return;
}
@ -105,7 +112,9 @@ void AnimationServer::StartAnimation(struct Animation &animation)
};
auto gret = ranimation->Init(param);
if (gret != GSERROR_OK) {
GSLOG2HI(ERROR) << "RotationAnimation Init failed: " << GSErrorStr(gret);
animation.retval->Resolve(gret);
isAnimationRunning = false;
return;
}
@ -120,6 +129,7 @@ void AnimationServer::AnimationSync(int64_t time, void *data)
} else {
GSLOG2HI(INFO) << "Animation End";
isAnimationRunning = false;
window->Hide();
}
}
@ -128,7 +138,7 @@ VsyncError AnimationServer::RequestNextVsync()
struct FrameCallback cb = {
.callback_ = std::bind(&AnimationServer::AnimationSync, this, SYNC_FUNC_ARG),
};
return VsyncHelper::FromHandler(handler)->RequestFrameCallback(cb);
return vhelper->RequestFrameCallback(cb);
}
void AnimationServer::OnScreenShot(const struct WMImageInfo &info)
@ -146,7 +156,7 @@ void AnimationServer::OnScreenShot(const struct WMImageInfo &info)
ainfo.ptr = std::make_shared<Array>();
ainfo.ptr->ptr = std::make_unique<uint8_t[]>(length);
ainfo.wmimage.data = ainfo.ptr.get();
if (memcpy_s(ainfo.ptr.get(), length, info.data, info.size) != EOK) {
if (memcpy_s(ainfo.ptr->ptr.get(), length, info.data, info.size) != EOK) {
GSLOG2HI(ERROR) << "memcpy_s failed: " << strerror(errno);
ainfo.wmimage.wret = static_cast<enum WMError>(GSERROR_INTERNEL);
screenshotPromise->Resolve(ainfo);

View File

@ -17,7 +17,13 @@
#include <chrono>
#include <gslogger.h>
namespace OHOS {
namespace {
DEFINE_HILOG_LABEL("RotationAnimation");
} // namespace
GSError RotationAnimation::Init(struct RotationAnimationParam &param)
{
auto vertexShader = "attribute vec4 pos;\n"
@ -35,10 +41,14 @@ GSError RotationAnimation::Init(struct RotationAnimationParam &param)
"void main()\n{\n"
" gl_FragColor = alpha * texture2D(texture, v_texCoord);\n"
"}\n";
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
param_ = param;
shader_ = std::make_unique<Shader>(vertexShader, fragmentShader);
texture_ = std::make_unique<Texture>(param_.data.get(), param_.width, param_.height);
texture_ = std::make_unique<Texture>(param_.data->ptr.get(), param_.width, param_.height);
shader_->Bind();
@ -67,6 +77,8 @@ bool RotationAnimation::Draw()
glClear(GL_COLOR_BUFFER_BIT);
double complete = static_cast<double>(now - param_.startTime) / param_.duration;
GSLOG2HI(DEBUG) << "complete: " << complete;
auto matrix = Matrix<GLfloat>::RotateMatrixZ(complete * param_.degree);
double alpha = 1.0 - complete;

View File

@ -17,19 +17,24 @@
#include <GLES2/gl2ext.h>
#include <gslogger.h>
namespace {
//DEFINE_HILOG_LABEL("AnimationServer::Texture");
} // namespace
Texture::Texture(void *buffer, int32_t width, int32_t height)
: buffer_(buffer), width_(width), height_(height)
{
glGenTextures(1, &rendererID_);
glBindTexture(GL_TEXTURE_2D, rendererID_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, width_, height_, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, buffer_);
glBindTexture(GL_TEXTURE_2D, 0);
}
Texture::~Texture()

View File

@ -80,7 +80,8 @@ SurfaceError EglManager::Init(EGLContext context)
{
ScopedBytrace eGLManagerInit("EGLManagerInit");
if (initFlag_) {
BLOGW("already init.");
BLOGW("already init, eglMakeCurrent");
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_);
return SURFACE_ERROR_OK;
}

View File

@ -141,6 +141,10 @@ SurfaceError ProducerEglSurface::InitContext(EGLContext context)
return SURFACE_ERROR_INIT;
}
if (initFlag_) {
return SURFACE_ERROR_OK;
}
if (RequestBufferProc() != SURFACE_ERROR_OK) {
BLOGNE("RequestBufferProc failed.");
return SURFACE_ERROR_INIT;

View File

@ -4,7 +4,7 @@
"cmds" : [
"start graphic_dumper_server",
"start bootanimation",
"start animationserver"
"start animation_server"
]
}
],
@ -22,8 +22,8 @@
"disabled" : 1,
"once" : 1
}, {
"name" : "animationserver",
"path" : ["/system/bin/animationserver"],
"name" : "animation_server",
"path" : ["/system/bin/animation_server"],
"disabled" : 1
}
]