|
| 1 | +#ifdef __OHOS__ |
| 2 | +#include <hilog/log.h> |
| 3 | +#endif |
| 4 | +#include <memory> |
| 5 | +#include <string> |
| 6 | +#include <utility> |
| 7 | +#include "../../display.h" |
| 8 | + |
| 9 | +#ifdef __OHOS__ |
| 10 | +#define LOG_CORE 0xD001700 |
| 11 | +// Note: LOG_TAG is defined in hilog/log.h as NULL, |
| 12 | +// redefine to avoid warnings if needed |
| 13 | +#undef LOG_TAG |
| 14 | +#define LOG_TAG "NativeApi" |
| 15 | +#endif |
| 16 | + |
| 17 | +namespace nativeapi { |
| 18 | + |
| 19 | +class Display::Impl { |
| 20 | + public: |
| 21 | + Impl() = default; |
| 22 | + Impl(void* display) : native_display_(display) {} |
| 23 | + |
| 24 | + void* native_display_ = nullptr; |
| 25 | +}; |
| 26 | + |
| 27 | +Display::Display() : pimpl_(std::make_unique<Impl>()) {} |
| 28 | + |
| 29 | +Display::Display(void* display) : pimpl_(std::make_unique<Impl>(display)) {} |
| 30 | + |
| 31 | +Display::Display(const Display& other) : pimpl_(std::make_unique<Impl>(*other.pimpl_)) {} |
| 32 | + |
| 33 | +Display& Display::operator=(const Display& other) { |
| 34 | + if (this != &other) { |
| 35 | + *pimpl_ = *other.pimpl_; |
| 36 | + } |
| 37 | + return *this; |
| 38 | +} |
| 39 | + |
| 40 | +Display::Display(Display&& other) noexcept : pimpl_(std::move(other.pimpl_)) {} |
| 41 | + |
| 42 | +Display& Display::operator=(Display&& other) noexcept { |
| 43 | + if (this != &other) { |
| 44 | + pimpl_ = std::move(other.pimpl_); |
| 45 | + } |
| 46 | + return *this; |
| 47 | +} |
| 48 | + |
| 49 | +Display::~Display() = default; |
| 50 | + |
| 51 | +void* Display::GetNativeObjectInternal() const { |
| 52 | + return pimpl_->native_display_; |
| 53 | +} |
| 54 | + |
| 55 | +std::string Display::GetId() const { |
| 56 | + return "primary"; |
| 57 | +} |
| 58 | + |
| 59 | +std::string Display::GetName() const { |
| 60 | + return "Primary Display"; |
| 61 | +} |
| 62 | + |
| 63 | +Point Display::GetPosition() const { |
| 64 | + return {0.0, 0.0}; |
| 65 | +} |
| 66 | + |
| 67 | +Size Display::GetSize() const { |
| 68 | + // Default display size for OpenHarmony devices |
| 69 | + return {360.0, 780.0}; |
| 70 | +} |
| 71 | + |
| 72 | +Rectangle Display::GetWorkArea() const { |
| 73 | + // Default work area matches display size |
| 74 | + Size size = GetSize(); |
| 75 | + return {0.0, 0.0, size.width, size.height}; |
| 76 | +} |
| 77 | + |
| 78 | +double Display::GetScaleFactor() const { |
| 79 | + return 1.0; |
| 80 | +} |
| 81 | + |
| 82 | +bool Display::IsPrimary() const { |
| 83 | + return true; |
| 84 | +} |
| 85 | + |
| 86 | +DisplayOrientation Display::GetOrientation() const { |
| 87 | + return DisplayOrientation::kPortrait; |
| 88 | +} |
| 89 | + |
| 90 | +int Display::GetRefreshRate() const { |
| 91 | + return 60; |
| 92 | +} |
| 93 | + |
| 94 | +int Display::GetBitDepth() const { |
| 95 | + return 32; |
| 96 | +} |
| 97 | + |
| 98 | +} // namespace nativeapi |
| 99 | + |
0 commit comments