2020-02-16 20:14:01 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
|
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2020-05-24 11:26:21 +08:00
|
|
|
|
#include <kiwano/base/ObjectBase.h>
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
|
|
|
|
|
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
|
|
|
|
|
|
#include <kiwano/render/DirectX/D2DDeviceResources.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
KGE_DECLARE_SMART_PTR(NativeObject);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Render
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
2020-10-11 03:45:42 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>
|
2020-02-16 20:14:01 +08:00
|
|
|
|
*/
|
2020-08-04 02:19:08 +08:00
|
|
|
|
class KGE_API NativeObjectBase : public ObjectBase
|
2020-02-16 20:14:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2020-08-04 02:19:08 +08:00
|
|
|
|
NativeObjectBase();
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
bool IsValid() const override;
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
void* GetNativePointer() const;
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
template <typename _NativeTy>
|
|
|
|
|
|
_NativeTy* GetNativePointer() const;
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
virtual void ResetNativePointer(void* native_pointer = nullptr);
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
void* native_pointer_;
|
2020-02-16 20:14:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
#if defined(KGE_PLATFORM_WINDOWS)
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
class KGE_API NativeObject : public NativeObjectBase
|
2020-02-16 20:14:01 +08:00
|
|
|
|
{
|
2020-08-04 02:19:08 +08:00
|
|
|
|
public:
|
|
|
|
|
|
virtual ~NativeObject();
|
2020-02-16 20:14:01 +08:00
|
|
|
|
|
2020-08-04 02:19:08 +08:00
|
|
|
|
void ResetNativePointer(void* native_pointer = nullptr) override;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
typedef NativeObjectBase NativeObject;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
|
|
inline void* NativeObjectBase::GetNativePointer() const
|
2020-02-16 20:14:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
return native_pointer_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename _NativeTy>
|
2020-08-04 02:19:08 +08:00
|
|
|
|
inline _NativeTy* NativeObjectBase::GetNativePointer() const
|
2020-02-16 20:14:01 +08:00
|
|
|
|
{
|
2020-08-04 02:19:08 +08:00
|
|
|
|
if (native_pointer_ != nullptr)
|
2020-02-16 20:14:01 +08:00
|
|
|
|
{
|
2020-08-04 02:19:08 +08:00
|
|
|
|
return static_cast<_NativeTy*>(native_pointer_);
|
2020-02-16 20:14:01 +08:00
|
|
|
|
}
|
2020-08-04 02:19:08 +08:00
|
|
|
|
return nullptr;
|
2020-02-16 20:14:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace kiwano
|