30 #include YFM_Android_YCLib_Android
31 #include <android/native_activity.h>
33 #include YFM_YSLib_Service_YGDI
34 #include <android/configuration.h>
36 using namespace YSLib;
37 using namespace Drawing;
49 template<
typename _tDst,
typename _type>
53 if(
YB_UNLIKELY(val > std::numeric_limits<_tDst>::max()))
54 throw Exception(name +
" value out of range.");
59 template<
typename _tDst,
typename _type>
61 CheckPositiveScalar(_type val,
const std::string& name)
65 throw Exception(
"Failed getting " + name +
" value.");
66 return CheckScalar<_tDst>(val,
name);
75 throw Exception(
"Stride is small than width");
83 WindowReference::GetWidth()
const
86 CheckPositiveScalar<SDst>(::ANativeWindow_getWidth(hWindow),
"width");
89 WindowReference::GetHeight()
const
92 CheckPositiveScalar<SDst>(::ANativeWindow_getHeight(hWindow),
"height");
99 ::ANativeWindow_acquire(h_wnd);
101 HostWindow::~HostWindow()
103 ::ANativeWindow_release(GetNativeHandle());
138 return p_impl->GetBufferPtr();
144 return p_impl->GetContext();
156 return p_impl->GetWidth();
174 std::copy_n(p_buf,
GetAreaOf(GetSize()), p_impl->GetBufferPtr());
181 p_impl->swap(*sbuf.p_impl),
190 : ScreenBuffer(s, buf_stride),
197 std::lock_guard<std::mutex> lck(mtx);
207 const Size&
s(GetSize());
208 ::ANativeWindow_Buffer abuf;
209 ::ARect arect{pt.X, pt.Y, pt.X +
s.Width, pt.Y +
s.Height};
210 std::lock_guard<std::mutex> lck(mtx);
212 ::ANativeWindow_lock(h_wnd, &abuf, &arect);
213 CopyTo(static_cast<BitmapPtr>(abuf.bits), GetContext(),
214 WindowReference(h_wnd).GetSize(), {}, {},
s);
215 ::ANativeWindow_unlockAndPost(h_wnd);
222 const auto p(::ALooper_prepare(allow_non_callbacks
223 ? ALOOPER_PREPARE_ALLOW_NON_CALLBACKS : 0));
227 throw Exception(
"Failed get native looper pointer.");
233 char lang[2], country[2];
235 ::AConfiguration_getLanguage(&cfg, lang);
236 ::AConfiguration_getCountry(&cfg, country);
237 YTraceDe(lv,
"Configuration: MCC = %d, MNC = %d, language code = %c%c,"
238 " country = %c%c, orientation = %d, touch screen = %d, density = %d, "
239 " keyboard = %d, navigation = %d, keysHidden = %d, navHidden = %d,"
240 " SDK version = %d, screen size = %d, screen long = %d,"
241 " UI mode type = %d, UI mode night = %d.",
242 int(::AConfiguration_getMcc(&cfg)),
int(::AConfiguration_getMnc(&cfg)),
243 lang[0], lang[1], country[0], country[1],
244 int(::AConfiguration_getOrientation(&cfg)),
245 int(::AConfiguration_getTouchscreen(&cfg)),
246 int(::AConfiguration_getDensity(&cfg)),
247 int(::AConfiguration_getKeyboard(&cfg)),
248 int(::AConfiguration_getNavigation(&cfg)),
249 int(::AConfiguration_getKeysHidden(&cfg)),
250 int(::AConfiguration_getNavHidden(&cfg)),
251 int(::AConfiguration_getSdkVersion(&cfg)),
252 int(::AConfiguration_getScreenSize(&cfg)),
253 int(::AConfiguration_getScreenLong(&cfg)),
254 int(::AConfiguration_getUiModeType(&cfg)),
255 int(::AConfiguration_getUiModeNight(&cfg)));
268 YTraceDe(
Debug,
"Creating: %p\n", static_cast<void*>(p_activity));
void ANativeActivity_onCreate(::ANativeActivity *p_activity, void *,::size_t)
const YSLib::Drawing::Graphics & GetContext() const ynothrow
ScreenBuffer(const YSLib::Drawing::Size &)
构造:使用指定的缓冲区大小和等于缓冲区宽的像素跨距。
YSLib::SDst GetStride() const ynothrow
YF_API::ALooper & FetchNativeLooper(bool) ythrow(Exception)
取当前线程的本机消息循环。
yconstfn auto GetAreaOf(const Size &s) ynothrow-> decltype(s.Width *s.Height)
取面积。
std::uint16_t SDst
屏幕坐标距离。
YSLib::SDst width
宽:以像素数计量的缓冲区的实际宽度。
void swap(any &x, any &y)
交换对象。
#define YB_UNLIKELY(expr)
分支预测提示。
std::unique_ptr< ScreenBufferData > p_impl
YF_API void TraceConfiguration(::AConfiguration &, platform::Logger::Level=platform::Descriptions::Notice)
#define DefDeMoveCtor(_t)
std::exception Exception
YSLib 异常基类。
DefGetter(ynothrow, ScreenBuffer &, ScreenBufferRef,*this) using ScreenBuffer voi UpdateFrom)(YSLib::Drawing::BitmapPtr) ynothrow
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
yconstfn const string & name
void UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow
从缓冲区更新。
YSLib::Drawing::Size GetSize() const ynothrow
GSStringTemplate< char >::basic_string string
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
YF_API Logger & FetchCommonLogger()
取公共日志记录器。
YSLib::Drawing::BitmapPtr GetBufferPtr() const ynothrow
#define YAssertNonnull(_expr)
::ANativeWindow * NativeWindowHandle
void UpdateTo(NativeWindowHandle, const YSLib::Drawing::Point &={}) ynothrow
#define YTraceDe(...)
YCLib 默认调试跟踪。
YF_API bool CopyTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
位图缓冲区向指针指定的缓冲区复制。
if(YB_UNLIKELY(r >=sGraphics.Height)) throw std return pBuffer r *sGraphics Width
ScreenRegionBuffer(const YSLib::Drawing::Size &, YSLib::SDst)
构造:使用指定的缓冲区大小和像素跨距。 像素跨距小于缓冲区大小。
ScreenBufferData(const Size &, SDst)
void Resize(const YSLib::Drawing::Size &)
重新设置大小。
void swap(ScreenBuffer &) ynothrow
交换。