mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-22 22:51:05 +00:00
delete module frame rectify
Signed-off-by: baizengqiang <baizengqiang1@huawei.com>
This commit is contained in:
parent
e621ea23e2
commit
779ce6788f
1
BUILD.gn
1
BUILD.gn
@ -12,7 +12,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/graphic/graphic_2d/utils/wmlayout/wmlayout.gni")
|
||||
import("graphic_config.gni")
|
||||
|
||||
group("default") {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
@ -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 "animation_module.h"
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
#include <gslogger.h>
|
||||
#include <scoped_bytrace.h>
|
||||
#include <securec.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
DEFINE_HILOG_LABEL("AnimationModule");
|
||||
} // namespace
|
||||
|
||||
GSError AnimationModule::Init()
|
||||
{
|
||||
handler = AppExecFwk::EventHandler::Current();
|
||||
vhelper = VsyncHelper::Current();
|
||||
auto wm = WindowManager::GetInstance();
|
||||
auto option = WindowOption::Get();
|
||||
option->SetWindowType(WINDOW_TYPE_ANIMATION);
|
||||
auto wret = wm->CreateWindow(window, option);
|
||||
if (wret != GSERROR_OK || window == nullptr) {
|
||||
GSLOG2HI(ERROR) << "WindowManager::CreateWindow failed: " << GSErrorStr(wret);
|
||||
return wret;
|
||||
}
|
||||
|
||||
window->Hide();
|
||||
auto producer = window->GetProducer();
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError AnimationModule::StartRotationAnimation(int32_t did, int32_t degree)
|
||||
{
|
||||
if (isAnimationRunning == false) {
|
||||
struct Animation animation {
|
||||
.degree = degree,
|
||||
.retval = new Promise<GSError>(),
|
||||
};
|
||||
handler->PostTask(std::bind(&AnimationModule::StartAnimation, this, std::ref(animation)));
|
||||
return animation.retval->Await();
|
||||
}
|
||||
return GSERROR_ANIMATION_RUNNING;
|
||||
}
|
||||
|
||||
void AnimationModule::OnScreenShot(const struct WMImageInfo &info)
|
||||
{
|
||||
int32_t length = info.size;
|
||||
struct AnimationScreenshotInfo ainfo = {
|
||||
.wmimage = info,
|
||||
.ptr = nullptr,
|
||||
};
|
||||
if (info.wret != GSERROR_OK) {
|
||||
screenshotPromise->Resolve(ainfo);
|
||||
return;
|
||||
}
|
||||
|
||||
ainfo.ptr = std::make_shared<struct Array>();
|
||||
ainfo.ptr->ptr = std::make_unique<uint8_t[]>(length);
|
||||
ainfo.wmimage.data = ainfo.ptr.get();
|
||||
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 GSError>(GSERROR_INTERNAL);
|
||||
screenshotPromise->Resolve(ainfo);
|
||||
return;
|
||||
}
|
||||
|
||||
screenshotPromise->Resolve(ainfo);
|
||||
}
|
||||
|
||||
void AnimationModule::StartAnimation(struct Animation &animation)
|
||||
{
|
||||
if (isAnimationRunning) {
|
||||
animation.retval->Resolve(GSERROR_ANIMATION_RUNNING);
|
||||
return;
|
||||
}
|
||||
|
||||
ScopedBytrace trace(__func__);
|
||||
isAnimationRunning = true;
|
||||
GSLOG2HI(INFO) << "Animation Start";
|
||||
window->Hide();
|
||||
auto wm = WindowManager::GetInstance();
|
||||
screenshotPromise = new Promise<struct AnimationScreenshotInfo>();
|
||||
wm->ListenNextScreenShot(0, this);
|
||||
auto asinfo = screenshotPromise->Await();
|
||||
if (asinfo.wmimage.wret) {
|
||||
GSLOG2HI(ERROR) << "OnScreenShot failed: " << GSErrorStr(asinfo.wmimage.wret);
|
||||
animation.retval->Resolve(static_cast<enum GSError>(asinfo.wmimage.wret));
|
||||
isAnimationRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
window->Show();
|
||||
|
||||
auto sret = eglSurface->InitContext();
|
||||
if (sret != GSERROR_OK) {
|
||||
GSLOG2HI(ERROR) << "EGLSurface InitContext failed: " << sret;
|
||||
animation.retval->Resolve(static_cast<enum GSError>(sret));
|
||||
isAnimationRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ranimation = std::make_unique<RotationAnimation>();
|
||||
constexpr int32_t rotationAnimationDuration = 500;
|
||||
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
struct RotationAnimationParam param = {
|
||||
.data = asinfo.ptr,
|
||||
.width = window->GetWidth(),
|
||||
.height = window->GetHeight(),
|
||||
.startTime = now,
|
||||
.duration = rotationAnimationDuration,
|
||||
.degree = animation.degree,
|
||||
};
|
||||
auto gret = ranimation->Init(param);
|
||||
if (gret != GSERROR_OK) {
|
||||
GSLOG2HI(ERROR) << "RotationAnimation Init failed: " << GSErrorStr(gret);
|
||||
animation.retval->Resolve(gret);
|
||||
isAnimationRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
struct FrameCallback cb = { .callback_ = std::bind(&AnimationModule::AnimationSync, this, SYNC_FUNC_ARG) };
|
||||
animation.retval->Resolve(static_cast<enum GSError>(vhelper->RequestFrameCallback(cb)));
|
||||
}
|
||||
|
||||
void AnimationModule::AnimationSync(int64_t time, void *data)
|
||||
{
|
||||
ScopedBytrace trace(__func__);
|
||||
if (ranimation->Draw()) {
|
||||
eglSurface->SwapBuffers();
|
||||
struct FrameCallback cb = { .callback_ = std::bind(&AnimationModule::AnimationSync, this, SYNC_FUNC_ARG) };
|
||||
vhelper->RequestFrameCallback(cb);
|
||||
trace.End();
|
||||
} else {
|
||||
trace.End();
|
||||
GSLOG2HI(INFO) << "Animation End";
|
||||
window->Hide();
|
||||
isAnimationRunning = false;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,108 +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_WM_WINDOW_MANAGER_H
|
||||
#define INTERFACES_INNERKITS_WM_WINDOW_MANAGER_H
|
||||
|
||||
#include "window_manager_common.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
#include <../wmclient/iscreen_shot_callback.h>
|
||||
#include <../wmclient/iwindow_shot_callback.h>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief The IWindowManager class is an abstract definition of windows manager.
|
||||
* Provides a series of client/interfaces for window management, event processing, etc.
|
||||
*/
|
||||
|
||||
class WindowBase {
|
||||
public:
|
||||
WindowBase(int32_t windowid, sptr<Surface>& surface);
|
||||
virtual ~WindowBase();
|
||||
|
||||
void GetRequestConfig(BufferRequestConfig &config);
|
||||
void SetRequestConfig(BufferRequestConfig &config);
|
||||
void RegisterWindowInfoChangeCb(funcWindowInfoChange cb);
|
||||
|
||||
int32_t GetWindowID();
|
||||
virtual sptr<Surface> GetSurface();
|
||||
|
||||
protected:
|
||||
int32_t m_windowid;
|
||||
sptr<Surface> surface_;
|
||||
BufferRequestConfig config_;
|
||||
};
|
||||
|
||||
class Window : public WindowBase {
|
||||
public:
|
||||
Window(int32_t windowid, sptr<Surface>& surface);
|
||||
~Window();
|
||||
|
||||
void Show();
|
||||
void Hide();
|
||||
void Move(int32_t x, int32_t y);
|
||||
void SwitchTop();
|
||||
void ChangeWindowType(WindowType type);
|
||||
void ReSize(int32_t width, int32_t height);
|
||||
void Rotate(rotateType type);
|
||||
void RegisterOnWindowCreateCb(void(* cb)(uint32_t pid));
|
||||
};
|
||||
|
||||
class SubWindow : public WindowBase {
|
||||
public:
|
||||
SubWindow(int32_t windowid, sptr<Surface>& surface);
|
||||
virtual ~SubWindow();
|
||||
|
||||
virtual void Move(int32_t x, int32_t y);
|
||||
virtual void SetSubWindowSize(int32_t width, int32_t height);
|
||||
};
|
||||
|
||||
class ScreenShotCallback : public RefBase {
|
||||
public:
|
||||
virtual void OnScreenShot(const struct WMImageInfo &info){}
|
||||
};
|
||||
|
||||
class WindowShotCallback : public RefBase {
|
||||
public:
|
||||
virtual void OnWindowShot(const struct WMImageInfo &info){}
|
||||
};
|
||||
|
||||
class WindowManager : public RefBase {
|
||||
public:
|
||||
static sptr<WindowManager> GetInstance();
|
||||
|
||||
std::unique_ptr<Window> CreateWindow(WindowConfig *config);
|
||||
std::unique_ptr<SubWindow> CreateSubWindow(int32_t parentid, WindowConfig *config);
|
||||
void StartShotScreen(IScreenShotCallback *cb);
|
||||
void StartShotWindow(int32_t id, IWindowShotCallback *cb);
|
||||
int32_t GetMaxWidth();
|
||||
int32_t GetMaxHeight();
|
||||
void SwitchTop(int windowId);
|
||||
void DestroyWindow(int windowId);
|
||||
private:
|
||||
static sptr<WindowManager> instance;
|
||||
WindowManager();
|
||||
virtual ~WindowManager();
|
||||
|
||||
void init();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WM_WINDOW_MANAGER_H
|
@ -1,45 +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_WM_WINDOW_MANAGER_COMMON_H
|
||||
#define INTERFACES_INNERKITS_WM_WINDOW_MANAGER_COMMON_H
|
||||
|
||||
#include "wmclient/wm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef enum {
|
||||
WINDOW_LAYER_DEFINE_NORMAL_ID = 5000,
|
||||
WINDOW_LAYER_DEFINE_STATUSBAR_ID = 6000,
|
||||
WINDOW_LAYER_DEFINE_NAVIBAR_ID = 7000,
|
||||
WINDOW_LAYER_DEFINE_ALARM_ID = 8000,
|
||||
} LayerID;
|
||||
|
||||
constexpr int32_t LAYER_ID_APP_TYPE_BASE = 5000;
|
||||
constexpr int32_t LAYER_ID_TYPE_OFSSET = 1000;
|
||||
|
||||
typedef enum {
|
||||
SHOT_WINDOW = 0,
|
||||
SHOT_SCREEN,
|
||||
SHOT_INVALID
|
||||
} ShotType;
|
||||
|
||||
struct MoveReq {
|
||||
int32_t id;
|
||||
int32_t pos_x;
|
||||
int32_t pos_y;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WM_WINDOW_MANAGER_COMMON_H
|
@ -1,31 +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_WMCLIENT_ISCREEN_SHOT_CALLBACK_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_ISCREEN_SHOT_CALLBACK_H
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IScreenShotCallback {
|
||||
public:
|
||||
virtual ~IScreenShotCallback() = default;
|
||||
virtual void OnScreenShot(const struct WMImageInfo &info) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_ISCREEN_SHOT_CALLBACK_H
|
@ -1,31 +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_WMCLIENT_IWINDOW_SHOT_CALLBACK_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_IWINDOW_SHOT_CALLBACK_H
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IWindowShotCallback {
|
||||
public:
|
||||
virtual ~IWindowShotCallback() = default;
|
||||
virtual void OnWindowShot(const struct WMImageInfo &info) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_IWINDOW_SHOT_CALLBACK_H
|
@ -1,45 +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_WMCLIENT_SUBWINDOW_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_SUBWINDOW_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
using FrameAvailableFunc = std::function<int32_t(sptr<SurfaceBuffer> &buffer)>;
|
||||
class Subwindow : public RefBase {
|
||||
public:
|
||||
virtual sptr<Surface> GetSurface() const = 0;
|
||||
|
||||
virtual GSError Move(int32_t x, int32_t y) = 0;
|
||||
virtual GSError Resize(uint32_t width, uint32_t height) = 0;
|
||||
virtual GSError Destroy() = 0;
|
||||
|
||||
virtual void OnPositionChange(WindowPositionChangeFunc func) = 0;
|
||||
virtual void OnSizeChange(WindowSizeChangeFunc func) = 0;
|
||||
virtual void OnBeforeFrameSubmit(BeforeFrameSubmitFunc func) = 0;
|
||||
|
||||
virtual GSError OnFrameAvailable(FrameAvailableFunc func)
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_SUBWINDOW_H
|
@ -1,45 +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_WMCLIENT_SUBWINDOW_OPTION_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_SUBWINDOW_OPTION_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class SubwindowOption : public RefBase {
|
||||
public:
|
||||
static sptr<SubwindowOption> Get();
|
||||
|
||||
virtual GSError SetWindowType(SubwindowType type) = 0;
|
||||
virtual GSError SetX(int32_t x) = 0;
|
||||
virtual GSError SetY(int32_t y) = 0;
|
||||
virtual GSError SetWidth(uint32_t w) = 0;
|
||||
virtual GSError SetHeight(uint32_t h) = 0;
|
||||
virtual GSError SetConsumerSurface(const sptr<Surface> &surf) = 0;
|
||||
|
||||
virtual SubwindowType GetWindowType() const = 0;
|
||||
virtual int32_t GetX() const = 0;
|
||||
virtual int32_t GetY() const = 0;
|
||||
virtual uint32_t GetWidth() const = 0;
|
||||
virtual uint32_t GetHeight() const = 0;
|
||||
virtual sptr<Surface> GetConsumerSurface() const = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_SUBWINDOW_OPTION_H
|
@ -1,46 +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_WMCLIENT_VIRTUAL_DISPLAY_OPTION_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_VIRTUAL_DISPLAY_OPTION_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class VirtualDisplayOption : public RefBase {
|
||||
public:
|
||||
static sptr<VirtualDisplayOption> Get();
|
||||
|
||||
virtual GSError SetX(int32_t x) = 0;
|
||||
virtual GSError SetY(int32_t y) = 0;
|
||||
virtual GSError SetWidth(uint32_t width) = 0;
|
||||
virtual GSError SetHeight(uint32_t height) = 0;
|
||||
|
||||
virtual int32_t GetX() const = 0;
|
||||
virtual int32_t GetY() const = 0;
|
||||
virtual uint32_t GetWidth() const = 0;
|
||||
virtual uint32_t GetHeight() const = 0;
|
||||
|
||||
virtual bool IsSettingX() const = 0;
|
||||
virtual bool IsSettingY() const = 0;
|
||||
virtual bool IsSettingWidth() const = 0;
|
||||
virtual bool IsSettingHeight() const = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_VIRTUAL_DISPLAY_OPTION_H
|
@ -1,83 +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_WMCLIENT_WINDOW_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_WINDOW_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
#include <promise.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class Window : public RefBase {
|
||||
public:
|
||||
virtual sptr<Surface> GetSurface() const = 0;
|
||||
virtual sptr<IBufferProducer> GetProducer() const = 0;
|
||||
virtual int32_t GetID() const = 0;
|
||||
virtual int32_t GetX() const = 0;
|
||||
virtual int32_t GetY() const = 0;
|
||||
virtual uint32_t GetWidth() const = 0;
|
||||
virtual uint32_t GetHeight() const = 0;
|
||||
virtual uint32_t GetDestWidth() const = 0;
|
||||
virtual uint32_t GetDestHeight() const = 0;
|
||||
virtual bool GetVisibility() const = 0;
|
||||
virtual WindowType GetType() const = 0;
|
||||
virtual WindowMode GetMode() const = 0;
|
||||
|
||||
virtual sptr<Promise<GSError>> Show() = 0;
|
||||
virtual sptr<Promise<GSError>> Hide() = 0;
|
||||
virtual sptr<Promise<GSError>> Move(int32_t x, int32_t y) = 0;
|
||||
virtual sptr<Promise<GSError>> SwitchTop() = 0;
|
||||
virtual sptr<Promise<GSError>> SetWindowType(WindowType type) = 0;
|
||||
virtual sptr<Promise<GSError>> SetWindowMode(WindowMode mode) = 0;
|
||||
virtual sptr<Promise<GSError>> Resize(uint32_t width, uint32_t height) = 0;
|
||||
virtual sptr<Promise<GSError>> ScaleTo(uint32_t width, uint32_t height) = 0;
|
||||
virtual GSError Rotate(WindowRotateType type) = 0;
|
||||
virtual GSError Destroy() = 0;
|
||||
|
||||
// prop listener
|
||||
virtual void OnPositionChange(WindowPositionChangeFunc func) = 0;
|
||||
virtual void OnSizeChange(WindowSizeChangeFunc func) = 0;
|
||||
virtual void OnVisibilityChange(WindowVisibilityChangeFunc func) = 0;
|
||||
virtual void OnTypeChange(WindowTypeChangeFunc func) = 0;
|
||||
virtual void OnModeChange(WindowModeChangeFunc func) = 0;
|
||||
virtual void OnSplitStatusChange(SplitStatusChangeFunc func) = 0;
|
||||
virtual void OnBeforeFrameSubmit(BeforeFrameSubmitFunc func) = 0;
|
||||
|
||||
// pip Mode
|
||||
virtual bool GetPIPMode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual GSError EnterPIPMode(int32_t x, int32_t y,
|
||||
uint32_t width, uint32_t height)
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
virtual GSError ExitPIPMode()
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
virtual GSError OnPIPModeChange(WindowPIPModeChangeFunc func)
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_WINDOW_H
|
@ -1,56 +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_WMCLIENT_WINDOW_MANAGER_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_WINDOW_MANAGER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
#include "iscreen_shot_callback.h"
|
||||
#include "iwindow_shot_callback.h"
|
||||
#include "subwindow.h"
|
||||
#include "subwindow_option.h"
|
||||
#include "window.h"
|
||||
#include "window_manager_type.h"
|
||||
#include "window_option.h"
|
||||
#include "virtual_display_option.h"
|
||||
|
||||
namespace OHOS {
|
||||
class WindowManager : public RefBase {
|
||||
public:
|
||||
static sptr<WindowManager> GetInstance();
|
||||
|
||||
virtual GSError Init() = 0;
|
||||
|
||||
virtual GSError GetDisplays(std::vector<struct WMDisplayInfo> &displays) const = 0;
|
||||
virtual sptr<Window> GetWindowByID(int32_t wid) = 0;
|
||||
|
||||
virtual GSError CreateWindow(sptr<Window> &window, const sptr<WindowOption> &option) = 0;
|
||||
virtual GSError CreateSubwindow(sptr<Subwindow> &subwindow,
|
||||
const sptr<Window> &window,
|
||||
const sptr<SubwindowOption> &option) = 0;
|
||||
|
||||
virtual GSError ListenNextScreenShot(int32_t id, IScreenShotCallback *cb) = 0;
|
||||
virtual GSError ListenNextWindowShot(const sptr<Window> &window, IWindowShotCallback *cb) = 0;
|
||||
|
||||
virtual GSError CreateVirtualDisplay(const sptr<VirtualDisplayOption> &option) = 0;
|
||||
virtual GSError DestroyVirtualDisplay(uint32_t did) = 0;
|
||||
virtual GSError SetDisplayMode(WMSDisplayMode mode) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_WINDOW_MANAGER_H
|
@ -1,115 +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_WMCLIENT_WINDOW_MANAGER_TYPE_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_WINDOW_MANAGER_TYPE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#include "wm_common.h"
|
||||
|
||||
#include "common/graphic_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace OHOS {
|
||||
#endif
|
||||
|
||||
enum SubwindowType {
|
||||
SUBWINDOW_TYPE_NORMAL = 0,
|
||||
SUBWINDOW_TYPE_VIDEO = 1,
|
||||
SUBWINDOW_TYPE_OFFSCREEN = 2,
|
||||
SUBWINDOW_TYPE_MAX,
|
||||
};
|
||||
|
||||
enum WindowRotateType {
|
||||
WINDOW_ROTATE_TYPE_NORMAL = 0,
|
||||
WINDOW_ROTATE_TYPE_90 = 1,
|
||||
WINDOW_ROTATE_TYPE_180 = 2,
|
||||
WINDOW_ROTATE_TYPE_270 = 3,
|
||||
WINDOW_ROTATE_TYPE_FLIPPED = 4,
|
||||
WINDOW_ROTATE_TYPE_FLIPPED_90 = 5,
|
||||
WINDOW_ROTATE_TYPE_FLIPPED_180 = 6,
|
||||
WINDOW_ROTATE_TYPE_FLIPPED_270 = 7,
|
||||
WINDOW_ROTATE_TYPE_MAX,
|
||||
};
|
||||
|
||||
enum WindowMode {
|
||||
WINDOW_MODE_UNSET = 0,
|
||||
WINDOW_MODE_FULL = 1,
|
||||
WINDOW_MODE_FREE = 2,
|
||||
WINDOW_MODE_MAX,
|
||||
};
|
||||
|
||||
// bitmask
|
||||
enum WMSDisplayMode {
|
||||
WM_DISPLAY_MODE_SINGLE = 1,
|
||||
WM_DISPLAY_MODE_CLONE = 2,
|
||||
WM_DISPLAY_MODE_EXTEND = 4,
|
||||
WM_DISPLAY_MODE_EXPAND = 8,
|
||||
};
|
||||
|
||||
enum DisplayType {
|
||||
DISPLAY_TYPE_PHYSICAL = 0,
|
||||
DISPLAY_TYPE_VIRTUAL,
|
||||
DISPLAY_TYPE_MAX,
|
||||
};
|
||||
|
||||
enum SplitStatus {
|
||||
SPLIT_STATUS_CLEAR = 0,
|
||||
SPLIT_STATUS_VAGUE = 1,
|
||||
SPLIT_STATUS_RETAIN = 2,
|
||||
SPLIT_STATUS_DESTROY = 3,
|
||||
SPLIT_STATUS_MAX,
|
||||
};
|
||||
|
||||
enum WindowSplitMode {
|
||||
WINDOW_SPLIT_MODE_UNSET = 0,
|
||||
WINDOW_SPLIT_MODE_SET = 1,
|
||||
WINDOW_SPLIT_MODE_MAX,
|
||||
};
|
||||
|
||||
enum SplitMode {
|
||||
SPLIT_MODE_NULL = 0,
|
||||
SPLIT_MODE_UNENABLE = 1,
|
||||
SPLIT_MODE_SINGLE = 2,
|
||||
SPLIT_MODE_SELECT = 3,
|
||||
SPLIT_MODE_CONFIRM = 4,
|
||||
SPLIT_MODE_DIVIDER_TOUCH_DOWN = 5,
|
||||
SPLIT_MODE_DIVIDER_TOUCH_MOVE = 6,
|
||||
SPLIT_MODE_DIVIDER_TOUCH_UP = 7,
|
||||
SPLIT_MODE_MAX,
|
||||
};
|
||||
|
||||
struct WMDisplayInfo {
|
||||
int32_t id;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t phyWidth;
|
||||
uint32_t phyHeight;
|
||||
uint32_t vsync;
|
||||
enum DisplayType type;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
using WindowModeChangeFunc = std::function<void(WindowMode mode)>;
|
||||
using BeforeFrameSubmitFunc = std::function<void()>;
|
||||
using SplitStatusChangeFunc = std::function<void(SplitStatus status)>;
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_WINDOW_MANAGER_TYPE_H
|
@ -1,54 +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_WMCLIENT_WINDOW_OPTION_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_WINDOW_OPTION_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <surface.h>
|
||||
|
||||
#include "window_manager_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class WindowOption : public RefBase {
|
||||
public:
|
||||
static sptr<WindowOption> Get();
|
||||
|
||||
virtual GSError SetWindowType(WindowType type) = 0;
|
||||
virtual GSError SetWindowMode(WindowMode mode) = 0;
|
||||
virtual GSError SetDisplay(int32_t did) = 0;
|
||||
virtual GSError SetConsumerSurface(const sptr<Surface> &surf) = 0;
|
||||
virtual GSError SetX(int32_t x) = 0;
|
||||
virtual GSError SetY(int32_t y) = 0;
|
||||
virtual GSError SetWidth(uint32_t width) = 0;
|
||||
virtual GSError SetHeight(uint32_t height) = 0;
|
||||
|
||||
virtual WindowType GetWindowType() const = 0;
|
||||
virtual WindowMode GetWindowMode() const = 0;
|
||||
virtual int32_t GetDisplay() const = 0;
|
||||
virtual sptr<Surface> GetConsumerSurface() const = 0;
|
||||
virtual int32_t GetX() const = 0;
|
||||
virtual int32_t GetY() const = 0;
|
||||
virtual uint32_t GetWidth() const = 0;
|
||||
virtual uint32_t GetHeight() const = 0;
|
||||
|
||||
virtual bool IsSettingX() const = 0;
|
||||
virtual bool IsSettingY() const = 0;
|
||||
virtual bool IsSettingWidth() const = 0;
|
||||
virtual bool IsSettingHeight() const = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_WINDOW_OPTION_H
|
@ -1,160 +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_WMCLIENT_WM_COMMON_H
|
||||
#define INTERFACES_INNERKITS_WMCLIENT_WM_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
#include "common/graphic_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace OHOS {
|
||||
#endif
|
||||
|
||||
#define WINDOW_TYPE_LIST(macro) \
|
||||
macro(WINDOW_TYPE_NORMAL), \
|
||||
macro(WINDOW_TYPE_STATUS_BAR), \
|
||||
macro(WINDOW_TYPE_NAVI_BAR), \
|
||||
macro(WINDOW_TYPE_ALARM_SCREEN), \
|
||||
macro(WINDOW_TYPE_SYSTEM_UI), \
|
||||
macro(WINDOW_TYPE_LAUNCHER), \
|
||||
macro(WINDOW_TYPE_VIDEO), \
|
||||
macro(WINDOW_TYPE_INPUT_METHOD), \
|
||||
macro(WINDOW_TYPE_INPUT_METHOD_SELECTOR), \
|
||||
macro(WINDOW_TYPE_VOLUME_OVERLAY), \
|
||||
macro(WINDOW_TYPE_NOTIFICATION_SHADE), \
|
||||
macro(WINDOW_TYPE_FLOAT), \
|
||||
macro(WINDOW_TYPE_CALLING), \
|
||||
macro(WINDOW_TYPE_FULL_SCREEN), \
|
||||
macro(WINDOW_TYPE_POPUP), \
|
||||
macro(WINDOW_TYPE_SAFE_OVERLAY), \
|
||||
macro(WINDOW_TYPE_SCREENSAVER_CALLING), \
|
||||
macro(WINDOW_TYPE_SCREENSAVER_DIALOG), \
|
||||
macro(WINDOW_TYPE_SCREENSAVER), \
|
||||
macro(WINDOW_TYPE_SEARCHER), \
|
||||
macro(WINDOW_TYPE_STATUS_SCREEN), \
|
||||
macro(WINDOW_TYPE_SYSTEM_ERROR), \
|
||||
macro(WINDOW_TYPE_TOAST), \
|
||||
macro(WINDOW_TYPE_WALLPAPER), \
|
||||
macro(WINDOW_TYPE_ANIMATION), \
|
||||
macro(WINDOW_TYPE_SPLIT_LINE), \
|
||||
macro(WINDOW_TYPE_LAUNCH_PAGE), \
|
||||
macro(WINDOW_TYPE_CURSOR), \
|
||||
macro(WINDOW_TYPE_APPLICATION_BASE), \
|
||||
macro(WINDOW_TYPE_APPLICATION_FIRST), \
|
||||
macro(WINDOW_TYPE_APPLICATION_NORMAL), \
|
||||
macro(WINDOW_TYPE_TOP), \
|
||||
macro(WINDOW_TYPE_MAX),
|
||||
|
||||
#define DEFINE_ENUM_WINDOW_TYPE(id) id
|
||||
#define DEFINE_STRMAP_WINDOW_TYPE(id) { #id, id, }
|
||||
|
||||
enum WindowType { WINDOW_TYPE_LIST(DEFINE_ENUM_WINDOW_TYPE) };
|
||||
|
||||
#ifdef __cplusplus
|
||||
static const std::map<std::string, enum WindowType> windowTypeStrs = {
|
||||
WINDOW_TYPE_LIST(DEFINE_STRMAP_WINDOW_TYPE)
|
||||
};
|
||||
#endif
|
||||
|
||||
enum SubWindowType {
|
||||
WM_WINDOW_TYPE_SUB_NORMAL = 0,
|
||||
WM_WINDOW_TYPE_SUB_VIDEO = 1,
|
||||
};
|
||||
|
||||
enum rotateType {
|
||||
/**
|
||||
* no transform
|
||||
*/
|
||||
WM_ROTATE_TYPE_NORMAL = 0,
|
||||
/**
|
||||
* 90 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_90 = 1,
|
||||
/**
|
||||
* 180 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_180 = 2,
|
||||
/**
|
||||
* 270 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_270 = 3,
|
||||
/**
|
||||
* 180 degree flip around a vertical axis
|
||||
*/
|
||||
WM_ROTATE_TYPE_FLIPPED = 4,
|
||||
/**
|
||||
* flip and rotate 90 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_FLIPPED_90 = 5,
|
||||
/**
|
||||
* flip and rotate 180 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_FLIPPED_180 = 6,
|
||||
/**
|
||||
* flip and rotate 270 degrees counter-clockwise
|
||||
*/
|
||||
WM_ROTATE_TYPE_FLIPPED_270 = 7,
|
||||
};
|
||||
|
||||
struct WMImageInfo {
|
||||
enum GSError wret;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t format;
|
||||
uint32_t size;
|
||||
const void *data;
|
||||
};
|
||||
|
||||
struct WindowInfo {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t pos_x;
|
||||
int32_t pos_y;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
using funcWindowInfoChange = std::function<void(WindowInfo &info)>;
|
||||
using WindowPositionChangeFunc = std::function<void(int32_t x, int32_t y)>;
|
||||
using WindowSizeChangeFunc = std::function<void(uint32_t width, uint32_t height)>;
|
||||
using WindowVisibilityChangeFunc = std::function<void(bool visibility)>;
|
||||
using WindowTypeChangeFunc = std::function<void(WindowType type)>;
|
||||
using WindowPIPModeChangeFunc = std::function<void(bool inPIPMode)>;
|
||||
#endif
|
||||
|
||||
typedef void (*FuncSync)(uint64_t timestamp);
|
||||
struct WindowConfig {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t pos_x;
|
||||
int32_t pos_y;
|
||||
int32_t format;
|
||||
int32_t stride;
|
||||
int32_t type;
|
||||
int32_t parentid;
|
||||
bool subwindow;
|
||||
FuncSync sync;
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
} // namespace OHOS
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMCLIENT_WM_COMMON_H
|
@ -1,29 +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_WMSERVICE_IWINDOW_CHANGE_LISTENER_CLAZZ_H
|
||||
#define INTERFACES_INNERKITS_WMSERVICE_IWINDOW_CHANGE_LISTENER_CLAZZ_H
|
||||
|
||||
namespace OHOS {
|
||||
class IWindowChangeListenerClazz {
|
||||
public:
|
||||
virtual ~IWindowChangeListenerClazz() = default;
|
||||
|
||||
virtual void OnWindowCreate(int32_t pid, int32_t wid) = 0;
|
||||
virtual void OnWindowDestroy(int32_t pid, int32_t wid) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMSERVICE_IWINDOW_CHANGE_LISTENER_CLAZZ_H
|
@ -1,29 +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_WMSERVICE_IWINDOW_MANAGER_DISPLAY_LISTENER_CLAZZ_H
|
||||
#define INTERFACES_INNERKITS_WMSERVICE_IWINDOW_MANAGER_DISPLAY_LISTENER_CLAZZ_H
|
||||
|
||||
namespace OHOS {
|
||||
class IWindowManagerDisplayListenerClazz {
|
||||
public:
|
||||
virtual ~IWindowManagerDisplayListenerClazz() = default;
|
||||
|
||||
virtual void OnScreenPlugin(int32_t did) = 0;
|
||||
virtual void OnScreenPlugout(int32_t did) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMSERVICE_IWINDOW_MANAGER_DISPLAY_LISTENER_CLAZZ_H
|
@ -1,88 +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_WMSERVICE_IWINDOW_MANAGER_SERVICE_H
|
||||
#define INTERFACES_INNERKITS_WMSERVICE_IWINDOW_MANAGER_SERVICE_H
|
||||
|
||||
#include <vector>
|
||||
#include <promise.h>
|
||||
#include <refbase.h>
|
||||
#include <window_manager_type.h>
|
||||
|
||||
#include "iwindow_change_listener_clazz.h"
|
||||
#include "iwindow_manager_display_listener_clazz.h"
|
||||
|
||||
#include "window_manager_service_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IWindowManagerService : public RefBase {
|
||||
public:
|
||||
virtual ~IWindowManagerService() = default;
|
||||
|
||||
virtual GSError GetDisplays(std::vector<struct WMDisplayInfo> &displays) = 0;
|
||||
virtual sptr<PromisePowerStatus> GetDisplayPower(int32_t did) = 0;
|
||||
virtual sptr<PromiseWMError> SetDisplayPower(int32_t did, DispPowerStatus status) = 0;
|
||||
virtual sptr<PromiseBacklight> GetDisplayBacklight(int32_t did) = 0;
|
||||
virtual sptr<PromiseWMError> SetDisplayBacklight(int32_t did, uint32_t level) = 0;
|
||||
virtual sptr<PromiseWMError> SetDisplayMode(WMSDisplayMode modes) = 0;
|
||||
virtual sptr<PromiseWMError> OnWindowListChange(IWindowChangeListenerClazz *listener) = 0;
|
||||
virtual GSError GetDisplayModes(uint32_t &displayModes) = 0;
|
||||
virtual GSError AddDisplayChangeListener(IWindowManagerDisplayListenerClazz *listener) = 0;
|
||||
|
||||
virtual GSError SetDisplayDirection(WMSDisplayDirection direction) = 0;
|
||||
virtual GSError OnDisplayDirectionChange(DisplayDirectionChangeFunc func) = 0;
|
||||
|
||||
virtual sptr<PromiseWMError> SetStatusBarVisibility(bool visibility) = 0;
|
||||
virtual sptr<PromiseWMError> SetNavigationBarVisibility(bool visibility) = 0;
|
||||
|
||||
virtual sptr<PromiseWMSImageInfo> ShotScreen(int32_t did) = 0;
|
||||
virtual sptr<PromiseWMSImageInfo> ShotWindow(int32_t wid) = 0;
|
||||
|
||||
virtual sptr<PromiseWMError> DestroyWindow(int32_t wid) = 0;
|
||||
virtual sptr<PromiseWMError> SwitchTop(int32_t wid) = 0;
|
||||
virtual sptr<PromiseWMError> Show(int32_t wid) = 0;
|
||||
virtual sptr<PromiseWMError> Hide(int32_t wid) = 0;
|
||||
virtual sptr<PromiseWMError> Move(int32_t wid, int32_t x, int32_t y) = 0;
|
||||
virtual sptr<PromiseWMError> Resize(int32_t wid, uint32_t width, uint32_t height) = 0;
|
||||
virtual sptr<PromiseWMError> ScaleTo(int32_t wid, uint32_t width, uint32_t height) = 0;
|
||||
virtual sptr<PromiseWMError> SetWindowType(int32_t wid, WindowType type) = 0;
|
||||
virtual sptr<PromiseWMError> SetWindowMode(int32_t wid, WindowMode mode) = 0;
|
||||
|
||||
virtual sptr<PromiseWMError> CreateVirtualDisplay(int32_t x, int32_t y, int32_t width, int32_t height) = 0;
|
||||
virtual sptr<PromiseWMError> DestroyVirtualDisplay(uint32_t did) = 0;
|
||||
|
||||
virtual GSError StartRotationAnimation(uint32_t did, int32_t degree)
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
virtual sptr<PromiseWMError> SetSplitMode(SplitMode mode, int32_t x = 0, int32_t y = 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual GSError CreateLaunchPage(const std::string &filename)
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
virtual GSError CancelLaunchPage()
|
||||
{
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMSERVICE_IWINDOW_MANAGER_SERVICE_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_WMSERVICE_WINDOW_MANAGER_SERVICE_CLIENT_H
|
||||
#define INTERFACES_INNERKITS_WMSERVICE_WINDOW_MANAGER_SERVICE_CLIENT_H
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
#include "iwindow_manager_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class WindowManagerServiceClient : public RefBase {
|
||||
public:
|
||||
virtual ~WindowManagerServiceClient() = default;
|
||||
static sptr<WindowManagerServiceClient> GetInstance();
|
||||
|
||||
virtual GSError Init() = 0;
|
||||
virtual sptr<IWindowManagerService> GetService() const = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMSERVICE_WINDOW_MANAGER_SERVICE_CLIENT_H
|
@ -1,61 +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_WMSERVICE_WINDOW_MANAGER_SERVICE_TYPE_H
|
||||
#define INTERFACES_INNERKITS_WMSERVICE_WINDOW_MANAGER_SERVICE_TYPE_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <promise.h>
|
||||
#include <window_manager_type.h>
|
||||
|
||||
namespace OHOS {
|
||||
enum WMSDisplayDirection {
|
||||
WMS_DISPLAY_DIRECTION_DOWN = 0,
|
||||
WMS_DISPLAY_DIRECTION_LEFT = 1,
|
||||
WMS_DISPLAY_DIRECTION_UP = 2,
|
||||
WMS_DISPLAY_DIRECTION_RIGHT = 3,
|
||||
};
|
||||
|
||||
using DisplayDirectionChangeFunc = std::function<void(WMSDisplayDirection newDirection)>;
|
||||
|
||||
struct WMSImageInfo {
|
||||
GSError wret;
|
||||
int32_t fd;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t stride;
|
||||
uint32_t format;
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
struct PowerStatus {
|
||||
GSError wret;
|
||||
DispPowerStatus status;
|
||||
};
|
||||
|
||||
struct Backlight {
|
||||
GSError wret;
|
||||
uint32_t level;
|
||||
};
|
||||
|
||||
using PromiseWMError = Promise<WMError>;
|
||||
using PromiseGSError = Promise<GSError>;
|
||||
using PromiseWMSImageInfo = Promise<WMSImageInfo>;
|
||||
using PromisePowerStatus = Promise<PowerStatus>;
|
||||
using PromiseBacklight = Promise<Backlight>;
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_WMSERVICE_WINDOW_MANAGER_SERVICE_TYPE_H
|
@ -1,29 +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/ohos/ace/ace.gni")
|
||||
|
||||
js_declaration("window") {
|
||||
sources = [ "./api" ]
|
||||
|
||||
part_name = "graphic_2d"
|
||||
}
|
||||
|
||||
ohos_copy("window_declaration") {
|
||||
sources = [ "./api" ]
|
||||
|
||||
outputs = [ target_out_dir + "/$target_name/" ]
|
||||
|
||||
module_source_dir = target_out_dir + "/$target_name"
|
||||
module_install_name = ""
|
||||
}
|
@ -1,135 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* interface of display manager
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
declare namespace display {
|
||||
/**
|
||||
* get the default display
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
function getDefaultDisplay(): Promise<Display>;
|
||||
|
||||
/**
|
||||
/**
|
||||
* the state of display
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
enum DisplayState {
|
||||
/**
|
||||
* unknown
|
||||
*/
|
||||
STATE_UNKNOWN = 0,
|
||||
/**
|
||||
* screen off
|
||||
*/
|
||||
STATE_OFF,
|
||||
/**
|
||||
* screen on
|
||||
*/
|
||||
STATE_ON,
|
||||
/**
|
||||
* doze, but it will update for some important system messages
|
||||
*/
|
||||
STATE_DOZE,
|
||||
/**
|
||||
* doze and not update
|
||||
*/
|
||||
STATE_DOZE_SUSPEND,
|
||||
/**
|
||||
* VR node
|
||||
*/
|
||||
STATE_VR,
|
||||
/**
|
||||
* screen on and not update
|
||||
*/
|
||||
STATE_ON_SUSPEND,
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties of display, it couldn't update automatically
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
interface Display {
|
||||
/**
|
||||
* display id
|
||||
*/
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* display name
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* the display is alive
|
||||
*/
|
||||
alive: boolean;
|
||||
|
||||
/**
|
||||
* the state of display
|
||||
*/
|
||||
state: DisplayState;
|
||||
|
||||
/**
|
||||
* refresh rate, unit: Hz
|
||||
*/
|
||||
refreshRate: number;
|
||||
|
||||
/**
|
||||
* the rotation degrees of the display
|
||||
*/
|
||||
rotation: number;
|
||||
|
||||
/**
|
||||
* the width of display, unit: pixel
|
||||
*/
|
||||
width: number;
|
||||
|
||||
/**
|
||||
* the height of display, unit: pixel
|
||||
*/
|
||||
height: number;
|
||||
|
||||
/**
|
||||
* indicates the display resolution.
|
||||
*/
|
||||
densityDPI: number;
|
||||
|
||||
/**
|
||||
* indicates the display density in pixels. The value of a low-resolution display is 1.0
|
||||
*/
|
||||
densityPixels: number;
|
||||
|
||||
/**
|
||||
* indicates the text scale density of a display.
|
||||
*/
|
||||
scaledDensity: number;
|
||||
|
||||
/**
|
||||
* the DPI on X-axis.
|
||||
*/
|
||||
xDPI: number;
|
||||
|
||||
/**
|
||||
* the DPI on Y-axis.
|
||||
*/
|
||||
yDPI: number;
|
||||
}
|
||||
}
|
||||
|
||||
export default display;
|
@ -1,81 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Window manager.
|
||||
* @devices tv, phone, tablet, wearable.
|
||||
*/
|
||||
declare namespace window {
|
||||
/**
|
||||
* Obtain the top window of the current application.
|
||||
* @devices tv, phone, tablet, wearable.
|
||||
*/
|
||||
function getTopWindow(): Promise<Window>;
|
||||
|
||||
/**
|
||||
* The type of a window.
|
||||
* @devices tv, phone, tablet, wearable.
|
||||
*/
|
||||
enum WindowType {
|
||||
/**
|
||||
* App.
|
||||
*/
|
||||
TYPE_APP = 0,
|
||||
/**
|
||||
* System alert.
|
||||
*/
|
||||
TYPE_SYSTEM_ALERT = 30,
|
||||
/**
|
||||
* System volume.
|
||||
*/
|
||||
TYPE_SYSTEM_VOLUME = 70,
|
||||
/**
|
||||
* System panel.
|
||||
*/
|
||||
TYPE_SYSTEM_PANEL = 90,
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface of window.
|
||||
*/
|
||||
interface Window {
|
||||
/**
|
||||
* Set the position of a window.
|
||||
* @param x Indicate the X-coordinate of the window.
|
||||
* @param y Indicate the Y-coordinate of the window.
|
||||
* @devices tv, phone, tablet, wearable, liteWearable.
|
||||
*/
|
||||
moveTo(x: number, y: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Set the size of a window .
|
||||
* @param width Indicates the width of the window.
|
||||
* @param height Indicates the height of the window.
|
||||
* @devices tv, phone, tablet, wearable, liteWearable.
|
||||
*/
|
||||
resetSize(width: number, height: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Set the type of a window.
|
||||
* @param type Indicate the type of a window.
|
||||
* @devices tv, phone, tablet, wearable, liteWearable.
|
||||
*/
|
||||
setWindowType(type: WindowType): Promise<void>;
|
||||
}
|
||||
|
||||
function setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void>;
|
||||
}
|
||||
|
||||
export default window;
|
@ -1 +0,0 @@
|
||||
{}
|
@ -1,63 +0,0 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.test.window",
|
||||
"vendor": "test",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 5,
|
||||
"target": 5,
|
||||
"releaseType": "Beta1"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.test.window",
|
||||
"name": ".Test",
|
||||
"deviceType": [
|
||||
"tablet",
|
||||
"2in1",
|
||||
"default",
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "com.test.window.Test",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"label": "Test",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
package com.test.window;
|
||||
|
||||
import ohos.aafwk.ability.AbilityPackage;
|
||||
|
||||
public class Test extends AbilityPackage {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
super.onInitialize();
|
||||
}
|
||||
}
|
@ -1,31 +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.
|
||||
*/
|
||||
|
||||
package com.test.window;
|
||||
|
||||
import ohos.ace.ability.AceAbility;
|
||||
import ohos.aafwk.content.Intent;
|
||||
|
||||
public class TestAbility extends AceAbility {
|
||||
@Override
|
||||
public void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World"
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界"
|
||||
}
|
||||
}
|
@ -1,24 +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.
|
||||
*/
|
||||
|
||||
.container {
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 100px;
|
||||
}
|
@ -1,21 +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.
|
||||
-->
|
||||
|
||||
<div class="container">
|
||||
<text class="title">
|
||||
你好地球
|
||||
{{ $t('strings.hello') }} {{title}}
|
||||
</text>
|
||||
</div>
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "Test"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "JS_Phone_Empty Feature Ability"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 6.6 KiB |
@ -1,190 +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.
|
||||
"""
|
||||
|
||||
"""
|
||||
gn gen --ide=json
|
||||
1. modifty at ./build/core/build_scripts/make_main.sh
|
||||
|
||||
${BUILD_TOOLS_DIR}/gn gen ${TARGET_OUT_DIR} --> ${BUILD_TOOLS_DIR}/gn gen --ide=json ${TARGET_OUT_DIR}
|
||||
|
||||
2. build object --> generate project.json at out/ohos-arm-release/project.json
|
||||
|
||||
3. python3 gn_project_to_cmake.py root_path_of_project(eg. home/xxxx/code/openharmony)
|
||||
|
||||
to generate CMakeLists.txt at home/xxxx/code/openharmony
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path, PureWindowsPath
|
||||
from typing import List
|
||||
|
||||
def to_abs_path(path: str) -> str:
|
||||
if path.startswith("//"):
|
||||
path = path[2:]
|
||||
return path
|
||||
|
||||
|
||||
class GnTarget(object):
|
||||
def __init__(self, full_name: str, content: object):
|
||||
self.full_name = full_name
|
||||
self.content = content
|
||||
self.resolved = False
|
||||
|
||||
@property
|
||||
def dep_names(self) -> set:
|
||||
return set(self.content.get('deps', []))
|
||||
|
||||
@property
|
||||
def inputs_field(self) -> set:
|
||||
return set(self.content.get('inputs', set()))
|
||||
|
||||
@property
|
||||
def sources_field(self) -> set:
|
||||
return set(self.content.get('sources', set()))
|
||||
|
||||
@property
|
||||
def include_dirs_field(self) -> set:
|
||||
return set(self.content.get('include_dirs', set()))
|
||||
|
||||
def __filter_src_dirs(self, files) -> set:
|
||||
return set(f.split("/src/")[0] + "/src" for f in files)
|
||||
|
||||
@property
|
||||
def cpp_src_files(self) -> set:
|
||||
return set(to_abs_path(jf) for jf in self.sources_field
|
||||
if
|
||||
jf.endswith(".cpp") or jf.endswith(".h") or jf.endswith(".c++") or jf.endswith(".cc"))
|
||||
|
||||
@property
|
||||
def cpp_hdr_dirs(self) -> set:
|
||||
return set(to_abs_path(x) for x in self.include_dirs_field if x != "//" and not x.startswith("//out"))
|
||||
|
||||
|
||||
class ProjectJson(object):
|
||||
def __init__(self, path: str):
|
||||
self.path = path
|
||||
with open(path, 'r') as project_file:
|
||||
self.jobj = json.load(project_file)
|
||||
|
||||
self.gn_targets_cache = dict()
|
||||
project_targets = self.jobj['targets']
|
||||
for k, v in project_targets.items():
|
||||
if (k.find("rosen") < 0):
|
||||
continue
|
||||
print(k)
|
||||
self.gn_targets_cache[k] = GnTarget(full_name=k, content=v)
|
||||
|
||||
@property
|
||||
def targets(self):
|
||||
return self.gn_targets_cache.values()
|
||||
|
||||
@property
|
||||
def target_names(self):
|
||||
return set([x.full_name for x in self.targets])
|
||||
|
||||
def find_targets_startswith(self, prefix: str) -> List[GnTarget]:
|
||||
return [x for x in self.targets if x.full_name.startswith(prefix)]
|
||||
|
||||
def get_target(self, name: str) -> GnTarget:
|
||||
return next(x for x in self.targets if x.full_name == name)
|
||||
|
||||
|
||||
class CMakeCreator(object):
|
||||
def __init__(self, project_json: ProjectJson, project_root_dir: str):
|
||||
self.project_json = project_json
|
||||
self.project_root_dir = project_root_dir
|
||||
self.project_name = os.path.basename(self.project_root_dir)
|
||||
|
||||
@property
|
||||
def project_cpp_srcs(self):
|
||||
ret = set()
|
||||
for x in self.project_json.targets:
|
||||
for f in x.cpp_src_files:
|
||||
f = os.path.join(self.project_root_dir, f)
|
||||
if os.path.isfile(f):
|
||||
ret.add(f)
|
||||
print(f)
|
||||
|
||||
return sorted(ret)
|
||||
|
||||
@property
|
||||
def project_cpp_hdrs(self):
|
||||
ret = set()
|
||||
for x in self.project_json.targets:
|
||||
ret.update([_ for _ in x.cpp_hdr_dirs if os.path.isdir(self.project_root_dir + "/" + _)])
|
||||
return sorted(ret)
|
||||
|
||||
@property
|
||||
def jar_deps(self):
|
||||
ret = set()
|
||||
for x in self.project_json.targets:
|
||||
ret.update([_ for _ in x.jar_files if os.path.isfile(self.project_root_dir + "/" + _)])
|
||||
return sorted(ret)
|
||||
|
||||
def write_cmakelist(self):
|
||||
hdr_list_str = "\n ".join(self.project_cpp_hdrs)
|
||||
src_list_str = "\n ".join(self.project_cpp_srcs)
|
||||
|
||||
project_name = self.project_name + "clion"
|
||||
|
||||
with open(os.path.join(self.project_root_dir, 'CMakeLists.txt'), "w") as f:
|
||||
f.write("""cmake_minimum_required(VERSION 3.15)\n""")
|
||||
f.write("project(" + project_name + ")\n""")
|
||||
f.write("set(CMAKE_CXX_STANDARD 17)\n")
|
||||
f.write("include_directories(" + hdr_list_str + ")\n")
|
||||
f.write("add_executable(" + project_name + " " + src_list_str + ")\n")
|
||||
|
||||
with open(os.path.join(self.project_root_dir, 'CMakeLists.txt'), "w") as f:
|
||||
f.write('# Generated by gn_project_to_cmake.py.\n')
|
||||
f.write("""cmake_minimum_required(VERSION 3.15)
|
||||
project({}clion)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
include_directories({})
|
||||
add_executable({}clion {})
|
||||
""".format(self.project_name, hdr_list_str, self.project_name, src_list_str))
|
||||
|
||||
def write(self):
|
||||
self.write_cmakelist()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#
|
||||
# read args
|
||||
#
|
||||
if len(sys.argv) < 2:
|
||||
print("""Usage: {} <project_root_dir>,
|
||||
eg. {} /home/xxxxxx/codes/openharmony""".format(sys.argv[0], sys.argv[0]))
|
||||
sys.exit(1)
|
||||
|
||||
project_root_dir = sys.argv[1]
|
||||
if not os.path.isdir(project_root_dir):
|
||||
print(project_root_dir + " not exist!")
|
||||
sys.exit(1)
|
||||
|
||||
#
|
||||
# parse project.json
|
||||
#
|
||||
project_json = ProjectJson(path=os.path.join(*[project_root_dir, "out", "ohos-arm-release", "project.json"]))
|
||||
print(project_json)
|
||||
|
||||
#
|
||||
# write CMakeLists.txt
|
||||
#
|
||||
CMakeCreator(project_json=project_json, project_root_dir=project_root_dir).write()
|
||||
|
@ -21,18 +21,6 @@ group("color_manager") {
|
||||
]
|
||||
}
|
||||
|
||||
group("scoped_bytrace") {
|
||||
public_deps = [ "scoped_bytrace:scoped_bytrace" ]
|
||||
}
|
||||
|
||||
group("promise") {
|
||||
public_deps = [ "promise:promise" ]
|
||||
}
|
||||
|
||||
group("semaphore") {
|
||||
public_deps = [ "semaphore:semaphore" ]
|
||||
}
|
||||
|
||||
group("socketpair") {
|
||||
public_deps = [ "socketpair:socketpair" ]
|
||||
}
|
||||
@ -41,34 +29,6 @@ group("test_header") {
|
||||
public_deps = [ "test_header:test_header" ]
|
||||
}
|
||||
|
||||
group("option_parser") {
|
||||
public_deps = [ "option_parser:option_parser" ]
|
||||
}
|
||||
|
||||
group("libgslogger") {
|
||||
public_deps = [ "gslogger:libgslogger" ]
|
||||
}
|
||||
|
||||
group("matrix") {
|
||||
public_deps = [ "matrix:matrix" ]
|
||||
}
|
||||
|
||||
group("raw_parser") {
|
||||
public_deps = [ "raw_parser:raw_parser" ]
|
||||
}
|
||||
|
||||
group("cpudraw") {
|
||||
public_deps = [ "cpudraw:cpudraw" ]
|
||||
}
|
||||
|
||||
group("gl_utils") {
|
||||
public_deps = [ "gl_utils:gl_utils" ]
|
||||
}
|
||||
|
||||
group("raw_maker") {
|
||||
public_deps = [ "raw_maker:raw_maker" ]
|
||||
}
|
||||
|
||||
group("sandbox_utils") {
|
||||
public_deps = [ "sandbox:sandbox_utils" ]
|
||||
}
|
||||
@ -95,17 +55,7 @@ ohos_shared_library("libgraphic_utils") {
|
||||
|
||||
deps = [
|
||||
":color_manager",
|
||||
":cpudraw",
|
||||
":gl_utils",
|
||||
":libgslogger",
|
||||
":matrix",
|
||||
":option_parser",
|
||||
":promise",
|
||||
":raw_maker",
|
||||
":raw_parser",
|
||||
":sandbox_utils",
|
||||
":scoped_bytrace",
|
||||
":semaphore",
|
||||
":test_header",
|
||||
]
|
||||
|
||||
|
@ -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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build cpudraw.a {{{
|
||||
config("cpudraw_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("cpudraw_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("cpudraw") {
|
||||
sources = [ "src/cpudraw.cpp" ]
|
||||
|
||||
configs = [ ":cpudraw_config" ]
|
||||
|
||||
public_configs = [ ":cpudraw_public_config" ]
|
||||
|
||||
deps = [ "..:scoped_bytrace" ]
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
}
|
||||
## Build cpudraw.a }}}
|
@ -1,54 +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 UTILS_INCLUDE_CPUDRAW_EXPORT_CPUDRAW_H
|
||||
#define UTILS_INCLUDE_CPUDRAW_EXPORT_CPUDRAW_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct CpudrawRect {
|
||||
double x;
|
||||
double y;
|
||||
double w;
|
||||
double h;
|
||||
|
||||
bool Contain(int32_t x2, int32_t y2);
|
||||
};
|
||||
|
||||
class Cpudraw {
|
||||
public:
|
||||
Cpudraw(uint32_t *vaddr, int32_t width, int32_t height);
|
||||
|
||||
void SetColor(const uint32_t &color);
|
||||
void SetBorder(const int32_t &border);
|
||||
|
||||
void DrawBorder(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h);
|
||||
void DrawBorder(const struct CpudrawRect &rect);
|
||||
|
||||
void DrawRect(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h);
|
||||
void DrawRect(const struct CpudrawRect &rect);
|
||||
|
||||
private:
|
||||
int32_t Min(const int32_t &a, const int32_t &b);
|
||||
int32_t Max(const int32_t &a, const int32_t &b);
|
||||
|
||||
uint32_t *addr = nullptr;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
uint32_t color = 0xffffffff;
|
||||
int32_t border = 0;
|
||||
};
|
||||
|
||||
#endif // UTILS_INCLUDE_CPUDRAW_EXPORT_CPUDRAW_H
|
@ -1,77 +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 "cpudraw.h"
|
||||
|
||||
#include <scoped_bytrace.h>
|
||||
|
||||
bool CpudrawRect::Contain(int32_t x2, int32_t y2)
|
||||
{
|
||||
return x <= x2 && x2 <= x + w && y <= y2 && y2 <= y + h;
|
||||
}
|
||||
|
||||
Cpudraw::Cpudraw(uint32_t *vaddr, int32_t width, int32_t height)
|
||||
: addr(vaddr), width(width), height(height)
|
||||
{
|
||||
}
|
||||
|
||||
void Cpudraw::SetColor(const uint32_t &color)
|
||||
{
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
void Cpudraw::SetBorder(const int32_t &border)
|
||||
{
|
||||
this->border = border;
|
||||
}
|
||||
|
||||
void Cpudraw::DrawBorder(const struct CpudrawRect &rect)
|
||||
{
|
||||
DrawBorder(rect.x, rect.y, rect.w, rect.h);
|
||||
}
|
||||
|
||||
void Cpudraw::DrawBorder(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h)
|
||||
{
|
||||
ScopedBytrace trace(__func__);
|
||||
DrawRect(x, y, border, h);
|
||||
DrawRect(x + w - border, y, border, h);
|
||||
DrawRect(x, y, w, border);
|
||||
DrawRect(x, y + h - border, w, border);
|
||||
}
|
||||
|
||||
void Cpudraw::DrawRect(const struct CpudrawRect &rect)
|
||||
{
|
||||
DrawRect(rect.x, rect.y, rect.w, rect.h);
|
||||
}
|
||||
|
||||
void Cpudraw::DrawRect(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h)
|
||||
{
|
||||
ScopedBytrace trace(__func__);
|
||||
for (int32_t j = Max(y, 0); j < Min(y + h, height); j++) {
|
||||
for (int32_t i = Max(x, 0); i < Min(x + w, width); i++) {
|
||||
addr[j * width + i] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Cpudraw::Min(const int32_t &a, const int32_t &b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
int32_t Cpudraw::Max(const int32_t &a, const int32_t &b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
@ -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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/graphic/graphic_2d/graphic_config.gni")
|
||||
|
||||
## Build gl_utils.a {{{
|
||||
config("gl_utils_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
|
||||
if (!ace_enable_gpu) {
|
||||
cflags += [ "-Wno-unused-private-field" ]
|
||||
}
|
||||
}
|
||||
|
||||
config("gl_utils_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("gl_utils") {
|
||||
sources = []
|
||||
|
||||
if (ace_enable_gpu) {
|
||||
sources += [
|
||||
"src/shader.cpp",
|
||||
"src/texture.cpp",
|
||||
]
|
||||
} else {
|
||||
sources += [
|
||||
"src/mock/shader.cpp",
|
||||
"src/mock/texture.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
configs = [ ":gl_utils_config" ]
|
||||
|
||||
public_configs = [ ":gl_utils_public_config" ]
|
||||
|
||||
public_deps = [
|
||||
"$graphic_2d_root/frameworks/opengl_wrapper:EGL",
|
||||
"$graphic_2d_root/frameworks/opengl_wrapper:GLESv3",
|
||||
"..:libgslogger",
|
||||
"..:matrix",
|
||||
]
|
||||
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
## Build gl_utils.a }}}
|
@ -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_ANIMATION_SERVER_SERVER_INCLUDE_SHADER_H
|
||||
#define FRAMEWORKS_ANIMATION_SERVER_SERVER_INCLUDE_SHADER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
#include <matrix.h>
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
Shader(const std::string& vertexSource, const std::string& fragmentSource);
|
||||
~Shader();
|
||||
|
||||
bool Available();
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
|
||||
void SetUniform1i(const std::string& name, int32_t v);
|
||||
void SetUniform1f(const std::string& name, float v);
|
||||
void SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3);
|
||||
void SetUniformMat4f(const std::string& name, const Matrix<float>& matrix);
|
||||
|
||||
int32_t GetAttribLocation(const std::string& name);
|
||||
|
||||
private:
|
||||
int32_t GetUniformLocation(const std::string& name);
|
||||
uint32_t CompileShader(uint32_t type, const std::string& source);
|
||||
uint32_t CreateShader(const std::string& vertexShader, const std::string& fragmentShader);
|
||||
|
||||
uint32_t rendererID_ = 0;
|
||||
std::unordered_map<std::string, int32_t> uniformLocationCache_;
|
||||
};
|
||||
|
||||
#endif // FRAMEWORKS_ANIMATION_SERVER_SERVER_INCLUDE_SHADER_H
|
@ -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_ANIMATION_SERVER_SERVER_INCLUDE_TEXTURE_H
|
||||
#define FRAMEWORKS_ANIMATION_SERVER_SERVER_INCLUDE_TEXTURE_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
// from buffer
|
||||
Texture(void *buffer, int32_t width, int32_t height);
|
||||
|
||||
// from texture
|
||||
Texture(uint32_t texture);
|
||||
~Texture();
|
||||
|
||||
void Bind(uint32_t slot = 0) const;
|
||||
void Unbind();
|
||||
|
||||
inline int32_t GetWidth() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
inline int32_t GetHeight() const
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t rendererID_ = 0;
|
||||
void *buffer_ = nullptr;
|
||||
int32_t width_ = 0;
|
||||
int32_t height_ = 0;
|
||||
};
|
||||
|
||||
#endif // FRAMEWORKS_ANIMATION_SERVER_SERVER_INCLUDE_TEXTURE_H
|
@ -1,73 +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 "shader.h"
|
||||
|
||||
Shader::Shader(const std::string& vertexSource, const std::string& fragmentSource)
|
||||
{
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
}
|
||||
|
||||
bool Shader::Available()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Shader::Bind() const
|
||||
{
|
||||
}
|
||||
|
||||
void Shader::Unbind() const
|
||||
{
|
||||
}
|
||||
|
||||
void Shader::SetUniform1i(const std::string& name, int32_t v)
|
||||
{
|
||||
}
|
||||
|
||||
void Shader::SetUniform1f(const std::string& name, float v)
|
||||
{
|
||||
}
|
||||
|
||||
void Shader::SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
}
|
||||
|
||||
void Shader::SetUniformMat4f(const std::string& name, const Matrix<float>& matrix)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t Shader::GetAttribLocation(const std::string& name)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t Shader::GetUniformLocation(const std::string& name)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t Shader::CompileShader(uint32_t type, const std::string& source)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t Shader::CreateShader(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
{
|
||||
return -1;
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
Texture::Texture(void *buffer, int32_t width, int32_t height)
|
||||
: buffer_(buffer), width_(width), height_(height)
|
||||
{
|
||||
}
|
||||
|
||||
Texture::Texture(uint32_t texture)
|
||||
{
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
}
|
||||
|
||||
void Texture::Bind(uint32_t slot) const
|
||||
{
|
||||
}
|
||||
|
||||
void Texture::Unbind()
|
||||
{
|
||||
}
|
@ -1,159 +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 "shader.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <gslogger.h>
|
||||
|
||||
namespace {
|
||||
DEFINE_HILOG_LABEL("Shader");
|
||||
} // namespace
|
||||
|
||||
Shader::Shader(const std::string& vertexSource, const std::string& fragmentSource)
|
||||
{
|
||||
rendererID_ = CreateShader(vertexSource, fragmentSource);
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
if (rendererID_ != 0) {
|
||||
glDeleteProgram(rendererID_);
|
||||
}
|
||||
}
|
||||
|
||||
bool Shader::Available()
|
||||
{
|
||||
return rendererID_ != 0;
|
||||
}
|
||||
|
||||
void Shader::Bind() const
|
||||
{
|
||||
glUseProgram(rendererID_);
|
||||
}
|
||||
|
||||
void Shader::Unbind() const
|
||||
{
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void Shader::SetUniform1i(const std::string& name, int32_t v)
|
||||
{
|
||||
glUniform1i(GetUniformLocation(name), v);
|
||||
}
|
||||
|
||||
void Shader::SetUniform1f(const std::string& name, float v)
|
||||
{
|
||||
glUniform1f(GetUniformLocation(name), v);
|
||||
}
|
||||
|
||||
void Shader::SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
glUniform4f(GetUniformLocation(name), v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
void Shader::SetUniformMat4f(const std::string& name, const Matrix<float>& matrix)
|
||||
{
|
||||
glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
}
|
||||
|
||||
int32_t Shader::GetAttribLocation(const std::string& name)
|
||||
{
|
||||
return glGetAttribLocation(rendererID_, name.c_str());
|
||||
}
|
||||
|
||||
int32_t Shader::GetUniformLocation(const std::string& name)
|
||||
{
|
||||
if (uniformLocationCache_.find(name) != uniformLocationCache_.end()) {
|
||||
return uniformLocationCache_[name];
|
||||
}
|
||||
auto location = glGetUniformLocation(rendererID_, name.c_str());
|
||||
if (location == -1) {
|
||||
GSLOG2HI(WARN) << "Warning: uniform '" << name << "' doesn't exist!" << std::endl;
|
||||
}
|
||||
|
||||
uniformLocationCache_[name] = location;
|
||||
return location;
|
||||
}
|
||||
|
||||
uint32_t Shader::CompileShader(uint32_t type, const std::string& source)
|
||||
{
|
||||
auto id = glCreateShader(type);
|
||||
auto src = source.c_str();
|
||||
glShaderSource(id, 1, &src, nullptr);
|
||||
glCompileShader(id);
|
||||
|
||||
auto result = GL_FALSE;
|
||||
glGetShaderiv(id, GL_COMPILE_STATUS, &result);
|
||||
if (result == GL_FALSE) {
|
||||
int32_t length = 0;
|
||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length < 0) {
|
||||
GSLOG2HI(ERROR) << "CompileShader Failed length is not right";
|
||||
return 0;
|
||||
}
|
||||
char* message = static_cast<char*>(malloc(length));
|
||||
if (message == nullptr) {
|
||||
GSLOG2HI(ERROR) << "CompileShader Failed malloc failed";
|
||||
return 0;
|
||||
}
|
||||
glGetShaderInfoLog(id, length, &length, message);
|
||||
GSLOG2HI(ERROR) << "CompileShader[" << type << "] Failed: " << message;
|
||||
glDeleteShader(id);
|
||||
free(message);
|
||||
message = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
uint32_t Shader::CreateShader(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
{
|
||||
auto program = glCreateProgram();
|
||||
auto vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
|
||||
auto fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
|
||||
|
||||
glAttachShader(program, vs);
|
||||
glAttachShader(program, fs);
|
||||
glLinkProgram(program);
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
|
||||
auto result = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &result);
|
||||
if (result == GL_FALSE) {
|
||||
int32_t length = 0;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length < 0) {
|
||||
GSLOG2HI(ERROR) << "CreateShader Failed length is not right";
|
||||
return 0;
|
||||
}
|
||||
char* message = static_cast<char*>(malloc(length));
|
||||
if (message == nullptr) {
|
||||
GSLOG2HI(ERROR) << "CreateShader Failed malloc failed";
|
||||
return 0;
|
||||
}
|
||||
glGetProgramInfoLog(program, length, nullptr, message);
|
||||
GSLOG2HI(ERROR) << "program error[" << glGetError() << "]: " << message;
|
||||
free(message);
|
||||
message = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSLOG2HI(INFO) << "Shader create success " << program;
|
||||
return program;
|
||||
}
|
@ -1,58 +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 "texture.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <gslogger.h>
|
||||
|
||||
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_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_);
|
||||
}
|
||||
|
||||
Texture::Texture(uint32_t texture)
|
||||
{
|
||||
rendererID_ = texture;
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
glDeleteTextures(1, &rendererID_);
|
||||
}
|
||||
|
||||
void Texture::Bind(uint32_t slot) const
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + slot);
|
||||
glBindTexture(GL_TEXTURE_2D, rendererID_);
|
||||
}
|
||||
|
||||
void Texture::Unbind()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
@ -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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build libgslogger.a {{{
|
||||
config("libgslogger_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("libgslogger_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("libgslogger") {
|
||||
sources = [ "src/gslogger.cpp" ]
|
||||
|
||||
configs = [ ":libgslogger_config" ]
|
||||
|
||||
public_configs = [ ":libgslogger_public_config" ]
|
||||
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
## Build libgslogger.a }}}
|
@ -1,161 +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 UTILS_INCLUDE_LOGGER_EXPORT_GSLOGGER_H
|
||||
#define UTILS_INCLUDE_LOGGER_EXPORT_GSLOGGER_H
|
||||
|
||||
#include <any>
|
||||
#include <cstdarg>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
class Gslogger : public std::stringstream {
|
||||
public:
|
||||
enum class LOG_LEVEL { DEBUG, INFO, WARN, ERROR, FATAL };
|
||||
enum class LOG_PHASE { BEGIN, END };
|
||||
|
||||
using GsloggerWrapperFunc = void(*)(Gslogger &, enum LOG_PHASE phase);
|
||||
// output GsloggerWrapperFunc
|
||||
static void Stdout(Gslogger &logger, enum LOG_PHASE phase);
|
||||
static void Stderr(Gslogger &logger, enum LOG_PHASE phase);
|
||||
static void Hilog(Gslogger &logger, enum LOG_PHASE phase);
|
||||
static void FileLog(Gslogger &logger, enum LOG_PHASE phase);
|
||||
|
||||
// wrapper GsloggerWrapperFunc
|
||||
static void Func(Gslogger &logger, enum LOG_PHASE phase); // 1
|
||||
static void FuncLine(Gslogger &logger, enum LOG_PHASE phase); // 2
|
||||
static void FileLine(Gslogger &logger, enum LOG_PHASE phase); // 3
|
||||
static void FileFuncLine(Gslogger &logger, enum LOG_PHASE phase); // 4
|
||||
static void PidTid(Gslogger &logger, enum LOG_PHASE phase); // +5
|
||||
|
||||
Gslogger(const std::string &file, const std::string &func, int line, enum LOG_LEVEL level, ...);
|
||||
virtual ~Gslogger() override;
|
||||
|
||||
const std::string &GetFile() const;
|
||||
const std::string &GetFunc() const;
|
||||
int GetLine() const;
|
||||
enum LOG_LEVEL GetLevel() const;
|
||||
va_list &GetVariousArgument();
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> GetData()
|
||||
{
|
||||
using sptrT = std::shared_ptr<T>;
|
||||
sptrT ret = nullptr;
|
||||
auto pRet = std::any_cast<sptrT>(&data_);
|
||||
if (pRet != nullptr) {
|
||||
ret = *pRet;
|
||||
} else {
|
||||
ret = std::make_shared<T>();
|
||||
data_ = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string file_;
|
||||
std::string func_;
|
||||
int line_;
|
||||
enum LOG_LEVEL level_;
|
||||
va_list vl_;
|
||||
std::any data_;
|
||||
std::vector<GsloggerWrapperFunc> wrappers_;
|
||||
};
|
||||
|
||||
#define LOGGER_ARG(level) __FILE__, __func__, __LINE__, (Gslogger::LOG_LEVEL::level)
|
||||
|
||||
// hilog
|
||||
#define DEFINE_HILOG_LABEL(str) \
|
||||
namespace { constexpr const char *HILOG_LABEL = str; }
|
||||
#define GSLOG0HI(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Hilog, HILOG_LABEL, NULL)
|
||||
#define GSLOG1HI(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Func, Gslogger::Hilog, HILOG_LABEL, NULL)
|
||||
#define GSLOG2HI(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FuncLine, Gslogger::Hilog, HILOG_LABEL, NULL)
|
||||
#define GSLOG3HI(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileLine, Gslogger::Hilog, HILOG_LABEL, NULL)
|
||||
#define GSLOG4HI(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileFuncLine, Gslogger::Hilog, HILOG_LABEL, NULL)
|
||||
|
||||
// stdout
|
||||
#define GSLOG0SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Stdout, NULL)
|
||||
#define GSLOG1SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Func, Gslogger::Stdout, NULL)
|
||||
#define GSLOG2SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FuncLine, Gslogger::Stdout, NULL)
|
||||
#define GSLOG3SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileLine, Gslogger::Stdout, NULL)
|
||||
#define GSLOG4SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileFuncLine, Gslogger::Stdout, NULL)
|
||||
#define GSLOG5SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::Stdout, NULL)
|
||||
#define GSLOG6SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::Func, Gslogger::Stdout, NULL)
|
||||
#define GSLOG7SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FuncLine, Gslogger::Stdout, NULL)
|
||||
#define GSLOG8SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileLine, Gslogger::Stdout, NULL)
|
||||
#define GSLOG9SO(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileFuncLine, Gslogger::Stdout, NULL)
|
||||
|
||||
// stderr
|
||||
#define GSLOG0SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Stderr, NULL)
|
||||
#define GSLOG1SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Func, Gslogger::Stderr, NULL)
|
||||
#define GSLOG2SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FuncLine, Gslogger::Stderr, NULL)
|
||||
#define GSLOG3SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileLine, Gslogger::Stderr, NULL)
|
||||
#define GSLOG4SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileFuncLine, Gslogger::Stderr, NULL)
|
||||
#define GSLOG5SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::Stderr, NULL)
|
||||
#define GSLOG6SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::Func, Gslogger::Stderr, NULL)
|
||||
#define GSLOG7SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FuncLine, Gslogger::Stderr, NULL)
|
||||
#define GSLOG8SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileLine, Gslogger::Stderr, NULL)
|
||||
#define GSLOG9SE(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileFuncLine, Gslogger::Stderr, NULL)
|
||||
|
||||
// filelog
|
||||
#define DEFINE_FILE_LABEL(str) \
|
||||
namespace { constexpr const char *FILE_LABEL = str; }
|
||||
#define GSLOG0F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG1F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::Func, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG2F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FuncLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG3F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG4F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::FileFuncLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG5F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG6F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::Func, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG7F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FuncLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG8F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
#define GSLOG9F(level) Gslogger(LOGGER_ARG(level), \
|
||||
Gslogger::PidTid, Gslogger::FileFuncLine, Gslogger::FileLog, FILE_LABEL, NULL)
|
||||
|
||||
#endif // UTILS_INCLUDE_LOGGER_EXPORT_GSLOGGER_H
|
@ -1,206 +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 "gslogger.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <hilog/log.h>
|
||||
|
||||
namespace {
|
||||
const char *GetLevelStr(enum Gslogger::LOG_LEVEL level)
|
||||
{
|
||||
switch (level) {
|
||||
case Gslogger::LOG_LEVEL::DEBUG: return "D";
|
||||
case Gslogger::LOG_LEVEL::INFO: return "I";
|
||||
case Gslogger::LOG_LEVEL::WARN: return "W";
|
||||
case Gslogger::LOG_LEVEL::ERROR: return "E";
|
||||
case Gslogger::LOG_LEVEL::FATAL: return "F";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Gslogger::Stdout(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// LOG_PHASE::END
|
||||
std::cout << "[" << GetLevelStr(logger.GetLevel()) << "] " << logger.str() << std::endl;
|
||||
}
|
||||
|
||||
void Gslogger::Stderr(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// LOG_PHASE::END
|
||||
std::cerr << "[" << GetLevelStr(logger.GetLevel()) << "] " << logger.str() << std::endl;
|
||||
}
|
||||
|
||||
void Gslogger::Hilog(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
struct HilogData {
|
||||
OHOS::HiviewDFX::HiLogLabel hiLogLabel;
|
||||
};
|
||||
auto data = logger.GetData<struct HilogData>();
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
auto label = va_arg(logger.GetVariousArgument(), const char *);
|
||||
data->hiLogLabel = { LOG_CORE, 0, label };
|
||||
return;
|
||||
}
|
||||
|
||||
// LOG_PHASE::END
|
||||
auto fn = OHOS::HiviewDFX::HiLog::Debug;
|
||||
switch (logger.GetLevel()) {
|
||||
case LOG_LEVEL::DEBUG:
|
||||
fn = OHOS::HiviewDFX::HiLog::Debug;
|
||||
break;
|
||||
case LOG_LEVEL::INFO:
|
||||
fn = OHOS::HiviewDFX::HiLog::Info;
|
||||
break;
|
||||
case LOG_LEVEL::WARN:
|
||||
fn = OHOS::HiviewDFX::HiLog::Warn;
|
||||
break;
|
||||
case LOG_LEVEL::ERROR:
|
||||
fn = OHOS::HiviewDFX::HiLog::Error;
|
||||
break;
|
||||
case LOG_LEVEL::FATAL:
|
||||
fn = OHOS::HiviewDFX::HiLog::Fatal;
|
||||
break;
|
||||
}
|
||||
fn(data->hiLogLabel, "%{public}s", logger.str().c_str());
|
||||
}
|
||||
|
||||
void Gslogger::FileLog(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
struct FileLogData {
|
||||
const char *filename;
|
||||
};
|
||||
auto data = logger.GetData<struct FileLogData>();
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
auto filename = va_arg(logger.GetVariousArgument(), const char *);
|
||||
data->filename = filename;
|
||||
return;
|
||||
}
|
||||
|
||||
char path[PATH_MAX + 1] = { 0x00 };
|
||||
if (strlen(data->filename) > PATH_MAX || realpath(data->filename, path) == NULL) {
|
||||
std::cerr << "File path error!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// LOG_PHASE::END
|
||||
std::ofstream ofs(path, std::ofstream::out | std::ofstream::app);
|
||||
if (!ofs) {
|
||||
// open failed, errno
|
||||
return;
|
||||
}
|
||||
|
||||
if (ofs) {
|
||||
ofs << "[" << GetLevelStr(logger.GetLevel()) << "] " << logger.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Gslogger::Func(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
logger << "[" << logger.GetFunc() << "] ";
|
||||
}
|
||||
}
|
||||
|
||||
void Gslogger::FuncLine(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
logger << "[" << logger.GetFunc() << ":" << logger.GetLine() << "] ";
|
||||
}
|
||||
}
|
||||
|
||||
void Gslogger::FileLine(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
logger << "[" << logger.GetFile() << " +" << logger.GetLine() << "] ";
|
||||
}
|
||||
}
|
||||
|
||||
void Gslogger::FileFuncLine(Gslogger& logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
logger << "[" << logger.GetFile() << " +" << logger.GetLine() << ":" << logger.GetFunc() << "] ";
|
||||
}
|
||||
}
|
||||
|
||||
void Gslogger::PidTid(Gslogger &logger, enum LOG_PHASE phase)
|
||||
{
|
||||
if (phase == LOG_PHASE::BEGIN) {
|
||||
logger << "[" << getpid() << "][" << gettid() << "]";
|
||||
}
|
||||
}
|
||||
|
||||
Gslogger::Gslogger(const std::string &file, const std::string &func, int line, enum LOG_LEVEL level, ...)
|
||||
{
|
||||
file_ = file;
|
||||
func_ = func;
|
||||
line_ = line;
|
||||
level_ = level;
|
||||
va_start(vl_, level);
|
||||
|
||||
while (true) {
|
||||
GsloggerWrapperFunc f = va_arg(vl_, GsloggerWrapperFunc);
|
||||
if (f == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
f(*this, LOG_PHASE::BEGIN);
|
||||
wrappers_.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
Gslogger::~Gslogger()
|
||||
{
|
||||
for (const auto &wrapper : wrappers_) {
|
||||
wrapper(*this, LOG_PHASE::END);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &Gslogger::GetFile() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
|
||||
const std::string &Gslogger::GetFunc() const
|
||||
{
|
||||
return func_;
|
||||
}
|
||||
|
||||
int Gslogger::GetLine() const
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
|
||||
enum Gslogger::LOG_LEVEL Gslogger::GetLevel() const
|
||||
{
|
||||
return level_;
|
||||
}
|
||||
|
||||
va_list &Gslogger::GetVariousArgument()
|
||||
{
|
||||
return vl_;
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 optparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def parse_args(args):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--output")
|
||||
opts, _ = parser.parse_args(args)
|
||||
return opts
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = parse_args(sys.argv[1:])
|
||||
parse_scripts = subprocess.check_call(
|
||||
["cp", "-f", "/usr/include/FlexLexer.h", options.output])
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 optparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def parse_args(args):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--input")
|
||||
parser.add_option("--output")
|
||||
opts, _ = parser.parse_args(args)
|
||||
return opts
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = parse_args(sys.argv[1:])
|
||||
parse_scripts = subprocess.check_call(
|
||||
["flex", "--c++", "-o", options.output, options.input])
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 optparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def parse_args(args):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--input")
|
||||
parser.add_option("--output")
|
||||
opts, _ = parser.parse_args(args)
|
||||
return opts
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = parse_args(sys.argv[1:])
|
||||
parse_scripts = subprocess.check_call(
|
||||
["bison", "-Wnone", "-o", options.output, options.input])
|
@ -1,130 +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/ohos.gni")
|
||||
|
||||
gni_filepath = "//foundation/graphic/graphic_2d/utils/lex_yacc"
|
||||
|
||||
template("lex_yacc") {
|
||||
lex_name = invoker.lex
|
||||
yacc_name = invoker.yacc
|
||||
gen_flexlexer_name = "${target_name}_gen_flexlexer"
|
||||
gen_lex_name = "${target_name}_gen_lex"
|
||||
gen_yacc_name = "${target_name}_gen_yacc"
|
||||
gen_lex_yacc_name = "${target_name}_gen_lex_yacc"
|
||||
gen_config_name = "${target_name}_gen_config"
|
||||
|
||||
flexlexer_filename = "$root_gen_dir/$target_name/FlexLexer.h"
|
||||
flexlexer_pathname = rebase_path(flexlexer_filename, root_build_dir)
|
||||
action(gen_flexlexer_name) {
|
||||
script = "$gni_filepath/gen_flexlexer_header.py"
|
||||
inputs = [ script ]
|
||||
outputs = [ flexlexer_filename ]
|
||||
args = [
|
||||
"--output",
|
||||
flexlexer_pathname,
|
||||
]
|
||||
}
|
||||
|
||||
lex_filename = "$root_gen_dir/$target_name/lexer.yy.cc"
|
||||
lex_pathname = rebase_path(lex_filename, root_build_dir)
|
||||
action(gen_lex_name) {
|
||||
script = "$gni_filepath/gen_lex_cpp.py"
|
||||
lex_inputfile = rebase_path(lex_name, root_build_dir)
|
||||
|
||||
inputs = [
|
||||
script,
|
||||
lex_name,
|
||||
]
|
||||
outputs = [ lex_filename ]
|
||||
args = [
|
||||
"--input",
|
||||
lex_inputfile,
|
||||
"--output",
|
||||
lex_pathname,
|
||||
]
|
||||
}
|
||||
|
||||
yacc_filename = "$root_gen_dir/$target_name/parser.cpp"
|
||||
yacc_pathname = rebase_path(yacc_filename, root_build_dir)
|
||||
action(gen_yacc_name) {
|
||||
script = "$gni_filepath/gen_yacc_cpp.py"
|
||||
yacc_inputfile = rebase_path(yacc_name, root_build_dir)
|
||||
|
||||
inputs = [
|
||||
script,
|
||||
yacc_name,
|
||||
]
|
||||
outputs = [ yacc_filename ]
|
||||
args = [
|
||||
"--input",
|
||||
yacc_inputfile,
|
||||
"--output",
|
||||
yacc_pathname,
|
||||
]
|
||||
}
|
||||
|
||||
config(gen_config_name) {
|
||||
include_dirs = [
|
||||
".",
|
||||
"$root_gen_dir/$target_name",
|
||||
]
|
||||
cflags = [
|
||||
"-Wno-unused-private-field",
|
||||
"-Wno-header-hygiene",
|
||||
"-Wno-implicit-fallthrough",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library(gen_lex_yacc_name) {
|
||||
sources = [
|
||||
"$lex_filename",
|
||||
"$yacc_filename",
|
||||
]
|
||||
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"cflags",
|
||||
"include_dirs",
|
||||
"public_configs",
|
||||
"deps",
|
||||
"public_deps",
|
||||
])
|
||||
|
||||
if (!defined(configs)) {
|
||||
configs = []
|
||||
}
|
||||
if (defined(invoker.configs)) {
|
||||
configs += invoker.configs
|
||||
}
|
||||
|
||||
if (!defined(public_configs)) {
|
||||
public_configs = []
|
||||
}
|
||||
public_configs += [
|
||||
":$gen_config_name",
|
||||
"//build/config/compiler:rtti",
|
||||
"//build/config/compiler:exceptions",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":${gen_flexlexer_name}",
|
||||
":${gen_lex_name}",
|
||||
":${gen_yacc_name}",
|
||||
]
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
public_deps = [ ":${gen_lex_yacc_name}" ]
|
||||
}
|
||||
}
|
@ -1,22 +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/ohos.gni")
|
||||
|
||||
config("matrix_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
group("matrix") {
|
||||
public_configs = [ ":matrix_public_config" ]
|
||||
}
|
@ -1,149 +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 UTILS_MATRIX_EXPORT_MATRIX_H
|
||||
#define UTILS_MATRIX_EXPORT_MATRIX_H
|
||||
|
||||
#include <math.h>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
template<class T = float>
|
||||
class Matrix {
|
||||
public:
|
||||
static inline constexpr int32_t rowcol = 4;
|
||||
static inline constexpr int32_t units = rowcol * rowcol;
|
||||
|
||||
static Matrix<T> UnitMatrix()
|
||||
{
|
||||
Matrix<T> retval;
|
||||
for (int32_t i = 0; i < units; i++) {
|
||||
retval.ptr[i] = 0;
|
||||
}
|
||||
retval.ele(0x0, 0x0) = 0x1;
|
||||
retval.ele(0x1, 0x1) = 0x1;
|
||||
retval.ele(0x2, 0x2) = 0x1;
|
||||
retval.ele(0x3, 0x3) = 0x1;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static Matrix<T> TranslateMatrix(T x, T y, T z = 0)
|
||||
{
|
||||
Matrix<T> retval = UnitMatrix();
|
||||
retval.ele(0x0, 0x3) = x;
|
||||
retval.ele(0x1, 0x3) = y;
|
||||
retval.ele(0x2, 0x3) = z;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static Matrix<T> ScaleMatrix(T x, T y, T z = 1)
|
||||
{
|
||||
Matrix<T> retval = UnitMatrix();
|
||||
retval.ele(0x0, 0x0) *= x;
|
||||
retval.ele(0x1, 0x1) *= y;
|
||||
retval.ele(0x2, 0x2) *= z;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static Matrix<T> RotateMatrixZ(double angle)
|
||||
{
|
||||
Matrix<T> retval = UnitMatrix();
|
||||
double rad = angle * acos(-1) / 180.0;
|
||||
retval.ele(0x0, 0x0) = cos(rad);
|
||||
retval.ele(0x0, 0x1) = -sin(rad);
|
||||
retval.ele(0x1, 0x0) = sin(rad);
|
||||
retval.ele(0x1, 0x1) = cos(rad);
|
||||
return retval;
|
||||
}
|
||||
|
||||
Matrix() = default;
|
||||
|
||||
Matrix(const Matrix<T> &m)
|
||||
{
|
||||
for (int32_t i = 0; i < units; i++) {
|
||||
ptr[i] = m.ptr[i];
|
||||
}
|
||||
}
|
||||
|
||||
Matrix(Matrix<T> &&m)
|
||||
{
|
||||
ptr = std::move(m.ptr);
|
||||
}
|
||||
|
||||
Matrix<T> &operator =(const Matrix<T> &m)
|
||||
{
|
||||
for (int32_t i = 0; i < units; i++) {
|
||||
ptr[i] = m.ptr[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Matrix<T> operator *(const Matrix<T> other)
|
||||
{
|
||||
Matrix<T> retval;
|
||||
for (int i = 0; i < rowcol; i++) {
|
||||
for (int j = 0; j < rowcol; j++) {
|
||||
retval.ele(i, j) = 0;
|
||||
for (int k = 0; k < rowcol; k++) {
|
||||
retval.ele(i, j) += ele(i, k) * other.ele(k, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
operator T*() const
|
||||
{
|
||||
return ptr.get();
|
||||
}
|
||||
|
||||
friend std::ostream &operator <<(std::ostream &os, const Matrix<T> &m)
|
||||
{
|
||||
os << std::endl;
|
||||
os << "Matrix {" << std::endl;
|
||||
os << " [" << m.ele(0x0, 0x0) << "] ["
|
||||
<< m.ele(0x0, 0x1) << "] ["
|
||||
<< m.ele(0x0, 0x2) << "] ["
|
||||
<< m.ele(0x0, 0x3) << "]"
|
||||
<< std::endl;
|
||||
os << " [" << m.ele(0x1, 0x0) << "] ["
|
||||
<< m.ele(0x1, 0x1) << "] ["
|
||||
<< m.ele(0x1, 0x2) << "] ["
|
||||
<< m.ele(0x1, 0x3) << "]"
|
||||
<< std::endl;
|
||||
os << " [" << m.ele(0x2, 0x0) << "] ["
|
||||
<< m.ele(0x2, 0x1) << "] ["
|
||||
<< m.ele(0x2, 0x2) << "] ["
|
||||
<< m.ele(0x2, 0x3) << "]"
|
||||
<< std::endl;
|
||||
os << " [" << m.ele(0x3, 0x0) << "] ["
|
||||
<< m.ele(0x3, 0x1) << "] ["
|
||||
<< m.ele(0x3, 0x2) << "] ["
|
||||
<< m.ele(0x3, 0x3) << "]"
|
||||
<< std::endl;
|
||||
os << "}" << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
inline T &ele(int i, int j) const
|
||||
{
|
||||
return ptr[i + j * rowcol];
|
||||
}
|
||||
|
||||
std::unique_ptr<T[]> ptr = std::make_unique<T[]>(units);
|
||||
};
|
||||
|
||||
#endif // UTILS_MATRIX_EXPORT_MATRIX_H
|
@ -1,41 +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/ohos.gni")
|
||||
|
||||
## Build option_parser.a {{{
|
||||
config("option_parser_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("option_parser_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("option_parser") {
|
||||
sources = [ "src/option_parser.cpp" ]
|
||||
|
||||
configs = [ ":option_parser_config" ]
|
||||
|
||||
public_configs = [ ":option_parser_public_config" ]
|
||||
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
}
|
||||
## Build option_parser.a }}}
|
@ -1,166 +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 UTILS_OPTION_PARSER_EXPORT_OPTION_PARSER_H
|
||||
#define UTILS_OPTION_PARSER_EXPORT_OPTION_PARSER_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class OptionParser {
|
||||
public:
|
||||
int32_t Parse(int32_t argc, const char **argv);
|
||||
std::string GetErrorString();
|
||||
|
||||
template<typename T>
|
||||
int32_t AddOption(const std::string &shortOpt, const std::string &longOpt, T &result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<int32_t>(const std::string &shortOpt, const std::string &longOpt, int32_t &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::i32);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<uint32_t>(const std::string &shortOpt, const std::string &longOpt, uint32_t &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::u32);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<int64_t>(const std::string &shortOpt, const std::string &longOpt, int64_t &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::i64);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<double>(const std::string &shortOpt, const std::string &longOpt, double &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::f64);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<std::string>(const std::string &shortOpt, const std::string &longOpt, std::string &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::str);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddOption<bool>(const std::string &shortOpt, const std::string &longOpt, bool &result)
|
||||
{
|
||||
return AddOption(shortOpt, longOpt, &result, Option::ValueType::bol);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int32_t AddArguments(T &result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddArguments<int32_t>(int32_t &result)
|
||||
{
|
||||
return AddArguments(&result, Argument::ValueType::i32);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddArguments<uint32_t>(uint32_t &result)
|
||||
{
|
||||
return AddArguments(&result, Argument::ValueType::u32);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddArguments<int64_t>(int64_t &result)
|
||||
{
|
||||
return AddArguments(&result, Argument::ValueType::i64);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddArguments<double>(double &result)
|
||||
{
|
||||
return AddArguments(&result, Argument::ValueType::f64);
|
||||
}
|
||||
|
||||
template<>
|
||||
int32_t AddArguments<std::string>(std::string &result)
|
||||
{
|
||||
return AddArguments(&result, Argument::ValueType::str);
|
||||
}
|
||||
|
||||
int32_t GetSkippedArgc();
|
||||
const char **GetSkippedArgv();
|
||||
|
||||
private:
|
||||
int32_t ParseArgument(const char *arg, const char *arg2);
|
||||
int32_t ParseArgc(const char *arg, const char *arg2);
|
||||
int32_t ParseShortOption(const char *arg1, const char *arg2);
|
||||
int32_t ParseLongEqualOption(const char *arg, const char *arg2);
|
||||
int32_t ParseLongOption(const char *arg1, const char *arg2);
|
||||
int32_t AddSkipped(const char *arg, const char *arg2);
|
||||
|
||||
struct Option {
|
||||
const std::string so;
|
||||
const std::string lo;
|
||||
union Value {
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
double f64;
|
||||
std::string str;
|
||||
bool bl;
|
||||
} *result;
|
||||
enum class ValueType {
|
||||
i32,
|
||||
u32,
|
||||
i64,
|
||||
f64,
|
||||
str,
|
||||
bol,
|
||||
} type;
|
||||
};
|
||||
|
||||
int32_t AddOption(const std::string &shortOpt,
|
||||
const std::string &longOpt, void *result, Option::ValueType type);
|
||||
|
||||
struct Argument {
|
||||
union Value {
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
double f64;
|
||||
std::string str;
|
||||
} *result;
|
||||
enum class ValueType {
|
||||
i32,
|
||||
u32,
|
||||
i64,
|
||||
f64,
|
||||
str,
|
||||
} type;
|
||||
};
|
||||
|
||||
int32_t AddArguments(void *result, Argument::ValueType type);
|
||||
|
||||
std::list<struct Argument> arguments;
|
||||
std::vector<struct Option> options;
|
||||
std::vector<const char *> skipped;
|
||||
std::string error = "";
|
||||
};
|
||||
|
||||
#endif // UTILS_OPTION_PARSER_EXPORT_OPTION_PARSER_H
|
@ -1,282 +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 <option_parser.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
enum {
|
||||
PARSER_NEXT = 0,
|
||||
PARSER_ERROR = 1,
|
||||
PARSER_PARSED = 2,
|
||||
PARSER_PARSED_MORE = 3,
|
||||
};
|
||||
|
||||
int32_t OptionParser::ParseArgument(const char *arg, const char *arg2)
|
||||
{
|
||||
if (arguments.empty()) {
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
std::stringstream ss(arg);
|
||||
switch (arguments.front().type) {
|
||||
case Argument::ValueType::i32:
|
||||
ss >> std::setbase(0) >> arguments.front().result->i32;
|
||||
break;
|
||||
case Argument::ValueType::u32:
|
||||
ss >> std::setbase(0) >> arguments.front().result->u32;
|
||||
break;
|
||||
case Argument::ValueType::i64:
|
||||
ss >> std::setbase(0) >> arguments.front().result->i64;
|
||||
break;
|
||||
case Argument::ValueType::f64:
|
||||
ss >> arguments.front().result->f64;
|
||||
break;
|
||||
case Argument::ValueType::str:
|
||||
ss >> arguments.front().result->str;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ss.eof() || !ss) {
|
||||
error = "parse ";
|
||||
error = error + arg + " error";
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
|
||||
arguments.pop_front();
|
||||
return PARSER_PARSED;
|
||||
}
|
||||
|
||||
int32_t OptionParser::ParseArgc(const char *arg, const char *arg2)
|
||||
{
|
||||
if (arg[0] == 0) {
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
|
||||
if (arg[0] != '-') {
|
||||
skipped.push_back(arg);
|
||||
return PARSER_PARSED;
|
||||
}
|
||||
|
||||
if (arg[1] == 0) {
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
int32_t OptionParser::ParseShortOption(const char *arg1, const char *arg2)
|
||||
{
|
||||
if (arg1[1] == '-') {
|
||||
// long option
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
for (const auto &option : options) {
|
||||
if (option.so == &arg1[1]) {
|
||||
if (option.type == Option::ValueType::bol) {
|
||||
option.result->bl = !option.result->bl;
|
||||
return PARSER_PARSED;
|
||||
} else if (arg2 == nullptr) {
|
||||
error = option.so + " need argument";
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
|
||||
std::stringstream ss(arg2);
|
||||
switch (option.type) {
|
||||
case Option::ValueType::i32:
|
||||
ss >> std::setbase(0) >> option.result->i32;
|
||||
break;
|
||||
case Option::ValueType::u32:
|
||||
ss >> std::setbase(0) >> option.result->u32;
|
||||
break;
|
||||
case Option::ValueType::i64:
|
||||
ss >> std::setbase(0) >> option.result->i64;
|
||||
break;
|
||||
case Option::ValueType::f64:
|
||||
ss >> option.result->f64;
|
||||
break;
|
||||
case Option::ValueType::str:
|
||||
ss >> option.result->str;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ss.eof() || !ss) {
|
||||
error = "parse ";
|
||||
error = error + arg1 + " error, " + arg2;
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
|
||||
return PARSER_PARSED_MORE;
|
||||
}
|
||||
}
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
int32_t OptionParser::ParseLongEqualOption(const char *arg, const char *arg2)
|
||||
{
|
||||
if (arg[1] != '-') {
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
bool parsed = false;
|
||||
for (const char *c = arg; *c; c++) {
|
||||
if (*c == '=') {
|
||||
std::string arg1(arg, c - arg);
|
||||
std::string arg2(c + 1);
|
||||
ret = ParseLongOption(arg1.c_str(), arg2.c_str());
|
||||
parsed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == PARSER_ERROR || ret == PARSER_NEXT) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (parsed) {
|
||||
return PARSER_PARSED;
|
||||
}
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
int32_t OptionParser::ParseLongOption(const char *arg1, const char *arg2)
|
||||
{
|
||||
if (arg1[1] != '-') {
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
for (const auto &option : options) {
|
||||
if (option.lo == &arg1[0x2]) {
|
||||
if (option.type == Option::ValueType::bol) {
|
||||
option.result->bl = !option.result->bl;
|
||||
return PARSER_PARSED;
|
||||
} else if (arg2 == nullptr) {
|
||||
error = option.lo + " need argument";
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
|
||||
std::stringstream ss(arg2);
|
||||
switch (option.type) {
|
||||
case Option::ValueType::i32:
|
||||
ss >> std::setbase(0) >> option.result->i32;
|
||||
break;
|
||||
case Option::ValueType::u32:
|
||||
ss >> std::setbase(0) >> option.result->u32;
|
||||
break;
|
||||
case Option::ValueType::i64:
|
||||
ss >> std::setbase(0) >> option.result->i64;
|
||||
break;
|
||||
case Option::ValueType::f64:
|
||||
ss >> option.result->f64;
|
||||
break;
|
||||
case Option::ValueType::str:
|
||||
ss >> option.result->str;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ss.eof() || !ss) {
|
||||
error = "parse ";
|
||||
error = error + arg1 + " error, " + arg2;
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
return PARSER_PARSED_MORE;
|
||||
}
|
||||
}
|
||||
return PARSER_NEXT;
|
||||
}
|
||||
|
||||
int32_t OptionParser::AddSkipped(const char *arg, const char *arg2)
|
||||
{
|
||||
skipped.push_back(arg);
|
||||
return PARSER_PARSED;
|
||||
}
|
||||
|
||||
int32_t OptionParser::Parse(int32_t argc, const char **argv)
|
||||
{
|
||||
int32_t (OptionParser:: *parsers[])(const char *, const char *) = {
|
||||
&OptionParser::ParseArgument,
|
||||
&OptionParser::ParseArgc,
|
||||
&OptionParser::ParseShortOption,
|
||||
&OptionParser::ParseLongEqualOption,
|
||||
&OptionParser::ParseLongOption,
|
||||
&OptionParser::AddSkipped,
|
||||
};
|
||||
for (int32_t i = 0; i < argc; i++) {
|
||||
for (auto &parser : parsers) {
|
||||
auto ret = (this->*parser)(argv[i], argv[i + 1]);
|
||||
if (ret == PARSER_ERROR) {
|
||||
return ret;
|
||||
} else if (ret == PARSER_PARSED_MORE) {
|
||||
i++;
|
||||
break;
|
||||
} else if (ret == PARSER_PARSED) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!arguments.empty()) {
|
||||
error = "need more arguments";
|
||||
return 1;
|
||||
} else {
|
||||
skipped.push_back(nullptr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t OptionParser::AddOption(const std::string &shortOpt,
|
||||
const std::string &longOpt, void *result, Option::ValueType type)
|
||||
{
|
||||
struct Option option = {
|
||||
.so = shortOpt,
|
||||
.lo = longOpt,
|
||||
.result = reinterpret_cast<union Option::Value *>(result),
|
||||
.type = type,
|
||||
};
|
||||
options.emplace_back(std::move(option));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t OptionParser::AddArguments(void *result, Argument::ValueType type)
|
||||
{
|
||||
struct Argument argument = {
|
||||
.result = reinterpret_cast<union Argument::Value *>(result),
|
||||
.type = type,
|
||||
};
|
||||
arguments.emplace_back(std::move(argument));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string OptionParser::GetErrorString()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t OptionParser::GetSkippedArgc()
|
||||
{
|
||||
return skipped.size() - 1;
|
||||
}
|
||||
|
||||
const char **OptionParser::GetSkippedArgv()
|
||||
{
|
||||
return skipped.data();
|
||||
}
|
@ -1,22 +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/ohos.gni")
|
||||
|
||||
config("promise_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
group("promise") {
|
||||
public_configs = [ ":promise_public_config" ]
|
||||
}
|
@ -1,99 +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 UTILS_INCLUDE_PROMISE_H
|
||||
#define UTILS_INCLUDE_PROMISE_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
namespace OHOS {
|
||||
template<class T>
|
||||
class Promise : public RefBase {
|
||||
public:
|
||||
Promise() = default;
|
||||
Promise(const T& t);
|
||||
virtual ~Promise() = default;
|
||||
|
||||
virtual bool IsResolved() const;
|
||||
virtual const T &Await();
|
||||
virtual void Then(std::function<void(const T &t)> func);
|
||||
virtual bool Resolve(const T &t);
|
||||
|
||||
private:
|
||||
bool resolved = false;
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv;
|
||||
T value{};
|
||||
|
||||
std::function<void(const T &t)> onComplete = nullptr;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
Promise<T>::Promise(const T& t)
|
||||
{
|
||||
value = t;
|
||||
resolved = true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool Promise<T>::IsResolved() const
|
||||
{
|
||||
return resolved;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T &Promise<T>::Await()
|
||||
{
|
||||
if (resolved == false) {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
cv.wait(lock, [this]() { return resolved == true; });
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Promise<T>::Then(std::function<void(const T &t)> func)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (resolved == false) {
|
||||
onComplete = func;
|
||||
} else {
|
||||
func(value);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool Promise<T>::Resolve(const T &t)
|
||||
{
|
||||
if (resolved == false) {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (resolved == false) {
|
||||
value = t;
|
||||
resolved = true;
|
||||
cv.notify_all();
|
||||
if (onComplete != nullptr) {
|
||||
onComplete(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // UTILS_INCLUDE_PROMISE_H
|
@ -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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build raw_maker.a {{{
|
||||
config("raw_maker_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("raw_maker_public_config") {
|
||||
include_dirs = [
|
||||
"export",
|
||||
"../raw_parser/export",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("raw_maker") {
|
||||
sources = [ "src/raw_maker.cpp" ]
|
||||
|
||||
configs = [ ":raw_maker_config" ]
|
||||
|
||||
public_configs = [ ":raw_maker_public_config" ]
|
||||
|
||||
deps = [ "..:libgslogger" ]
|
||||
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"zlib:libz",
|
||||
]
|
||||
}
|
||||
## Build raw_maker.a }}}
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_MAKER_H
|
||||
#define FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_MAKER_H
|
||||
|
||||
#include <raw_parser.h>
|
||||
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
class RawMaker {
|
||||
public:
|
||||
void SetFilename(const std::string &filename);
|
||||
void SetWidth(uint32_t width);
|
||||
void SetHeight(uint32_t height);
|
||||
void SetHeaderType(RawHeaderType type);
|
||||
int32_t WriteNextData(const uint8_t *addr);
|
||||
|
||||
private:
|
||||
int32_t DoFirstFrame();
|
||||
int32_t PrepareInNone();
|
||||
int32_t PrepareInRaw(const uint8_t *addr);
|
||||
int32_t PrepareInCompress(const uint8_t *addr);
|
||||
int32_t UpdateLastFrame(const uint8_t *addr);
|
||||
int32_t WriteData();
|
||||
void WriteInt32(int32_t integer);
|
||||
void CompareWithLastFrame(const uint8_t *addr);
|
||||
|
||||
std::string filename = "";
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
int32_t size = 0;
|
||||
RawHeaderType type = RAW_HEADER_TYPE_NONE;
|
||||
bool firstFrame = true;
|
||||
std::ofstream ofs;
|
||||
std::unique_ptr<uint8_t[]> lastFrame;
|
||||
std::unique_ptr<uint8_t[]> compressed;
|
||||
|
||||
struct {
|
||||
RawHeaderType type;
|
||||
int32_t offset;
|
||||
int32_t length;
|
||||
int32_t compressedLength;
|
||||
const uint8_t *data;
|
||||
} writing;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_MAKER_H
|
@ -1,212 +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 "raw_maker.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <string>
|
||||
|
||||
#include <gslogger.h>
|
||||
#include <securec.h>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
DEFINE_HILOG_LABEL("RawMaker");
|
||||
} // namespace
|
||||
|
||||
void RawMaker::SetFilename(const std::string &filename)
|
||||
{
|
||||
if (firstFrame) {
|
||||
this->filename = filename;
|
||||
}
|
||||
if (this->filename != filename) {
|
||||
GSLOG2HI(ERROR) << "RawMaker::SetFilename now filename is different to first frame filename";
|
||||
}
|
||||
}
|
||||
|
||||
void RawMaker::SetWidth(uint32_t width)
|
||||
{
|
||||
if (firstFrame) {
|
||||
this->width = width;
|
||||
}
|
||||
if (this->width != width) {
|
||||
GSLOG2HI(ERROR) << "RawMaker::SetWidth now width is different to first frame width";
|
||||
}
|
||||
size = static_cast<int32_t>(width * height * 0x4);
|
||||
}
|
||||
|
||||
void RawMaker::SetHeight(uint32_t height)
|
||||
{
|
||||
if (firstFrame) {
|
||||
this->height = height;
|
||||
}
|
||||
if (this->height != height) {
|
||||
GSLOG2HI(ERROR) << "RawMaker::SetHeight now height is different to first frame height";
|
||||
}
|
||||
size = static_cast<int32_t>(width * height * 0x4);
|
||||
}
|
||||
|
||||
void RawMaker::SetHeaderType(RawHeaderType type)
|
||||
{
|
||||
this->type = type;
|
||||
if (type != RAW_HEADER_TYPE_NONE) {
|
||||
GSLOG2HI(ERROR) << "RawMaker::SetHeaderType now type is not RAW_HEADER_TYPE_NONE";
|
||||
}
|
||||
}
|
||||
|
||||
int32_t RawMaker::WriteNextData(const uint8_t *addr)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
if (firstFrame) {
|
||||
ret = DoFirstFrame();
|
||||
writing.offset = 0;
|
||||
writing.length = size;
|
||||
} else {
|
||||
CompareWithLastFrame(addr);
|
||||
}
|
||||
|
||||
ofs.open(filename, std::ofstream::app | std::ofstream::binary | std::ofstream::out);
|
||||
if (errno) {
|
||||
GSLOG2HI(ERROR) << "open " << filename << ", because " << strerror(errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (writing.length == 0) {
|
||||
ret = PrepareInNone();
|
||||
} else if (type == RAW_HEADER_TYPE_RAW) {
|
||||
ret = PrepareInRaw(addr);
|
||||
} else if (type == RAW_HEADER_TYPE_COMPRESSED) {
|
||||
ret = PrepareInCompress(addr);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
GSLOG2SO(ERROR) << "failed at prepare";
|
||||
ofs.close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
WriteData();
|
||||
ofs.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawMaker::PrepareInNone()
|
||||
{
|
||||
writing.type = RAW_HEADER_TYPE_NONE;
|
||||
writing.offset = 0;
|
||||
writing.length = 0;
|
||||
writing.compressedLength = 0;
|
||||
writing.data = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawMaker::PrepareInRaw(const uint8_t *addr)
|
||||
{
|
||||
writing.type = RAW_HEADER_TYPE_RAW;
|
||||
writing.compressedLength = writing.length;
|
||||
writing.data = addr + writing.offset;
|
||||
return UpdateLastFrame(addr);
|
||||
}
|
||||
|
||||
int32_t RawMaker::PrepareInCompress(const uint8_t *addr)
|
||||
{
|
||||
writing.type = RAW_HEADER_TYPE_COMPRESSED;
|
||||
|
||||
uLongf clen = compressBound(writing.length);
|
||||
compressed = std::make_unique<uint8_t[]>(clen);
|
||||
auto ret = compress(compressed.get(), &clen, addr + writing.offset, writing.length);
|
||||
if (ret != Z_OK) {
|
||||
GSLOG2HI(ERROR) << "compress failed with " << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
writing.compressedLength = static_cast<int32_t>(clen);
|
||||
writing.data = compressed.get();
|
||||
return UpdateLastFrame(addr);
|
||||
}
|
||||
|
||||
int32_t RawMaker::UpdateLastFrame(const uint8_t *addr)
|
||||
{
|
||||
auto dst = lastFrame.get() + writing.offset;
|
||||
auto dstlen = size - writing.offset;
|
||||
auto src = writing.data;
|
||||
auto srclen = writing.length;
|
||||
auto ret = memcpy_s(dst, dstlen, src, srclen);
|
||||
if (ret) {
|
||||
GSLOG2HI(ERROR) << "memcpy_s failed with <" << strerror(errno) << ">"
|
||||
<< ", params: " << "dstlen(" << dstlen << "), srclen(" << srclen << ")";
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawMaker::WriteData()
|
||||
{
|
||||
WriteInt32(writing.type);
|
||||
WriteInt32(writing.offset);
|
||||
WriteInt32(writing.length);
|
||||
WriteInt32(writing.compressedLength);
|
||||
ofs.write(reinterpret_cast<const char *>(writing.data), writing.compressedLength);
|
||||
|
||||
int32_t align = writing.compressedLength % 0x4;
|
||||
while (align) {
|
||||
align = (align + 1) % 0x4;
|
||||
ofs.write("\0", 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RawMaker::WriteInt32(int32_t integer)
|
||||
{
|
||||
ofs.write(reinterpret_cast<const char *>(&integer), sizeof(integer));
|
||||
}
|
||||
|
||||
void RawMaker::CompareWithLastFrame(const uint8_t *addr)
|
||||
{
|
||||
writing.length = 0;
|
||||
writing.offset = size;
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
if (addr[i] != lastFrame[i]) {
|
||||
writing.offset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = size - 1; i >= writing.offset; i++) {
|
||||
if (addr[i] != lastFrame[i]) {
|
||||
writing.length = i - writing.offset + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t RawMaker::DoFirstFrame()
|
||||
{
|
||||
firstFrame = false;
|
||||
ofs.open(filename, std::ofstream::trunc | std::ofstream::binary | std::ofstream::out);
|
||||
if (errno) {
|
||||
GSLOG2HI(ERROR) << "open " << filename << ", because " << strerror(errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
lastFrame = std::make_unique<uint8_t[]>(static_cast<uint32_t>(size));
|
||||
ofs.write("RAW.dif2", 0x8);
|
||||
WriteInt32(static_cast<int32_t>(width));
|
||||
WriteInt32(height);
|
||||
ofs.close();
|
||||
return 0;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,47 +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/ohos.gni")
|
||||
|
||||
## Build raw_parser.a {{{
|
||||
config("raw_parser_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("raw_parser_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("raw_parser") {
|
||||
sources = [ "src/raw_parser.cpp" ]
|
||||
|
||||
configs = [ ":raw_parser_config" ]
|
||||
|
||||
public_configs = [ ":raw_parser_public_config" ]
|
||||
|
||||
deps = [ "..:libgslogger" ]
|
||||
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"zlib:libz",
|
||||
]
|
||||
}
|
||||
## Build raw_parser.a }}}
|
@ -1,132 +0,0 @@
|
||||
#!/bin/bash
|
||||
# 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.
|
||||
|
||||
set -e
|
||||
|
||||
GENERATE_RAW=raw.raw
|
||||
# put jpg
|
||||
# bash generate_raw.sh <width> <height>
|
||||
|
||||
declare -A HEADER_TYPE=(
|
||||
[NONE]=0
|
||||
[RAW]=1
|
||||
[COMPRESSED]=2
|
||||
)
|
||||
|
||||
echo_int32_t_to_bin()
|
||||
{
|
||||
local int32_t=$1
|
||||
|
||||
local big_endian=$(printf "%08x" $int32_t)
|
||||
local little_endian=${big_endian:6:2}${big_endian:4:2}${big_endian:2:2}${big_endian:0:2}
|
||||
echo "0: $little_endian" | xxd -r
|
||||
}
|
||||
|
||||
get_file_size()
|
||||
{
|
||||
local filename=$1
|
||||
|
||||
du -b $filename | awk '{print $1}'
|
||||
}
|
||||
|
||||
echo_file_part()
|
||||
{
|
||||
local filename=$1
|
||||
local position=$2
|
||||
local length=$3
|
||||
|
||||
xxd -l $length -s $position -o $((-$position)) $filename | xxd -r
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
local width=$1
|
||||
local height=$2
|
||||
ls * | while read filename; do
|
||||
# check mime type
|
||||
file $filename | grep "image" >/dev/null 2>&1
|
||||
if [ $? != 0 ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# generate raw data
|
||||
convert $filename $filename.rgba
|
||||
xxd -c 1 $filename.rgba > $filename.xxd
|
||||
ofilename=$filename.rgba
|
||||
|
||||
if [ "$last_filename" = "" ]; then
|
||||
# first image
|
||||
header_type=${HEADER_TYPE["RAW"]}
|
||||
position=0
|
||||
length="$(get_file_size $ofilename)"
|
||||
else
|
||||
# damage range
|
||||
result="$(diff -y $filename.xxd $last_filename.xxd | grep " |$(echo -e "\x09")")"
|
||||
if [ "$result" = "" ]; then
|
||||
header_type=${HEADER_TYPE["NONE"]}
|
||||
position=0
|
||||
length=0
|
||||
else
|
||||
header_type=${HEADER_TYPE["RAW"]}
|
||||
position="$(printf "%d\n" 0x$(echo "$result" | head -1 | awk '{print $1}' | cut -d: -f1))"
|
||||
length="$(printf "%d\n" 0x$(echo "$result" | tail -1 | awk '{print $1}' | cut -d: -f1))"
|
||||
((length -= ${position}))
|
||||
((length = $length / 4 * 4))
|
||||
fi
|
||||
fi
|
||||
|
||||
# compress
|
||||
clen=$length
|
||||
if [ "$header_type" = "${HEADER_TYPE["RAW"]}" ]; then
|
||||
header_type=${HEADER_TYPE["COMPRESSED"]}
|
||||
ofilename=$filename.compress
|
||||
echo_file_part $filename.rgba $position $length | zlib-flate -compress=9 > $ofilename
|
||||
clen=$(get_file_size $ofilename)
|
||||
else
|
||||
if [ "$header_type" = "${HEADER_TYPE["NONE"]}" ]; then
|
||||
clen=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$last_filename" = "" ]; then
|
||||
echo -en "RAW.dif2" > $GENERATE_RAW
|
||||
echo_int32_t_to_bin $width >> $GENERATE_RAW
|
||||
echo_int32_t_to_bin $height >> $GENERATE_RAW
|
||||
fi
|
||||
echo_int32_t_to_bin $header_type >> $GENERATE_RAW
|
||||
echo_int32_t_to_bin $position >> $GENERATE_RAW
|
||||
echo_int32_t_to_bin $length >> $GENERATE_RAW
|
||||
echo_int32_t_to_bin $clen >> $GENERATE_RAW
|
||||
echo_file_part $ofilename 0 $clen >> $GENERATE_RAW
|
||||
|
||||
# for BUS_ADRALN
|
||||
(( align = $clen - $clen / 4 * 4 ))
|
||||
[ "$align" != "0" ] && (( align = 4 - $align ))
|
||||
[ "$align" != "0" ] && echo -en "\x00" >> $GENERATE_RAW && (( align-- ))
|
||||
[ "$align" != "0" ] && echo -en "\x00" >> $GENERATE_RAW && (( align-- ))
|
||||
[ "$align" != "0" ] && echo -en "\x00" >> $GENERATE_RAW && (( align-- ))
|
||||
|
||||
echo $filename $header_type $position $length $clen
|
||||
|
||||
last_filename=$filename
|
||||
done
|
||||
|
||||
rm -f *.rgba
|
||||
rm -f *.xxd
|
||||
rm -f *.compress
|
||||
return 0
|
||||
}
|
||||
|
||||
main $*
|
||||
exit $?
|
@ -1,103 +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_BOOTANIMATION_INCLUDE_RAW_PARSER_H
|
||||
#define FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_PARSER_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
enum RawHeaderType {
|
||||
RAW_HEADER_TYPE_NONE,
|
||||
RAW_HEADER_TYPE_RAW,
|
||||
RAW_HEADER_TYPE_COMPRESSED,
|
||||
};
|
||||
|
||||
struct RawFrameInfoPtr {
|
||||
enum RawHeaderType type;
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
uint32_t clen;
|
||||
uint8_t *mem;
|
||||
};
|
||||
|
||||
struct RawHeaderInfo {
|
||||
char magic[8];
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
struct RawFrameInfo {
|
||||
enum RawHeaderType type;
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
uint32_t clen;
|
||||
uint8_t mem[0];
|
||||
};
|
||||
|
||||
class RawParser {
|
||||
public:
|
||||
// 0 for success
|
||||
int32_t Parse(const std::string &file);
|
||||
|
||||
uint32_t GetWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
uint32_t GetHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
uint32_t GetSize() const
|
||||
{
|
||||
return width * height * 0x4;
|
||||
}
|
||||
|
||||
int32_t GetCount() const
|
||||
{
|
||||
return infos.size();
|
||||
}
|
||||
|
||||
// 0 for success
|
||||
int32_t GetNextData(uint32_t *addr);
|
||||
int32_t GetNowData(uint32_t *addr);
|
||||
|
||||
private:
|
||||
int32_t ReadFile(const std::string &file, std::unique_ptr<uint8_t[]> &ptr);
|
||||
|
||||
// 0 for success
|
||||
int32_t Uncompress(std::unique_ptr<uint8_t[]> &dst, uint32_t dstlen, uint8_t *cmem, uint32_t clen);
|
||||
|
||||
std::unique_ptr<uint8_t[]> compressed = nullptr;
|
||||
uint32_t clength = 0;
|
||||
|
||||
std::vector<struct RawFrameInfoPtr> infos;
|
||||
std::unique_ptr<uint8_t[]> uncompressed = nullptr;
|
||||
|
||||
int32_t lastID = -1;
|
||||
std::unique_ptr<uint8_t[]> lastData = nullptr;
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
|
||||
static constexpr int32_t magicHeaderLength = 16;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_RAW_PARSER_H
|
@ -1,162 +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 "raw_parser.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <gslogger.h>
|
||||
#include <mutex>
|
||||
#include <securec.h>
|
||||
#include <sstream>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
DEFINE_HILOG_LABEL("RawParser");
|
||||
} // namespace
|
||||
|
||||
int32_t RawParser::Parse(const std::string &file)
|
||||
{
|
||||
int32_t ret = ReadFile(file, compressed);
|
||||
if (ret) {
|
||||
GSLOG2HI(ERROR) << "ReadFile failed with" << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto minfo = reinterpret_cast<struct RawHeaderInfo*>(&compressed[0]);
|
||||
if (strncmp(minfo->magic, "RAW.dif2", 0x8) != 0) {
|
||||
GSLOG2HI(ERROR) << "magic header mistake, is " << minfo->magic;
|
||||
return -1;
|
||||
}
|
||||
|
||||
width = minfo->width;
|
||||
height = minfo->height;
|
||||
lastData = std::make_unique<uint8_t[]>(GetSize());
|
||||
|
||||
struct RawFrameInfo *info = reinterpret_cast<struct RawFrameInfo *>(&compressed[magicHeaderLength]);
|
||||
uint32_t ipos = reinterpret_cast<uint8_t *>(info) - reinterpret_cast<uint8_t *>(minfo);
|
||||
while (ipos < clength) {
|
||||
GSLOG2HI(DEBUG) << info->type << ", " << info->offset << ", " << info->length << ", " << info->clen;
|
||||
if (info->clen < 0) {
|
||||
GSLOG2HI(ERROR) << "clen < 0";
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct RawFrameInfoPtr zi = { info->type, info->offset, info->length, info->clen, info->mem };
|
||||
infos.push_back(zi);
|
||||
|
||||
// for BUS_ADRALN
|
||||
constexpr uint32_t memalign = 4;
|
||||
uint32_t align = info->clen - info->clen / memalign * memalign;
|
||||
if (align) {
|
||||
align = memalign - align;
|
||||
}
|
||||
info = reinterpret_cast<struct RawFrameInfo *>(info->mem + info->clen + align);
|
||||
ipos = reinterpret_cast<uint8_t *>(info) - reinterpret_cast<uint8_t *>(minfo);
|
||||
}
|
||||
|
||||
if (infos.empty()) {
|
||||
GSLOG2HI(ERROR) << "infos is empty";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawParser::GetNextData(uint32_t *addr)
|
||||
{
|
||||
const int32_t count = (lastID + 1) % static_cast<int32_t>(infos.size());
|
||||
if (count < 0) {
|
||||
GSLOG2HI(ERROR) << "current count < 0";
|
||||
return -1;
|
||||
}
|
||||
auto type = infos[count].type;
|
||||
if (type == RAW_HEADER_TYPE_NONE) {
|
||||
lastID = count;
|
||||
return GetNowData(addr);
|
||||
}
|
||||
|
||||
auto offset = infos[count].offset;
|
||||
auto length = infos[count].length;
|
||||
auto clen = infos[count].clen;
|
||||
if (type == RAW_HEADER_TYPE_COMPRESSED) {
|
||||
if (length == 0) {
|
||||
GSLOG2HI(INFO) << "length == 0";
|
||||
lastID = count;
|
||||
return GetNowData(addr);
|
||||
}
|
||||
|
||||
uncompressed = std::make_unique<uint8_t[]>(length);
|
||||
int32_t ret = Uncompress(uncompressed, length, infos[count].mem, clen);
|
||||
if (ret) {
|
||||
GSLOG2HI(ERROR) << "uncompress failed";
|
||||
return -1;
|
||||
}
|
||||
} else if (type == RAW_HEADER_TYPE_RAW) {
|
||||
uncompressed = std::make_unique<uint8_t[]>(length);
|
||||
if (memcpy_s(uncompressed.get(), length, infos[count].mem, clen)) {
|
||||
GSLOG2HI(ERROR) << "memcpy failed";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
lastID = count;
|
||||
if (length > 0 && memcpy_s(lastData.get() + offset, GetSize() - offset,
|
||||
uncompressed.get(), length) != EOK) {
|
||||
GSLOG2HI(ERROR) << "memcpy failed";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return GetNowData(addr);
|
||||
}
|
||||
|
||||
int32_t RawParser::GetNowData(uint32_t *addr)
|
||||
{
|
||||
if (memcpy_s(addr, GetSize(), lastData.get(), GetSize()) != EOK) {
|
||||
GSLOG2HI(ERROR) << "memcpy failed";
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawParser::ReadFile(const std::string &file, std::unique_ptr<uint8_t[]> &ptr)
|
||||
{
|
||||
std::ifstream ifs(file, std::ifstream::in | std::ifstream::binary);
|
||||
if (!ifs.good()) {
|
||||
GSLOG2HI(ERROR) << "read file failed";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ifs.seekg(0, ifs.end);
|
||||
clength = static_cast<uint32_t>(ifs.tellg());
|
||||
ifs.seekg (0, ifs.beg);
|
||||
|
||||
ptr = std::make_unique<uint8_t[]>(static_cast<unsigned int>(clength));
|
||||
ifs.read(reinterpret_cast<char *>(ptr.get()), clength);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RawParser::Uncompress(std::unique_ptr<uint8_t[]> &dst, uint32_t dstlen, uint8_t *cmem, uint32_t clen)
|
||||
{
|
||||
unsigned long ulength = dstlen;
|
||||
auto ret = uncompress(dst.get(), &ulength, cmem, clen);
|
||||
if (ret) {
|
||||
GSLOG2HI(ERROR) << "uncompress failed";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,47 +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/ohos.gni")
|
||||
|
||||
## Build scoped_bytrace.a {{{
|
||||
config("scoped_bytrace_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("scoped_bytrace_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("scoped_bytrace") {
|
||||
sources = [ "src/scoped_bytrace.cpp" ]
|
||||
|
||||
configs = [ ":scoped_bytrace_config" ]
|
||||
|
||||
public_configs = [ ":scoped_bytrace_public_config" ]
|
||||
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
}
|
||||
## Build scoped_bytrace.a }}}
|
@ -1,47 +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 UTILS_TRACE_SCOPED_BYTRACE_H
|
||||
#define UTILS_TRACE_SCOPED_BYTRACE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class ScopedBytrace {
|
||||
public:
|
||||
ScopedBytrace(const std::string &proc);
|
||||
~ScopedBytrace();
|
||||
|
||||
void End();
|
||||
|
||||
private:
|
||||
std::string proc_;
|
||||
bool isEnd = false;
|
||||
};
|
||||
|
||||
class ScopedDebugTrace {
|
||||
public:
|
||||
ScopedDebugTrace(const std::string &traceStr);
|
||||
~ScopedDebugTrace();
|
||||
|
||||
static bool isEnabled()
|
||||
{
|
||||
return debugTraceEnabled_;
|
||||
}
|
||||
|
||||
private:
|
||||
static bool debugTraceEnabled_;
|
||||
};
|
||||
|
||||
#endif // UTILS_TRACE_SCOPED_BYTRACE_H
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 SCOPED_TRACE_FMT_H
|
||||
#define SCOPED_TRACE_FMT_H
|
||||
|
||||
#include <hitrace_meter.h>
|
||||
#include "parameters.h"
|
||||
|
||||
static bool g_debugTraceEnabled =
|
||||
std::atoi((OHOS::system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0;
|
||||
|
||||
#define SCOPED_DEBUG_TRACE_FMT(fmt, ...) \
|
||||
do { \
|
||||
if (g_debugTraceEnabled) { \
|
||||
HITRACE_METER_FMT(HITRACE_TAG_GRAPHIC_AGP, fmt, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif // SCOPED_TRACE_FMT_H
|
@ -1,55 +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 "scoped_bytrace.h"
|
||||
|
||||
#include <hitrace_meter.h>
|
||||
#include <hilog/log.h>
|
||||
#include "parameters.h"
|
||||
|
||||
ScopedBytrace::ScopedBytrace(const std::string &proc) : proc_(proc)
|
||||
{
|
||||
StartTrace(HITRACE_TAG_GRAPHIC_AGP, proc_);
|
||||
isEnd = false;
|
||||
}
|
||||
|
||||
ScopedBytrace::~ScopedBytrace()
|
||||
{
|
||||
if (isEnd == false) {
|
||||
FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopedBytrace::End()
|
||||
{
|
||||
if (isEnd == false) {
|
||||
FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScopedDebugTrace::debugTraceEnabled_ =
|
||||
std::atoi((OHOS::system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0;
|
||||
ScopedDebugTrace::ScopedDebugTrace(const std::string &traceStr)
|
||||
{
|
||||
if (debugTraceEnabled_) {
|
||||
StartTrace(HITRACE_TAG_GRAPHIC_AGP, traceStr);
|
||||
}
|
||||
}
|
||||
ScopedDebugTrace::~ScopedDebugTrace()
|
||||
{
|
||||
if (debugTraceEnabled_) {
|
||||
FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
|
||||
}
|
||||
}
|
@ -1,41 +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/ohos.gni")
|
||||
|
||||
## Build semaphore.a {{{
|
||||
config("semaphore_config") {
|
||||
visibility = [ ":semaphore" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("semaphore_public_config") {
|
||||
include_dirs = [ "export" ]
|
||||
}
|
||||
|
||||
ohos_static_library("semaphore") {
|
||||
sources = [ "src/local_semaphore.cpp" ]
|
||||
|
||||
configs = [ ":semaphore_config" ]
|
||||
|
||||
public_configs = [ ":semaphore_public_config" ]
|
||||
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
## Build semaphore.a }}}
|
@ -1,35 +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 UTILS_INCLUDE_LOCAL_SEMAPHORE_H
|
||||
#define UTILS_INCLUDE_LOCAL_SEMAPHORE_H
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
namespace OHOS {
|
||||
class LocalSemaphore {
|
||||
public:
|
||||
LocalSemaphore(int count = 0);
|
||||
~LocalSemaphore();
|
||||
|
||||
void Inc();
|
||||
void Dec();
|
||||
|
||||
private:
|
||||
sem_t sem;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // UTILS_INCLUDE_LOCAL_SEMAPHORE_H
|
@ -1,44 +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 "local_semaphore.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
LocalSemaphore::LocalSemaphore(int count)
|
||||
{
|
||||
sem_init(&sem, false, static_cast<unsigned int>(count));
|
||||
}
|
||||
|
||||
LocalSemaphore::~LocalSemaphore()
|
||||
{
|
||||
sem_destroy(&sem);
|
||||
}
|
||||
|
||||
void LocalSemaphore::Inc()
|
||||
{
|
||||
sem_post(&sem);
|
||||
}
|
||||
|
||||
void LocalSemaphore::Dec()
|
||||
{
|
||||
int32_t ret = 0;
|
||||
do {
|
||||
ret = sem_wait(&sem);
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 optparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def parse_args(args):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--input")
|
||||
parser.add_option("--output")
|
||||
parser.add_option("--cmd")
|
||||
opts, _ = parser.parse_args(args)
|
||||
return opts
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = parse_args(sys.argv[1:])
|
||||
parse_scripts = subprocess.check_call(
|
||||
[options.cmd, options.input, options.output])
|
@ -1,59 +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/ohos.gni")
|
||||
|
||||
wmlayout_scss_gni_filepath = "//foundation/graphic/graphic_2d/utils/wmlayout"
|
||||
|
||||
template("wmlayout_scss") {
|
||||
scss_name = invoker.scss
|
||||
generate_binary_name = "${target_name}_binary"
|
||||
prebuilt_etc_name = "${target_name}_etc"
|
||||
|
||||
scss_filename = "$root_gen_dir/${target_name}"
|
||||
action(generate_binary_name) {
|
||||
script = "$wmlayout_scss_gni_filepath/gen_scss.py"
|
||||
inputs = [
|
||||
script,
|
||||
scss_name,
|
||||
]
|
||||
outputs = [ scss_filename ]
|
||||
label = "//foundation/graphic/graphic_2d/frameworks/wmserver/src/wmlayout_scss_parser:wmlayout_scss_parser($host_toolchain)"
|
||||
deps = [ label ]
|
||||
args = [
|
||||
"--cmd",
|
||||
"./" +
|
||||
rebase_path(get_label_info(label, "root_out_dir"), root_build_dir) +
|
||||
"/graphic/graphic_2d/wmlayout_scss_parser",
|
||||
"--input",
|
||||
rebase_path(scss_name, root_build_dir),
|
||||
"--output",
|
||||
rebase_path(scss_filename, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc(prebuilt_etc_name) {
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"part_name",
|
||||
"subsystem_name",
|
||||
])
|
||||
source = scss_filename
|
||||
relative_install_dir = "wmlayout.d"
|
||||
deps = [ ":${generate_binary_name}" ]
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
public_deps = [ ":${prebuilt_etc_name}" ]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user