diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index 7e76543c..15c310dc 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -82,6 +82,7 @@
+
@@ -100,7 +101,6 @@
-
@@ -192,7 +192,6 @@
-
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index 399185c7..8171b4f8 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -405,8 +405,8 @@
render\DirectX
-
- render
+
+ platform
@@ -671,9 +671,6 @@
render\DirectX
-
- render
-
diff --git a/src/kiwano-audio/Sound.cpp b/src/kiwano-audio/Sound.cpp
index f04421c4..e340c9f3 100644
--- a/src/kiwano-audio/Sound.cpp
+++ b/src/kiwano-audio/Sound.cpp
@@ -208,12 +208,12 @@ bool Sound::IsPlaying() const
if (!voice_)
return false;
+ if (!playing_)
+ return false;
+
XAUDIO2_VOICE_STATE state;
voice_->GetState(&state);
- uint32_t buffers_queued = state.BuffersQueued;
-
- if (buffers_queued && playing_)
- return true;
+ return !!state.BuffersQueued;
}
return false;
}
@@ -231,7 +231,7 @@ void Sound::SetVolume(float volume)
{
KGE_ASSERT(voice_ != nullptr && "IXAudio2SourceVoice* is NULL");
- volume = std::min(std::max(volume, -224.f), 224.f);
+ volume = std::min(std::max(volume, -XAUDIO2_MAX_VOLUME_LEVEL), XAUDIO2_MAX_VOLUME_LEVEL);
voice_->SetVolume(volume);
}
} // namespace audio
diff --git a/src/kiwano-audio/Sound.h b/src/kiwano-audio/Sound.h
index ebd2ce84..657cfa0c 100644
--- a/src/kiwano-audio/Sound.h
+++ b/src/kiwano-audio/Sound.h
@@ -22,7 +22,6 @@
#include
#include
#include
-#include
#include
namespace kiwano
diff --git a/src/kiwano/platform/NativeObject.hpp b/src/kiwano/platform/NativeObject.hpp
new file mode 100644
index 00000000..b8f3259b
--- /dev/null
+++ b/src/kiwano/platform/NativeObject.hpp
@@ -0,0 +1,89 @@
+// 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
+#include
+
+namespace kiwano
+{
+
+KGE_DECLARE_SMART_PTR(NativeObject);
+
+/**
+ * \~chinese
+ * @brief 含有本地指针的对象
+ */
+class KGE_API NativeObject : public ObjectBase
+{
+public:
+ NativeObject() = default;
+
+ const Any& GetNative() const;
+
+ template
+ _Ty GetNative() const;
+
+ template
+ _Ty* GetNativePtr() const;
+
+ void SetNative(const Any& native);
+
+ void ResetNative();
+
+protected:
+ Any native_;
+};
+
+inline const Any& NativeObject::GetNative() const
+{
+ return native_;
+}
+
+template
+inline _Ty NativeObject::GetNative() const
+{
+ if (native_.HasValue())
+ {
+ return native_.Cast<_Ty>();
+ }
+ return nullptr;
+}
+
+template
+inline _Ty* NativeObject::GetNativePtr() const
+{
+ if (native_.HasValue())
+ {
+ return native_.Cast<_Ty*>();
+ }
+ return nullptr;
+}
+
+inline void NativeObject::SetNative(const Any& native)
+{
+ native_ = native;
+}
+
+inline void NativeObject::ResetNative()
+{
+ native_.Clear();
+}
+
+} // namespace kiwano
diff --git a/src/kiwano/platform/win32/ComPtr.hpp b/src/kiwano/platform/win32/ComPtr.hpp
index 9fe892ee..37d480f1 100644
--- a/src/kiwano/platform/win32/ComPtr.hpp
+++ b/src/kiwano/platform/win32/ComPtr.hpp
@@ -22,11 +22,12 @@
#include
#include
#include
+#include
#include
namespace kiwano
{
-struct ComPtrPolicy
+struct ComRefPolicy
{
inline void Retain(IUnknown* ptr)
{
@@ -43,6 +44,74 @@ struct ComPtrPolicy
// ComPtr<> is a smart pointer for COM
template ::value, int>::type>
-using ComPtr = RefBasePtr<_Ty, ComPtrPolicy>;
+using ComPtr = RefBasePtr<_Ty, ComRefPolicy>;
+
+struct ComPolicy
+{
+ template ::value, int>::type>
+ static inline ComPtr<_Ty> Get(const NativeObject* object)
+ {
+ if (object)
+ {
+ const auto& native = object->GetNative();
+ if (native.HasValue())
+ {
+ auto ptr = native.Cast>();
+ if (ptr)
+ {
+ ComPtr<_Ty> native;
+ if (SUCCEEDED(ptr->QueryInterface<_Ty>(&native)))
+ return native;
+ }
+ }
+ }
+ return nullptr;
+ }
+
+ template ::value, int>::type>
+ static inline ComPtr<_Ty> Get(const NativeObject& object)
+ {
+ return ComPolicy::Get<_Ty>(&object);
+ }
+
+ template ::value, int>::type>
+ static inline ComPtr<_Ty> Get(NativeObjectPtr object)
+ {
+ return ComPolicy::Get<_Ty>(object.Get());
+ }
+
+ static inline void Set(NativeObject* object, ComPtr com_ptr)
+ {
+ if (object)
+ {
+ object->SetNative(Any{ com_ptr });
+ }
+ }
+
+ static inline void Set(NativeObject* object, IUnknown* com_ptr)
+ {
+ ComPolicy::Set(object, ComPtr(com_ptr));
+ }
+
+ static inline void Set(NativeObject& object, IUnknown* com_ptr)
+ {
+ ComPolicy::Set(&object, com_ptr);
+ }
+
+ static inline void Set(NativeObjectPtr object, IUnknown* com_ptr)
+ {
+ ComPolicy::Set(object.Get(), com_ptr);
+ }
+
+ static inline void Set(NativeObject& object, ComPtr com_ptr)
+ {
+ ComPolicy::Set(&object, com_ptr.Get());
+ }
+
+ static inline void Set(NativeObjectPtr object, ComPtr com_ptr)
+ {
+ ComPolicy::Set(object.Get(), com_ptr.Get());
+ }
+};
} // namespace kiwano
diff --git a/src/kiwano/render/Brush.cpp b/src/kiwano/render/Brush.cpp
index ab25d187..2b8545de 100644
--- a/src/kiwano/render/Brush.cpp
+++ b/src/kiwano/render/Brush.cpp
@@ -22,6 +22,10 @@
#include
#include
+#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
+#endif
+
namespace kiwano
{
GradientStop::GradientStop()
@@ -120,7 +124,7 @@ void Brush::SetTransform(const Transform& transform)
void Brush::SetTransform(const Matrix3x2& transform)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
diff --git a/src/kiwano/render/Brush.h b/src/kiwano/render/Brush.h
index e54da60f..51da5e08 100644
--- a/src/kiwano/render/Brush.h
+++ b/src/kiwano/render/Brush.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
#include
#include
diff --git a/src/kiwano/render/DirectX/FontCollectionLoader.h b/src/kiwano/render/DirectX/FontCollectionLoader.h
index a7d7816f..3a4f0576 100644
--- a/src/kiwano/render/DirectX/FontCollectionLoader.h
+++ b/src/kiwano/render/DirectX/FontCollectionLoader.h
@@ -21,7 +21,6 @@
#pragma once
#include
#include
-#include
namespace kiwano
{
diff --git a/src/kiwano/render/DirectX/RenderContextImpl.cpp b/src/kiwano/render/DirectX/RenderContextImpl.cpp
index 56164665..838e04db 100644
--- a/src/kiwano/render/DirectX/RenderContextImpl.cpp
+++ b/src/kiwano/render/DirectX/RenderContextImpl.cpp
@@ -62,7 +62,7 @@ HRESULT RenderContextImpl::CreateDeviceResources(ComPtr factory, C
if (SUCCEEDED(hr))
{
- NativeObject::Set(this, ctx);
+ ComPolicy::Set(this, ctx);
}
return hr;
}
@@ -73,7 +73,7 @@ void RenderContextImpl::DiscardDeviceResources()
render_ctx_.Reset();
current_brush_.Reset();
- ResetNativePointer();
+ ComPolicy::Set(this, nullptr);
}
TexturePtr RenderContextImpl::GetTarget() const
@@ -85,7 +85,7 @@ TexturePtr RenderContextImpl::GetTarget() const
if (target)
{
TexturePtr ptr = MakePtr();
- NativeObject::Set(*ptr, target.Get());
+ ComPolicy::Set(*ptr, target.Get());
}
return nullptr;
}
@@ -123,7 +123,7 @@ void RenderContextImpl::CreateTexture(Texture& texture, const PixelSize& size)
if (SUCCEEDED(hr))
{
- NativeObject::Set(texture, saved_bitmap);
+ ComPolicy::Set(texture, saved_bitmap);
}
KGE_THROW_IF_FAILED(hr, "Create texture failed");
@@ -145,7 +145,7 @@ void RenderContextImpl::DrawTexture(const Texture& texture, const Rect* src_rect
mode = D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR;
}
- auto bitmap = NativeObject::Get(texture);
+ auto bitmap = ComPolicy::Get(texture);
render_ctx_->DrawBitmap(bitmap.Get(), dest_rect ? &DX::ConvertToRectF(*dest_rect) : nullptr, brush_opacity_,
mode, src_rect ? &DX::ConvertToRectF(*src_rect) : nullptr);
@@ -159,10 +159,10 @@ void RenderContextImpl::DrawTextLayout(const TextLayout& layout, const Point& of
if (layout.IsValid())
{
- auto native = NativeObject::Get(layout);
- auto fill_brush = NativeObject::Get(current_brush_);
- auto outline_brush = NativeObject::Get(current_outline_brush);
- auto outline_stroke = NativeObject::Get(current_stroke_);
+ auto native = ComPolicy::Get(layout);
+ auto fill_brush = ComPolicy::Get(current_brush_);
+ auto outline_brush = ComPolicy::Get(current_outline_brush);
+ auto outline_stroke = ComPolicy::Get(current_stroke_);
float outline_width = 1.0f;
if (fill_brush)
@@ -201,9 +201,9 @@ void RenderContextImpl::DrawShape(const Shape& shape)
if (shape.IsValid())
{
- auto geometry = NativeObject::Get(shape);
- auto brush = NativeObject::Get(current_brush_);
- auto stroke_style = NativeObject::Get(current_stroke_);
+ auto geometry = ComPolicy::Get(shape);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto stroke_style = ComPolicy::Get(current_stroke_);
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
render_ctx_->DrawGeometry(geometry.Get(), brush.Get(), stroke_width, stroke_style.Get());
@@ -217,8 +217,8 @@ void RenderContextImpl::DrawLine(const Point& point1, const Point& point2)
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
- auto stroke_style = NativeObject::Get(current_stroke_);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto stroke_style = ComPolicy::Get(current_stroke_);
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
render_ctx_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), brush.Get(), stroke_width,
@@ -232,8 +232,8 @@ void RenderContextImpl::DrawRectangle(const Rect& rect)
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
- auto stroke_style = NativeObject::Get(current_stroke_);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto stroke_style = ComPolicy::Get(current_stroke_);
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
render_ctx_->DrawRectangle(DX::ConvertToRectF(rect), brush.Get(), stroke_width, stroke_style.Get());
@@ -246,8 +246,8 @@ void RenderContextImpl::DrawRoundedRectangle(const Rect& rect, const Vec2& radiu
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
- auto stroke_style = NativeObject::Get(current_stroke_);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto stroke_style = ComPolicy::Get(current_stroke_);
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
render_ctx_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), brush.Get(),
@@ -261,8 +261,8 @@ void RenderContextImpl::DrawEllipse(const Point& center, const Vec2& radius)
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
- auto stroke_style = NativeObject::Get(current_stroke_);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto stroke_style = ComPolicy::Get(current_stroke_);
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
render_ctx_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), brush.Get(),
@@ -278,8 +278,8 @@ void RenderContextImpl::FillShape(const Shape& shape)
if (shape.IsValid())
{
- auto brush = NativeObject::Get(current_brush_);
- auto geometry = NativeObject::Get(shape);
+ auto brush = ComPolicy::Get(current_brush_);
+ auto geometry = ComPolicy::Get(shape);
render_ctx_->FillGeometry(geometry.Get(), brush.Get());
IncreasePrimitivesCount();
@@ -291,7 +291,7 @@ void RenderContextImpl::FillRectangle(const Rect& rect)
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
+ auto brush = ComPolicy::Get(current_brush_);
render_ctx_->FillRectangle(DX::ConvertToRectF(rect), brush.Get());
IncreasePrimitivesCount();
@@ -302,7 +302,7 @@ void RenderContextImpl::FillRoundedRectangle(const Rect& rect, const Vec2& radiu
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
+ auto brush = ComPolicy::Get(current_brush_);
render_ctx_->FillRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), brush.Get());
IncreasePrimitivesCount();
@@ -313,7 +313,7 @@ void RenderContextImpl::FillEllipse(const Point& center, const Vec2& radius)
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
- auto brush = NativeObject::Get(current_brush_);
+ auto brush = ComPolicy::Get(current_brush_);
render_ctx_->FillEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), brush.Get());
IncreasePrimitivesCount();
@@ -345,8 +345,8 @@ void RenderContextImpl::PushLayer(Layer& layer)
{
KGE_ASSERT(render_ctx_ && "Render target has not been initialized!");
- auto native = NativeObject::Get(layer);
- auto mask = NativeObject::Get(layer.GetMaskShape());
+ auto native = ComPolicy::Get(layer);
+ auto mask = ComPolicy::Get(layer.GetMaskShape());
if (!native)
{
@@ -354,7 +354,7 @@ void RenderContextImpl::PushLayer(Layer& layer)
if (SUCCEEDED(hr))
{
- NativeObject::Set(layer, native);
+ ComPolicy::Set(layer, native);
}
KGE_THROW_IF_FAILED(hr, "Create ID2D1Layer failed");
}
@@ -400,7 +400,7 @@ void RenderContextImpl::SetCurrentBrush(BrushPtr brush)
if (current_brush_ && current_brush_->IsValid())
{
- NativeObject::Get(current_brush_)->SetOpacity(brush_opacity_);
+ ComPolicy::Get(current_brush_)->SetOpacity(brush_opacity_);
}
}
diff --git a/src/kiwano/render/DirectX/RendererImpl.cpp b/src/kiwano/render/DirectX/RendererImpl.cpp
index c68cd75d..92e6000e 100644
--- a/src/kiwano/render/DirectX/RendererImpl.cpp
+++ b/src/kiwano/render/DirectX/RendererImpl.cpp
@@ -20,7 +20,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -258,7 +258,7 @@ void RendererImpl::CreateTexture(Texture& texture, const String& file_path)
if (SUCCEEDED(hr))
{
- NativeObject::Set(texture, bitmap);
+ ComPolicy::Set(texture, bitmap);
texture.SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
texture.SetSizeInPixels({ bitmap->GetPixelSize().width, bitmap->GetPixelSize().height });
@@ -307,7 +307,7 @@ void RendererImpl::CreateTexture(Texture& texture, const BinaryData& data)
if (SUCCEEDED(hr))
{
- NativeObject::Set(texture, bitmap);
+ ComPolicy::Set(texture, bitmap);
texture.SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
texture.SetSizeInPixels({ bitmap->GetPixelSize().width, bitmap->GetPixelSize().height });
@@ -344,7 +344,7 @@ void RendererImpl::CreateTexture(Texture& texture, const PixelSize& size, const
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET, D2D1::PixelFormat(dxgi_format)), &output);
if (SUCCEEDED(hr))
{
- NativeObject::Set(texture, output);
+ ComPolicy::Set(texture, output);
texture.SetSize({ output->GetSize().width, output->GetSize().height });
texture.SetSizeInPixels({ output->GetPixelSize().width, output->GetPixelSize().height });
@@ -380,7 +380,7 @@ void RendererImpl::CreateGifImage(GifImage& gif, const String& file_path)
if (SUCCEEDED(hr))
{
- NativeObject::Set(gif, decoder);
+ ComPolicy::Set(gif, decoder);
}
}
@@ -406,7 +406,7 @@ void RendererImpl::CreateGifImage(GifImage& gif, const BinaryData& data)
if (SUCCEEDED(hr))
{
- NativeObject::Set(gif, decoder);
+ ComPolicy::Set(gif, decoder);
}
}
}
@@ -422,7 +422,7 @@ void RendererImpl::CreateGifImageFrame(GifImage::Frame& frame, const GifImage& g
hr = E_UNEXPECTED;
}
- auto decoder = NativeObject::Get(gif);
+ auto decoder = ComPolicy::Get(gif);
if (!decoder)
{
@@ -449,7 +449,7 @@ void RendererImpl::CreateGifImageFrame(GifImage::Frame& frame, const GifImage& g
if (SUCCEEDED(hr))
{
frame.texture = MakePtr();
- NativeObject::Set(frame.texture, bitmap);
+ ComPolicy::Set(frame.texture, bitmap);
frame.texture->SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
frame.texture->SetSizeInPixels({ bitmap->GetPixelSize().width, bitmap->GetPixelSize().height });
@@ -603,7 +603,7 @@ void RendererImpl::CreateFontCollection(Font& font, Vector& family_names
if (SUCCEEDED(hr))
{
d2d_res_->GetFontFamilyNames(family_names, font_collection); // ignore the result
- NativeObject::Set(font, font_collection);
+ ComPolicy::Set(font, font_collection);
}
}
@@ -626,7 +626,7 @@ void RendererImpl::CreateFontCollection(Font& font, Vector& family_names
if (SUCCEEDED(hr))
{
d2d_res_->GetFontFamilyNames(family_names, font_collection); // ignore the result
- NativeObject::Set(font, font_collection);
+ ComPolicy::Set(font, font_collection);
}
}
@@ -660,7 +660,7 @@ void RendererImpl::CreateTextLayout(TextLayout& layout, const String& content, c
auto font_weight = DWRITE_FONT_WEIGHT(font->GetWeight());
auto font_style = DWRITE_FONT_STYLE(font->GetPosture());
auto font_stretch = DWRITE_FONT_STRETCH(font->GetStretch());
- auto collection = NativeObject::Get(font);
+ auto collection = ComPolicy::Get(font);
WideString font_family;
@@ -683,7 +683,7 @@ void RendererImpl::CreateTextLayout(TextLayout& layout, const String& content, c
if (SUCCEEDED(hr))
{
- NativeObject::Set(layout, output);
+ ComPolicy::Set(layout, output);
layout.SetDirtyFlag(TextLayout::DirtyFlag::Dirty);
}
}
@@ -720,7 +720,7 @@ void RendererImpl::CreateLineShape(Shape& shape, const Point& begin_pos, const P
if (SUCCEEDED(hr))
{
- NativeObject::Set(shape, path_geo);
+ ComPolicy::Set(shape, path_geo);
}
}
}
@@ -744,7 +744,7 @@ void RendererImpl::CreateRectShape(Shape& shape, const Rect& rect)
if (SUCCEEDED(hr))
{
- NativeObject::Set(shape, output);
+ ComPolicy::Set(shape, output);
}
KGE_SET_STATUS_IF_FAILED(hr, shape, "Create ID2D1RectangleGeometry failed");
@@ -767,7 +767,7 @@ void RendererImpl::CreateRoundedRectShape(Shape& shape, const Rect& rect, const
if (SUCCEEDED(hr))
{
- NativeObject::Set(shape, output);
+ ComPolicy::Set(shape, output);
}
KGE_SET_STATUS_IF_FAILED(hr, shape, "Create ID2D1RoundedRectangleGeometry failed");
@@ -790,7 +790,7 @@ void RendererImpl::CreateEllipseShape(Shape& shape, const Point& center, const V
if (SUCCEEDED(hr))
{
- NativeObject::Set(shape, output);
+ ComPolicy::Set(shape, output);
}
KGE_SET_STATUS_IF_FAILED(hr, shape, "Create ID2D1EllipseGeometry failed");
@@ -813,7 +813,7 @@ void RendererImpl::CreateShapeSink(ShapeMaker& maker)
if (SUCCEEDED(hr))
{
ShapePtr shape = MakePtr();
- NativeObject::Set(shape, geometry);
+ ComPolicy::Set(shape, geometry);
maker.SetShape(shape);
}
@@ -835,7 +835,7 @@ void RendererImpl::CreateBrush(Brush& brush, const Color& color)
if (brush.GetType() == Brush::Type::SolidColor && brush.IsValid())
{
- hr = NativeObject::Get(brush)->QueryInterface(&solid_brush);
+ hr = ComPolicy::Get(brush)->QueryInterface(&solid_brush);
if (SUCCEEDED(hr))
{
solid_brush->SetColor(DX::ConvertToColorF(color));
@@ -847,7 +847,7 @@ void RendererImpl::CreateBrush(Brush& brush, const Color& color)
if (SUCCEEDED(hr))
{
- NativeObject::Set(brush, solid_brush);
+ ComPolicy::Set(brush, solid_brush);
}
}
}
@@ -879,7 +879,7 @@ void RendererImpl::CreateBrush(Brush& brush, const LinearGradientStyle& style)
if (SUCCEEDED(hr))
{
- NativeObject::Set(brush, output);
+ ComPolicy::Set(brush, output);
}
}
}
@@ -912,7 +912,7 @@ void RendererImpl::CreateBrush(Brush& brush, const RadialGradientStyle& style)
if (SUCCEEDED(hr))
{
- NativeObject::Set(brush, output);
+ ComPolicy::Set(brush, output);
}
}
}
@@ -930,7 +930,7 @@ void RendererImpl::CreateBrush(Brush& brush, TexturePtr texture)
if (SUCCEEDED(hr))
{
- auto bitmap = NativeObject::Get(texture);
+ auto bitmap = ComPolicy::Get(texture);
if (SUCCEEDED(hr))
{
@@ -939,7 +939,7 @@ void RendererImpl::CreateBrush(Brush& brush, TexturePtr texture)
if (SUCCEEDED(hr))
{
- NativeObject::Set(brush, output);
+ ComPolicy::Set(brush, output);
}
}
}
@@ -979,7 +979,7 @@ void RendererImpl::CreateStrokeStyle(StrokeStyle& stroke_style)
if (SUCCEEDED(hr))
{
- NativeObject::Set(stroke_style, output);
+ ComPolicy::Set(stroke_style, output);
}
}
@@ -1023,7 +1023,7 @@ RenderContextPtr RendererImpl::CreateTextureRenderContext(TexturePtr texture, co
if (SUCCEEDED(hr))
{
render_ctx->SetTarget(output.Get());
- NativeObject::Set(texture, output);
+ ComPolicy::Set(texture, output);
texture->SetSize({ output->GetSize().width, output->GetSize().height });
texture->SetSizeInPixels({ output->GetPixelSize().width, output->GetPixelSize().height });
diff --git a/src/kiwano/render/DirectX/helper.h b/src/kiwano/render/DirectX/helper.h
index 44244d4e..87f8b774 100644
--- a/src/kiwano/render/DirectX/helper.h
+++ b/src/kiwano/render/DirectX/helper.h
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/render/Font.cpp b/src/kiwano/render/Font.cpp
index dacfdfbf..4e490274 100644
--- a/src/kiwano/render/Font.cpp
+++ b/src/kiwano/render/Font.cpp
@@ -105,7 +105,7 @@ Font::Font(const String& family_name, float size, uint32_t weight, FontPosture p
FontPtr found = FontCache::GetInstance().GetFontByFamily(family_name);
if (found)
{
- this->ResetNativePointer(found->GetNativePointer());
+ this->SetNative(found->GetNative());
}
}
diff --git a/src/kiwano/render/Font.h b/src/kiwano/render/Font.h
index 11081c24..87ffc3b1 100644
--- a/src/kiwano/render/Font.h
+++ b/src/kiwano/render/Font.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/render/GifImage.cpp b/src/kiwano/render/GifImage.cpp
index 055bb8b7..5d7117f7 100644
--- a/src/kiwano/render/GifImage.cpp
+++ b/src/kiwano/render/GifImage.cpp
@@ -84,7 +84,7 @@ bool GifImage::Load(const String& file_path)
return true;
// Clear data
- ResetNativePointer();
+ ResetNative();
Fail("GifImage::Load failed");
}
return false;
@@ -100,7 +100,7 @@ bool GifImage::Load(const Resource& res)
return true;
// Clear data
- ResetNativePointer();
+ ResetNative();
Fail("GifImage::Load failed");
}
return false;
@@ -116,13 +116,14 @@ GifImage::Frame GifImage::GetFrame(uint32_t index)
} // namespace kiwano
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
namespace kiwano
{
bool GifImage::GetGlobalMetadata()
{
- ComPtr decoder = NativeObject::Get(this);
+ ComPtr decoder = ComPolicy::Get(this);
HRESULT hr = decoder ? S_OK : E_FAIL;
diff --git a/src/kiwano/render/NativeObject.cpp b/src/kiwano/render/NativeObject.cpp
deleted file mode 100644
index 7c3f01a6..00000000
--- a/src/kiwano/render/NativeObject.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "NativeObject.h"
-
-namespace kiwano
-{
-NativeObjectBase::NativeObjectBase()
- : native_pointer_(nullptr)
-{
-}
-
-bool NativeObjectBase::IsValid() const
-{
- return native_pointer_ != nullptr;
-}
-
-void NativeObjectBase::ResetNativePointer(void* native_pointer)
-{
- native_pointer_ = native_pointer;
-}
-
-#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
-
-NativeObject::~NativeObject()
-{
- ResetNativePointer();
-}
-
-void NativeObject::ResetNativePointer(void* native_pointer)
-{
- if (native_pointer_)
- {
- static_cast(native_pointer_)->Release();
- native_pointer_ = nullptr;
- }
-
- if (native_pointer)
- {
- native_pointer_ = native_pointer;
- static_cast(native_pointer_)->AddRef();
- }
-}
-
-#endif
-
-}
diff --git a/src/kiwano/render/NativeObject.h b/src/kiwano/render/NativeObject.h
deleted file mode 100644
index eebeac0a..00000000
--- a/src/kiwano/render/NativeObject.h
+++ /dev/null
@@ -1,139 +0,0 @@
-// 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
-#include
-
-#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
-#include
-#endif
-
-namespace kiwano
-{
-
-KGE_DECLARE_SMART_PTR(NativeObject);
-
-/**
- * \addtogroup Render
- * @{
- */
-
-/**
- * \~chinese
- * @brief 含有本地指针的对象
- */
-class KGE_API NativeObjectBase : public ObjectBase
-{
-public:
- NativeObjectBase();
-
- bool IsValid() const override;
-
- void* GetNativePointer() const;
-
- template
- _NativeTy* GetNativePointer() const;
-
- virtual void ResetNativePointer(void* native_pointer = nullptr);
-
-protected:
- void* native_pointer_;
-};
-
-#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
-
-class KGE_API NativeObject : public NativeObjectBase
-{
-public:
- virtual ~NativeObject();
-
- void ResetNativePointer(void* native_pointer = nullptr) override;
-
- template ::value, int>::type>
- static inline ComPtr<_Ty> Get(const NativeObject* object)
- {
- if (object)
- {
- ComPtr ptr = object->GetNativePointer();
- if (ptr)
- {
- ComPtr<_Ty> native;
- if (SUCCEEDED(ptr->QueryInterface<_Ty>(&native)))
- return native;
- }
- }
- return nullptr;
- }
-
- template
- static inline ComPtr<_Ty> Get(const NativeObject& object)
- {
- return NativeObject::Get<_Ty>(&object);
- }
-
- template
- static inline ComPtr<_Ty> Get(NativeObjectPtr object)
- {
- return NativeObject::Get<_Ty>(object.Get());
- }
-
- static inline void Set(NativeObject* object, ComPtr com_ptr)
- {
- if (object)
- {
- object->ResetNativePointer(com_ptr.Get());
- }
- }
-
- static inline void Set(NativeObject& object, ComPtr com_ptr)
- {
- NativeObject::Set(&object, com_ptr);
- }
-
- static inline void Set(NativeObjectPtr object, ComPtr com_ptr)
- {
- NativeObject::Set(object.Get(), com_ptr);
- }
-};
-
-#else
-
-typedef NativeObjectBase NativeObject;
-
-#endif
-
-/** @} */
-
-inline void* NativeObjectBase::GetNativePointer() const
-{
- return native_pointer_;
-}
-
-template
-inline _NativeTy* NativeObjectBase::GetNativePointer() const
-{
- if (native_pointer_ != nullptr)
- {
- return static_cast<_NativeTy*>(native_pointer_);
- }
- return nullptr;
-}
-
-} // namespace kiwano
diff --git a/src/kiwano/render/Shape.cpp b/src/kiwano/render/Shape.cpp
index 8833b27b..7b19fc68 100644
--- a/src/kiwano/render/Shape.cpp
+++ b/src/kiwano/render/Shape.cpp
@@ -22,6 +22,10 @@
#include
#include
+#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
+#endif
+
namespace kiwano
{
@@ -29,14 +33,14 @@ Shape::Shape() {}
void Shape::Clear()
{
- ResetNativePointer();
+ ResetNative();
}
Rect Shape::GetBoundingBox() const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
Rect bounds;
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (geometry)
{
// no matter it failed or not
@@ -52,7 +56,7 @@ Rect Shape::GetBoundingBox(const Matrix3x2& transform) const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
Rect bounds;
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (geometry)
{
// no matter it failed or not
@@ -68,7 +72,7 @@ float Shape::GetLength() const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
float length = 0.f;
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (geometry)
{
// no matter it failed or not
@@ -83,7 +87,7 @@ float Shape::GetLength() const
bool Shape::ComputePointAtLength(float length, Point& point, Vec2& tangent) const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (geometry)
{
HRESULT hr = geometry->ComputePointAtLength(length, D2D1::Matrix3x2F::Identity(), DX::ConvertToPoint2F(&point),
@@ -100,7 +104,7 @@ bool Shape::ComputePointAtLength(float length, Point& point, Vec2& tangent) cons
float Shape::ComputeArea() const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (geometry)
{
float area = 0.f;
@@ -116,7 +120,7 @@ float Shape::ComputeArea() const
bool Shape::ContainsPoint(const Point& point, const Matrix3x2* transform) const
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto geometry = NativeObject::Get(this);
+ auto geometry = ComPolicy::Get(this);
if (!geometry)
return false;
diff --git a/src/kiwano/render/Shape.h b/src/kiwano/render/Shape.h
index ce9f58fc..652ad572 100644
--- a/src/kiwano/render/Shape.h
+++ b/src/kiwano/render/Shape.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/render/ShapeMaker.cpp b/src/kiwano/render/ShapeMaker.cpp
index 48299ee4..d077188a 100644
--- a/src/kiwano/render/ShapeMaker.cpp
+++ b/src/kiwano/render/ShapeMaker.cpp
@@ -21,6 +21,10 @@
#include
#include
+#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
+#endif
+
namespace kiwano
{
@@ -34,7 +38,7 @@ ShapeMaker::~ShapeMaker()
void ShapeMaker::Clear()
{
CloseStream();
- ResetNativePointer();
+ ResetNative();
}
ShapePtr ShapeMaker::GetShape()
@@ -55,7 +59,7 @@ void ShapeMaker::BeginPath(const Point& begin_pos)
}
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->BeginFigure(DX::ConvertToPoint2F(begin_pos), D2D1_FIGURE_BEGIN_FILLED);
#else
// not supported
@@ -67,7 +71,7 @@ void ShapeMaker::EndPath(bool closed)
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN);
#else
// not supported
@@ -81,7 +85,7 @@ void ShapeMaker::AddLine(const Point& point)
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->AddLine(DX::ConvertToPoint2F(point));
#else
// not supported
@@ -93,7 +97,7 @@ void ShapeMaker::AddLines(const Vector& points)
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->AddLines(reinterpret_cast(&points[0]), static_cast(points.size()));
#else
// not supported
@@ -105,7 +109,7 @@ void kiwano::ShapeMaker::AddLines(const Point* points, size_t count)
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->AddLines(reinterpret_cast(points), UINT32(count));
#else
// not supported
@@ -117,7 +121,7 @@ void ShapeMaker::AddBezier(const Point& point1, const Point& point2, const Point
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->AddBezier(
D2D1::BezierSegment(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), DX::ConvertToPoint2F(point3)));
#else
@@ -130,7 +134,7 @@ void ShapeMaker::AddArc(const Point& point, const Size& radius, float rotation,
KGE_ASSERT(IsStreamOpened());
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
native->AddArc(D2D1::ArcSegment(DX::ConvertToPoint2F(point), DX::ConvertToSizeF(radius), rotation,
clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,
is_small ? D2D1_ARC_SIZE_SMALL : D2D1_ARC_SIZE_LARGE));
@@ -147,9 +151,9 @@ ShapePtr ShapeMaker::Combine(ShapePtr shape_a, ShapePtr shape_b, CombineMode mod
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
if (shape_a && shape_b)
{
- auto geo_a = NativeObject::Get(shape_a);
- auto geo_b = NativeObject::Get(shape_b);
- auto native = NativeObject::Get(maker);
+ auto geo_a = ComPolicy::Get(shape_a);
+ auto geo_b = ComPolicy::Get(shape_b);
+ auto native = ComPolicy::Get(maker);
HRESULT hr = geo_a->CombineWithGeometry(geo_b.Get(), D2D1_COMBINE_MODE(mode), DX::ConvertToMatrix3x2F(matrix),
native.Get());
@@ -172,7 +176,7 @@ void ShapeMaker::OpenStream()
Renderer::GetInstance().CreateShapeSink(*this);
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto geometry = NativeObject::Get(shape_);
+ auto geometry = ComPolicy::Get(shape_);
if (geometry)
{
ComPtr native;
@@ -180,7 +184,7 @@ void ShapeMaker::OpenStream()
HRESULT hr = geometry->Open(&native);
if (SUCCEEDED(hr))
{
- NativeObject::Set(this, native);
+ ComPolicy::Set(this, native);
}
KGE_THROW_IF_FAILED(hr, "ID2D1PathGeometry::Open failed");
}
@@ -195,12 +199,12 @@ void ShapeMaker::CloseStream()
return;
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
HRESULT hr = native->Close();
KGE_THROW_IF_FAILED(hr, "ID2D1PathGeometry::Close failed");
- ResetNativePointer();
+ ResetNative();
#else
return; // not supported
#endif
diff --git a/src/kiwano/render/StrokeStyle.cpp b/src/kiwano/render/StrokeStyle.cpp
index 3b8625a0..c8967390 100644
--- a/src/kiwano/render/StrokeStyle.cpp
+++ b/src/kiwano/render/StrokeStyle.cpp
@@ -18,7 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
#include
namespace kiwano
diff --git a/src/kiwano/render/StrokeStyle.h b/src/kiwano/render/StrokeStyle.h
index f5fb8800..3ca46be5 100644
--- a/src/kiwano/render/StrokeStyle.h
+++ b/src/kiwano/render/StrokeStyle.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/render/TextLayout.cpp b/src/kiwano/render/TextLayout.cpp
index da600a64..e192144e 100644
--- a/src/kiwano/render/TextLayout.cpp
+++ b/src/kiwano/render/TextLayout.cpp
@@ -21,6 +21,10 @@
#include
#include
+#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
+#endif
+
namespace kiwano
{
@@ -37,8 +41,13 @@ TextLayout::TextLayout(const String& content, const TextStyle& style)
Reset(content, style);
}
-void TextLayout::Reset(const String& content, const TextStyle& style)
+void TextLayout::Clear()
{
+ ResetNative();
+}
+
+void TextLayout::Reset(const String& content, const TextStyle& style)
+ {
content_length_ = (uint32_t)content.length();
if (content_length_)
{
@@ -80,7 +89,7 @@ void TextLayout::SetFont(FontPtr font)
return;
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get((const NativeObject*)(this));
KGE_ASSERT(native);
if (native)
@@ -89,7 +98,7 @@ void TextLayout::SetFont(FontPtr font)
// reset font collection
{
- auto collection = NativeObject::Get(font);
+ auto collection = ComPolicy::Get(font);
hr = native->SetFontCollection(collection.Get(), { 0, content_length_ });
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontCollection failed");
@@ -144,7 +153,7 @@ void TextLayout::SetFont(FontPtr font)
void TextLayout::SetUnderline(bool enable)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
@@ -162,7 +171,7 @@ void TextLayout::SetUnderline(bool enable)
void TextLayout::SetStrikethrough(bool enable)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
@@ -180,7 +189,7 @@ void TextLayout::SetStrikethrough(bool enable)
void TextLayout::SetAlignment(TextAlign align)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
@@ -215,7 +224,7 @@ void TextLayout::SetAlignment(TextAlign align)
void TextLayout::SetWrapWidth(float wrap_width)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
@@ -245,7 +254,7 @@ void TextLayout::SetWrapWidth(float wrap_width)
void TextLayout::SetLineSpacing(float line_spacing)
{
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
KGE_ASSERT(native);
if (native)
@@ -280,7 +289,7 @@ bool TextLayout::UpdateIfDirty()
line_count_ = 0;
size_ = Size();
- auto native = NativeObject::Get(this);
+ auto native = ComPolicy::Get(this);
if (content_length_ == 0 || !native)
return true;
diff --git a/src/kiwano/render/TextLayout.h b/src/kiwano/render/TextLayout.h
index 6df086db..c257649e 100644
--- a/src/kiwano/render/TextLayout.h
+++ b/src/kiwano/render/TextLayout.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
#include
namespace kiwano
@@ -135,11 +135,6 @@ inline bool TextLayout::IsDirty() const
return dirty_flag_ != DirtyFlag::Clean;
}
-inline void TextLayout::Clear()
-{
- ResetNativePointer();
-}
-
inline uint32_t TextLayout::GetContentLength() const
{
return content_length_;
diff --git a/src/kiwano/render/Texture.cpp b/src/kiwano/render/Texture.cpp
index e82f9797..b6b5dbce 100644
--- a/src/kiwano/render/Texture.cpp
+++ b/src/kiwano/render/Texture.cpp
@@ -23,6 +23,10 @@
#include
#include // std::hash
+#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
+#include
+#endif
+
namespace kiwano
{
@@ -104,8 +108,8 @@ void Texture::CopyFrom(TexturePtr copy_from)
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
if (IsValid() && copy_from)
{
- auto native = NativeObject::Get(this);
- auto native_to_copy = NativeObject::Get(copy_from);
+ auto native = ComPolicy::Get(this);
+ auto native_to_copy = ComPolicy::Get(copy_from);
HRESULT hr = native->CopyFromBitmap(nullptr, native_to_copy.Get(), nullptr);
@@ -121,8 +125,8 @@ void Texture::CopyFrom(TexturePtr copy_from, const Rect& src_rect, const Point&
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
if (IsValid() && copy_from)
{
- auto native = NativeObject::Get(this);
- auto native_to_copy = NativeObject::Get(copy_from);
+ auto native = ComPolicy::Get(this);
+ auto native_to_copy = ComPolicy::Get(copy_from);
HRESULT hr =
native->CopyFromBitmap(&D2D1::Point2U(uint32_t(dest_point.x), uint32_t(dest_point.y)), native_to_copy.Get(),
diff --git a/src/kiwano/render/Texture.h b/src/kiwano/render/Texture.h
index 3a9a73be..9c24ee96 100644
--- a/src/kiwano/render/Texture.h
+++ b/src/kiwano/render/Texture.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
namespace kiwano
{