From 03edd40ecdb4e5c909647b15765a1caec92f5887 Mon Sep 17 00:00:00 2001 From: Nomango Date: Wed, 11 Dec 2019 13:44:40 +0800 Subject: [PATCH] update intrusive_ptr --- src/kiwano-audio/SoundPlayer.cpp | 8 +-- src/kiwano-physics/Joint.cpp | 2 +- src/kiwano-physics/Joint.h | 2 +- src/kiwano/2d/Actor.cpp | 10 ++-- src/kiwano/2d/Canvas.h | 2 +- src/kiwano/common/intrusive_list.hpp | 14 ++--- src/kiwano/common/intrusive_ptr.hpp | 45 +++++++------- src/kiwano/common/vector.hpp | 2 +- src/kiwano/renderer/Geometry.cpp | 58 ++++++------------- src/kiwano/renderer/Geometry.h | 28 +++++---- src/kiwano/renderer/RenderTarget.cpp | 30 +++++----- src/kiwano/renderer/RenderTarget.h | 30 +++++----- src/kiwano/renderer/Renderer.h | 4 +- src/kiwano/renderer/TextLayout.h | 2 +- .../renderer/win32/D2DDeviceResources.cpp | 18 +++--- .../renderer/win32/D2DDeviceResources.h | 28 ++++----- .../renderer/win32/D3D10DeviceResources.h | 10 ++-- .../renderer/win32/D3D11DeviceResources.h | 12 ++-- src/kiwano/ui/Menu.cpp | 2 +- src/kiwano/utils/ResourceCache.h | 2 +- 20 files changed, 148 insertions(+), 161 deletions(-) diff --git a/src/kiwano-audio/SoundPlayer.cpp b/src/kiwano-audio/SoundPlayer.cpp index 1d81484f..5146b885 100644 --- a/src/kiwano-audio/SoundPlayer.cpp +++ b/src/kiwano-audio/SoundPlayer.cpp @@ -118,7 +118,7 @@ namespace kiwano void SoundPlayer::SetVolume(float volume) { volume_ = std::min(std::max(volume, -224.f), 224.f); - for (const auto& pair : sound_cache_) + for (auto& pair : sound_cache_) { pair.second->SetVolume(volume_); } @@ -126,7 +126,7 @@ namespace kiwano void SoundPlayer::PauseAll() { - for (const auto& pair : sound_cache_) + for (auto& pair : sound_cache_) { pair.second->Pause(); } @@ -134,7 +134,7 @@ namespace kiwano void SoundPlayer::ResumeAll() { - for (const auto& pair : sound_cache_) + for (auto& pair : sound_cache_) { pair.second->Resume(); } @@ -142,7 +142,7 @@ namespace kiwano void SoundPlayer::StopAll() { - for (const auto& pair : sound_cache_) + for (auto& pair : sound_cache_) { pair.second->Stop(); } diff --git a/src/kiwano-physics/Joint.cpp b/src/kiwano-physics/Joint.cpp index 08be38b7..05b209d7 100644 --- a/src/kiwano-physics/Joint.cpp +++ b/src/kiwano-physics/Joint.cpp @@ -207,7 +207,7 @@ namespace kiwano { } - GearJoint::GearJoint(World* world, GearJoint::Param const& param) + GearJoint::GearJoint(World* world, GearJoint::Param param) : Joint() , raw_joint_(nullptr) { diff --git a/src/kiwano-physics/Joint.h b/src/kiwano-physics/Joint.h index 46548a4f..1168d27f 100644 --- a/src/kiwano-physics/Joint.h +++ b/src/kiwano-physics/Joint.h @@ -237,7 +237,7 @@ namespace kiwano GearJoint(); GearJoint(World* world, b2GearJointDef* def); - GearJoint(World* world, Param const& param); + GearJoint(World* world, Param param); // 设定齿轮传动比 void SetRatio(float ratio); diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index ec4f0eff..427c2c9f 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -272,7 +272,7 @@ namespace kiwano } // update children's transform - for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) + for (auto child = children_.first_item().get(); child; child = child->next_item().get()) child->dirty_transform_ = true; } @@ -527,11 +527,11 @@ namespace kiwano Vector children; size_t hash_code = std::hash{}(name); - for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) + for (auto child = children_.first_item().get(); child; child = child->next_item().get()) { if (child->hash_name_ == hash_code && child->IsName(name)) { - children.push_back(child); + children.push_back(const_cast(child)); } } return children; @@ -541,11 +541,11 @@ namespace kiwano { size_t hash_code = std::hash{}(name); - for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) + for (auto child = children_.first_item().get(); child; child = child->next_item().get()) { if (child->hash_name_ == hash_code && child->IsName(name)) { - return child; + return const_cast(child); } } return nullptr; diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index eefaee8e..b05976e8 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -247,9 +247,9 @@ namespace kiwano TextStyle text_style_; StrokeStyle stroke_style_; GeometrySink geo_sink_; - TextureRenderTarget rt_; mutable bool cache_expired_; mutable Texture texture_cached_; + mutable TextureRenderTarget rt_; }; } diff --git a/src/kiwano/common/intrusive_list.hpp b/src/kiwano/common/intrusive_list.hpp index 0e49d091..c2c62b00 100644 --- a/src/kiwano/common/intrusive_list.hpp +++ b/src/kiwano/common/intrusive_list.hpp @@ -43,8 +43,8 @@ class intrusive_list_item { public: using value_type = _Ty; - using reference = value_type&; - using const_reference = const value_type&; + using reference = _Ty&; + using const_reference = const _Ty&; intrusive_list_item() : prev_(), next_() {} intrusive_list_item(_Ty const& rhs) : prev_(rhs->prev_), next_(rhs->next_) {} @@ -80,7 +80,7 @@ public: reference last_item() { return last_; } bool empty() const { return !first_; } - void push_back(const_reference child) + void push_back(value_type child) { if (child->prev_) child->prev_->next_ = child->next_; @@ -104,7 +104,7 @@ public: KGE_DEBUG_CHECK_LIST(this); } - void push_front(const_reference child) + void push_front(value_type child) { if (child->prev_) child->prev_->next_ = child->next_; @@ -128,7 +128,7 @@ public: KGE_DEBUG_CHECK_LIST(this); } - void insert_before(const_reference child, const_reference before) + void insert_before(value_type child, value_type before) { if (child->prev_) child->prev_->next_ = child->next_; @@ -147,7 +147,7 @@ public: KGE_DEBUG_CHECK_LIST(this); } - void insert_after(const_reference child, const_reference after) + void insert_after(value_type child, value_type after) { if (child->prev_) child->prev_->next_ = child->next_; @@ -166,7 +166,7 @@ public: KGE_DEBUG_CHECK_LIST(this); } - void remove(const_reference child) + void remove(value_type child) { #ifdef KGE_DEBUG_ENABLE_LIST_CHECK _Ty tmp = first_; diff --git a/src/kiwano/common/intrusive_ptr.hpp b/src/kiwano/common/intrusive_ptr.hpp index 70aadb9c..168aa5e3 100644 --- a/src/kiwano/common/intrusive_ptr.hpp +++ b/src/kiwano/common/intrusive_ptr.hpp @@ -36,35 +36,40 @@ public: using value_type = _Ty; using pointer_type = _Ty*; using const_pointer_type = const _Ty*; + using reference_type = _Ty&; + using const_reference_type = const _Ty&; using manager_type = _ManagerTy; - intrusive_ptr() noexcept {} - intrusive_ptr(std::nullptr_t) noexcept {} - intrusive_ptr(pointer_type p) : ptr_(p) { typename manager_type::AddRef(ptr_); } - intrusive_ptr(const intrusive_ptr& other) : ptr_(other.ptr_) { typename manager_type::AddRef(ptr_); } - intrusive_ptr(intrusive_ptr&& other) noexcept { ptr_ = other.ptr_; other.ptr_ = nullptr; } - ~intrusive_ptr() { typename manager_type::Release(ptr_); } + intrusive_ptr() noexcept : ptr_(nullptr) {} + intrusive_ptr(std::nullptr_t) noexcept : ptr_(nullptr) {} + intrusive_ptr(pointer_type p) : ptr_(p) { typename manager_type::AddRef(ptr_); } + intrusive_ptr(const intrusive_ptr& other) : ptr_(other.ptr_) { typename manager_type::AddRef(ptr_); } + intrusive_ptr(intrusive_ptr&& other) noexcept : ptr_(nullptr) { swap(other); } + ~intrusive_ptr() { reset(); } template - intrusive_ptr(const intrusive_ptr<_UTy, manager_type>& other) : ptr_(other.get()) { typename manager_type::AddRef(ptr_); } + intrusive_ptr(const intrusive_ptr<_UTy, manager_type>& other) { ptr_ = const_cast(dynamic_cast(other.get())); typename manager_type::AddRef(ptr_); } - inline pointer_type get() const noexcept { return ptr_; } - inline void reset(pointer_type ptr = nullptr) { intrusive_ptr{ ptr }.swap(*this); } - inline void swap(intrusive_ptr& other) noexcept { std::swap(ptr_, other.ptr_); } + inline pointer_type get() noexcept { return ptr_; } + inline const_pointer_type get() const noexcept { return ptr_; } + inline void reset(pointer_type ptr = nullptr) { typename manager_type::Release(ptr_); ptr_ = nullptr; } + inline void swap(intrusive_ptr& other) noexcept { std::swap(ptr_, other.ptr_); } - inline pointer_type operator ->() const { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return ptr_; } - inline value_type& operator *() const { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return *ptr_; } - inline pointer_type* operator &() { KGE_ASSERT(ptr_ == nullptr && "Memory leak"); return &ptr_; } - inline operator bool() const noexcept { return ptr_ != nullptr; } - inline bool operator !() const noexcept { return ptr_ == 0; } + inline pointer_type operator ->() { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return ptr_; } + inline const_pointer_type operator ->() const { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return ptr_; } + inline reference_type operator *() { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return *ptr_; } + inline const_reference_type operator *() const { KGE_ASSERT(ptr_ != nullptr && "Invalid pointer"); return *ptr_; } + inline pointer_type* operator &() { KGE_ASSERT(ptr_ == nullptr && "Memory leak"); return &ptr_; } + inline operator bool() const noexcept { return ptr_ != nullptr; } + inline bool operator !() const noexcept { return ptr_ == 0; } - inline const intrusive_ptr& operator=(const intrusive_ptr& other) const { if (other.ptr_ != ptr_) intrusive_ptr(other).swap(*const_cast(this)); return *this; } - inline const intrusive_ptr& operator=(intrusive_ptr&& other) const noexcept { if (other.ptr_ != ptr_) other.swap(*const_cast(this)); return *this; } - inline const intrusive_ptr& operator=(pointer_type p) const { if (p != ptr_) intrusive_ptr(p).swap(*const_cast(this)); return *this; } - inline const intrusive_ptr& operator=(std::nullptr_t) const noexcept { if (nullptr != ptr_) intrusive_ptr{}.swap(*const_cast(this)); return *this; } + inline intrusive_ptr& operator=(const intrusive_ptr& other) { if (other.ptr_ != ptr_) intrusive_ptr(other).swap(*this); return (*this); } + inline intrusive_ptr& operator=(intrusive_ptr&& other) noexcept { if (other.ptr_ != ptr_) other.swap(*this); return (*this); } + inline intrusive_ptr& operator=(pointer_type p) { if (p != ptr_) intrusive_ptr(p).swap(*this); return (*this); } + inline intrusive_ptr& operator=(std::nullptr_t) { reset(); return *this; } private: - pointer_type ptr_{ nullptr }; + pointer_type ptr_; }; template diff --git a/src/kiwano/common/vector.hpp b/src/kiwano/common/vector.hpp index dc8f9e0d..497357d0 100644 --- a/src/kiwano/common/vector.hpp +++ b/src/kiwano/common/vector.hpp @@ -21,7 +21,7 @@ #pragma once #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Geometry.cpp b/src/kiwano/renderer/Geometry.cpp index 6b008ffc..e8d204b6 100644 --- a/src/kiwano/renderer/Geometry.cpp +++ b/src/kiwano/renderer/Geometry.cpp @@ -92,14 +92,10 @@ namespace kiwano return false; } - Geometry Geometry::CombineWith(Geometry input, CombineMode mode, Matrix3x2 const& input_matrix) const + void Geometry::CombineWith(GeometrySink& sink, Geometry input, CombineMode mode, Matrix3x2 const& input_matrix) const { if (geo_ && input.geo_) { - GeometrySink sink; - sink.Init(); - sink.OpenSink(); - ThrowIfFailed( geo_->CombineWithGeometry( input.geo_.get(), @@ -108,41 +104,18 @@ namespace kiwano sink.GetGeometrySink().get() ) ); - - sink.CloseSink(); - return sink.GetGeometry(); } - return Geometry(); } - Geometry Geometry::Combine(Vector const& geos, Vector const& modes, Vector const& matrixs) + Geometry Geometry::CombineWith(Geometry input, CombineMode mode, Matrix3x2 const& input_matrix) const { - if ((geos.size() == (modes.size() + 1) || modes.size() == 1) - && (geos.size() == (matrixs.size() + 1) || matrixs.size() == 1)) - { - GeometrySink sink; - sink.Init(); - sink.OpenSink(); + GeometrySink sink; + sink.Open(); - for (size_t i = 0; i < geos.size() - 1; i++) - { - CombineMode mode = (modes.size() == 1) ? modes[0] : modes[i]; - const Matrix3x2& matrix = (matrixs.size() == 1) ? matrixs[0] : matrixs[i]; + CombineWith(sink, input, mode, input_matrix); - ThrowIfFailed( - geos[i].geo_->CombineWithGeometry( - geos[i + 1].geo_.get(), - D2D1_COMBINE_MODE(mode), - DX::ConvertToMatrix3x2F(matrix), - sink.GetGeometrySink().get() - ) - ); - } - - sink.CloseSink(); - return sink.GetGeometry(); - } - return Geometry(); + sink.Close(); + return sink.GetGeometry(); } float Geometry::ComputeArea() const @@ -214,13 +187,16 @@ namespace kiwano { } + GeometrySink::~GeometrySink() + { + Close(); + } + GeometrySink& GeometrySink::BeginPath(Point const& begin_pos) { - Init(); - if (!sink_) { - OpenSink(); + Open(); } sink_->BeginFigure(DX::ConvertToPoint2F(begin_pos), D2D1_FIGURE_BEGIN_FILLED); @@ -233,7 +209,7 @@ namespace kiwano { sink_->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN); - CloseSink(); + Close(); } return (*this); } @@ -312,15 +288,17 @@ namespace kiwano } } - void GeometrySink::OpenSink() + void GeometrySink::Open() { + Init(); + if (!sink_) { ThrowIfFailed(path_geo_->Open(&sink_)); } } - void GeometrySink::CloseSink() + void GeometrySink::Close() { if (sink_) { diff --git a/src/kiwano/renderer/Geometry.h b/src/kiwano/renderer/Geometry.h index 859e07cc..ea3daa6c 100644 --- a/src/kiwano/renderer/Geometry.h +++ b/src/kiwano/renderer/Geometry.h @@ -23,6 +23,7 @@ namespace kiwano { + class GeometrySink; // 几何体 class KGE_API Geometry @@ -72,19 +73,19 @@ namespace kiwano ) const; // 组合几何体 - Geometry CombineWith( + void CombineWith( + GeometrySink& sink, Geometry input, CombineMode mode, Matrix3x2 const& input_matrix = Matrix3x2() ) const; - // 组合多个几何体 - // 参数 modes 和 matrixs 的数量应为 1 或 geos 的数量减一 - static Geometry Combine( - Vector const& geos, - Vector const& modes, - Vector const& matrixs = { Matrix3x2() } - ); + // 组合几何体 + Geometry CombineWith( + Geometry input, + CombineMode mode, + Matrix3x2 const& input_matrix = Matrix3x2() + ) const; // 创建直线 static Geometry CreateLine( @@ -133,6 +134,7 @@ namespace kiwano { public: GeometrySink(); + ~GeometrySink(); // 开始添加路径 GeometrySink& BeginPath( @@ -179,6 +181,12 @@ namespace kiwano // 获取生成路径几何体 Geometry GetGeometry(); + // 打开流 + void Open(); + + // 关闭流 + void Close(); + public: inline ComPtr GetPathGeometry() const { return path_geo_; } @@ -190,10 +198,6 @@ namespace kiwano void Init(); - void OpenSink(); - - void CloseSink(); - protected: ComPtr path_geo_; ComPtr sink_; diff --git a/src/kiwano/renderer/RenderTarget.cpp b/src/kiwano/renderer/RenderTarget.cpp index cbe5a428..f1fea6c9 100644 --- a/src/kiwano/renderer/RenderTarget.cpp +++ b/src/kiwano/renderer/RenderTarget.cpp @@ -113,7 +113,7 @@ namespace kiwano } } - void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, StrokeStyle stroke) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -136,7 +136,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::FillGeometry(Geometry const& geometry) const + void RenderTarget::FillGeometry(Geometry const& geometry) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -157,7 +157,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStyle stroke) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -181,7 +181,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, StrokeStyle stroke) { HRESULT hr = S_OK; @@ -205,7 +205,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::FillRectangle(Rect const& rect) const + void RenderTarget::FillRectangle(Rect const& rect) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -226,7 +226,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, StrokeStyle stroke) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -253,7 +253,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::FillRoundedRectangle(Rect const& rect, Vec2 const& radius) const + void RenderTarget::FillRoundedRectangle(Rect const& rect, Vec2 const& radius) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -278,7 +278,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStyle stroke) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -305,7 +305,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::FillEllipse(Point const& center, Vec2 const& radius) const + void RenderTarget::FillEllipse(Point const& center, Vec2 const& radius) { HRESULT hr = S_OK; if (!render_target_ || !current_brush_) @@ -330,12 +330,12 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawTexture(Texture const& texture, Rect const& src_rect, Rect const& dest_rect) const + void RenderTarget::DrawTexture(Texture const& texture, Rect const& src_rect, Rect const& dest_rect) { DrawTexture(texture, &src_rect, &dest_rect); } - void RenderTarget::DrawTexture(Texture const& texture, const Rect* src_rect, const Rect* dest_rect) const + void RenderTarget::DrawTexture(Texture const& texture, const Rect* src_rect, const Rect* dest_rect) { HRESULT hr = S_OK; if (!render_target_) @@ -363,7 +363,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawTextLayout(TextLayout const& layout, Point const& offset) const + void RenderTarget::DrawTextLayout(TextLayout const& layout, Point const& offset) { HRESULT hr = S_OK; if (!text_renderer_) @@ -393,7 +393,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::CreateLayer(LayerArea& layer) const + void RenderTarget::CreateLayer(LayerArea& layer) { HRESULT hr = S_OK; @@ -540,7 +540,7 @@ namespace kiwano return global_transform_; } - ComPtr RenderTarget::GetStrokeStyle(StrokeStyle style) const + ComPtr RenderTarget::GetStrokeStyle(StrokeStyle style) { switch (style) { @@ -710,7 +710,7 @@ namespace kiwano { } - Texture TextureRenderTarget::GetOutput() const + Texture TextureRenderTarget::GetOutput() { HRESULT hr = E_FAIL; diff --git a/src/kiwano/renderer/RenderTarget.h b/src/kiwano/renderer/RenderTarget.h index c886da3e..41f78436 100644 --- a/src/kiwano/renderer/RenderTarget.h +++ b/src/kiwano/renderer/RenderTarget.h @@ -52,75 +52,75 @@ namespace kiwano void CreateLayer( LayerArea& layer - ) const; + ); void DrawGeometry( Geometry const& geometry, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter - ) const; + ); void FillGeometry( Geometry const& geometry - ) const; + ); void DrawLine( Point const& point1, Point const& point2, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter - ) const; + ); void DrawRectangle( Rect const& rect, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter - ) const; + ); void FillRectangle( Rect const& rect - ) const; + ); void DrawRoundedRectangle( Rect const& rect, Vec2 const& radius, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter - ) const; + ); void FillRoundedRectangle( Rect const& rect, Vec2 const& radius - ) const; + ); void DrawEllipse( Point const& center, Vec2 const& radius, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter - ) const; + ); void FillEllipse( Point const& center, Vec2 const& radius - ) const; + ); void DrawTexture( Texture const& texture, Rect const& src_rect, Rect const& dest_rect - ) const; + ); void DrawTexture( Texture const& texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr - ) const; + ); void DrawTextLayout( TextLayout const& layout, Point const& offset = Point{} - ) const; + ); void PushClipRect( Rect const& clip_rect @@ -206,7 +206,7 @@ namespace kiwano inline ComPtr GetTextRenderer() const { KGE_ASSERT(text_renderer_); return text_renderer_; } - ComPtr GetStrokeStyle(StrokeStyle style) const; + ComPtr GetStrokeStyle(StrokeStyle style); public: RenderTarget(); @@ -241,6 +241,6 @@ namespace kiwano public: TextureRenderTarget(); - Texture GetOutput() const; + Texture GetOutput(); }; } diff --git a/src/kiwano/renderer/Renderer.h b/src/kiwano/renderer/Renderer.h index 53488183..14ee8ca6 100644 --- a/src/kiwano/renderer/Renderer.h +++ b/src/kiwano/renderer/Renderer.h @@ -192,9 +192,9 @@ namespace kiwano inline Color const& GetClearColor() const { return clear_color_; } - inline ID2DDeviceResources* GetD2DDeviceResources() const { KGE_ASSERT(d2d_res_); return d2d_res_.get(); } + inline ID2DDeviceResources* GetD2DDeviceResources() { KGE_ASSERT(d2d_res_); return d2d_res_.get(); } - inline ID3DDeviceResources* GetD3DDeviceResources() const { KGE_ASSERT(d3d_res_); return d3d_res_.get(); } + inline ID3DDeviceResources* GetD3DDeviceResources() { KGE_ASSERT(d3d_res_); return d3d_res_.get(); } private: Renderer(); diff --git a/src/kiwano/renderer/TextLayout.h b/src/kiwano/renderer/TextLayout.h index cb5ad358..cc2c6d3c 100644 --- a/src/kiwano/renderer/TextLayout.h +++ b/src/kiwano/renderer/TextLayout.h @@ -76,6 +76,6 @@ namespace kiwano protected: TextStyle style_; TextFormat text_format_; - ComPtr text_layout_; + mutable ComPtr text_layout_; }; } diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.cpp b/src/kiwano/renderer/win32/D2DDeviceResources.cpp index 4ccdb0cd..d6e4bffc 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.cpp +++ b/src/kiwano/renderer/win32/D2DDeviceResources.cpp @@ -66,20 +66,20 @@ namespace kiwano HRESULT CreateTextFormat( _Out_ ComPtr& text_format, _In_ Font const& font - ) const override; + ) override; HRESULT CreateTextLayout( _Out_ ComPtr& text_layout, _In_ String const& text, - _In_ ComPtr const& text_format - ) const override; + _In_ ComPtr text_format + ) override; HRESULT SetD2DDevice( - _In_ ComPtr const& device + _In_ ComPtr device ) override; void SetTargetBitmap( - _In_ ComPtr const& target + _In_ ComPtr target ) override; void DiscardResources() override; @@ -298,7 +298,7 @@ namespace kiwano return hr; } - HRESULT D2DDeviceResources::SetD2DDevice(_In_ ComPtr const& device) + HRESULT D2DDeviceResources::SetD2DDevice(_In_ ComPtr device) { ComPtr device_ctx; @@ -317,7 +317,7 @@ namespace kiwano return hr; } - void D2DDeviceResources::SetTargetBitmap(_In_ ComPtr const& target) + void D2DDeviceResources::SetTargetBitmap(_In_ ComPtr target) { target_bitmap_ = target; if (device_context_) @@ -435,7 +435,7 @@ namespace kiwano return hr; } - HRESULT D2DDeviceResources::CreateTextFormat(_Out_ ComPtr & text_format, _In_ Font const & font) const + HRESULT D2DDeviceResources::CreateTextFormat(_Out_ ComPtr & text_format, _In_ Font const & font) { if (!dwrite_factory_) return E_UNEXPECTED; @@ -460,7 +460,7 @@ namespace kiwano } HRESULT D2DDeviceResources::CreateTextLayout(_Out_ ComPtr& text_layout, _In_ String const& text, - _In_ ComPtr const& text_format) const + _In_ ComPtr text_format) { if (!dwrite_factory_) return E_UNEXPECTED; diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.h b/src/kiwano/renderer/win32/D2DDeviceResources.h index 31ca7a0d..be14483d 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.h +++ b/src/kiwano/renderer/win32/D2DDeviceResources.h @@ -217,34 +217,34 @@ namespace kiwano virtual HRESULT CreateTextFormat( _Out_ ComPtr& text_format, _In_ Font const& font - ) const = 0; + ) = 0; virtual HRESULT CreateTextLayout( _Out_ ComPtr& text_layout, _In_ String const& text, - _In_ ComPtr const& text_format - ) const = 0; + _In_ ComPtr text_format + ) = 0; virtual HRESULT SetD2DDevice( - _In_ ComPtr const& device + _In_ ComPtr device ) = 0; virtual void SetTargetBitmap( - _In_ ComPtr const& target + _In_ ComPtr target ) = 0; virtual void DiscardResources() = 0; - inline ID2D1Factory1* GetFactory() const { KGE_ASSERT(factory_); return factory_.get(); } - inline IWICImagingFactory* GetWICImagingFactory() const { KGE_ASSERT(imaging_factory_); return imaging_factory_.get(); } - inline IDWriteFactory* GetDWriteFactory() const { KGE_ASSERT(dwrite_factory_); return dwrite_factory_.get(); } - inline ID2D1Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); } - inline ID2D1DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); } - inline ID2D1Bitmap1* GetTargetBitmap() const { KGE_ASSERT(target_bitmap_); return target_bitmap_.get(); } + inline ID2D1Factory1* GetFactory() { KGE_ASSERT(factory_); return factory_.get(); } + inline IWICImagingFactory* GetWICImagingFactory() { KGE_ASSERT(imaging_factory_); return imaging_factory_.get(); } + inline IDWriteFactory* GetDWriteFactory() { KGE_ASSERT(dwrite_factory_); return dwrite_factory_.get(); } + inline ID2D1Device* GetDevice() { KGE_ASSERT(device_); return device_.get(); } + inline ID2D1DeviceContext* GetDeviceContext() { KGE_ASSERT(device_context_); return device_context_.get(); } + inline ID2D1Bitmap1* GetTargetBitmap() { KGE_ASSERT(target_bitmap_); return target_bitmap_.get(); } - inline ID2D1StrokeStyle* GetMiterStrokeStyle() const { KGE_ASSERT(miter_stroke_style_); return miter_stroke_style_.get(); } - inline ID2D1StrokeStyle* GetBevelStrokeStyle() const { KGE_ASSERT(bevel_stroke_style_); return bevel_stroke_style_.get(); } - inline ID2D1StrokeStyle* GetRoundStrokeStyle() const { KGE_ASSERT(round_stroke_style_); return round_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetMiterStrokeStyle() { KGE_ASSERT(miter_stroke_style_); return miter_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetBevelStrokeStyle() { KGE_ASSERT(bevel_stroke_style_); return bevel_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetRoundStrokeStyle() { KGE_ASSERT(round_stroke_style_); return round_stroke_style_.get(); } protected: ComPtr factory_; diff --git a/src/kiwano/renderer/win32/D3D10DeviceResources.h b/src/kiwano/renderer/win32/D3D10DeviceResources.h index 9a5962ae..1d72688c 100644 --- a/src/kiwano/renderer/win32/D3D10DeviceResources.h +++ b/src/kiwano/renderer/win32/D3D10DeviceResources.h @@ -35,11 +35,11 @@ namespace kiwano public: static HRESULT Create(ID3D10DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd); - inline ID3D10Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); } - inline ID3D10RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.get(); } - inline ID3D10DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.get(); } - inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); } - inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); } + inline ID3D10Device* GetDevice() { KGE_ASSERT(device_); return device_.get(); } + inline ID3D10RenderTargetView* GetRenderTargetView() { KGE_ASSERT(rt_view_); return rt_view_.get(); } + inline ID3D10DepthStencilView* GetDepthStencilView() { KGE_ASSERT(ds_view_); return ds_view_.get(); } + inline IDXGIFactory* GetDXGIFactory() { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); } + inline IDXGISwapChain* GetDXGISwapChain() { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); } protected: ComPtr device_; diff --git a/src/kiwano/renderer/win32/D3D11DeviceResources.h b/src/kiwano/renderer/win32/D3D11DeviceResources.h index 2e50c2be..a7b9d65a 100644 --- a/src/kiwano/renderer/win32/D3D11DeviceResources.h +++ b/src/kiwano/renderer/win32/D3D11DeviceResources.h @@ -35,12 +35,12 @@ namespace kiwano public: static HRESULT Create(ID3D11DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd); - inline ID3D11Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); } - inline ID3D11DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); } - inline ID3D11RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.get(); } - inline ID3D11DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.get(); } - inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); } - inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); } + inline ID3D11Device* GetDevice() { KGE_ASSERT(device_); return device_.get(); } + inline ID3D11DeviceContext* GetDeviceContext() { KGE_ASSERT(device_context_); return device_context_.get(); } + inline ID3D11RenderTargetView* GetRenderTargetView() { KGE_ASSERT(rt_view_); return rt_view_.get(); } + inline ID3D11DepthStencilView* GetDepthStencilView() { KGE_ASSERT(ds_view_); return ds_view_.get(); } + inline IDXGIFactory* GetDXGIFactory() { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); } + inline IDXGISwapChain* GetDXGISwapChain() { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); } protected: ComPtr device_; diff --git a/src/kiwano/ui/Menu.cpp b/src/kiwano/ui/Menu.cpp index d18531d6..611ccf8b 100644 --- a/src/kiwano/ui/Menu.cpp +++ b/src/kiwano/ui/Menu.cpp @@ -52,7 +52,7 @@ namespace kiwano { enabled_ = enabled; - for (const auto& button : buttons_) + for (auto& button : buttons_) { button->SetEnabled(enabled); } diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h index 15a831e1..ca113b8d 100644 --- a/src/kiwano/utils/ResourceCache.h +++ b/src/kiwano/utils/ResourceCache.h @@ -97,7 +97,7 @@ namespace kiwano auto iter = object_cache_.find(id); if (iter == object_cache_.end()) return nullptr; - return dynamic_cast<_Ty*>((*iter).second.get()); + return const_cast<_Ty*>(dynamic_cast((*iter).second.get())); } protected: