Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit ae124362902ad96f7423b7ad4c3bf44ca0c9d10c
- Author: Daniel Brookes <[email protected]>
- Date: Tue Jun 8 08:24:57 2021 +0800
- Common: Add CreateDelayedMarkupHandle for vector image handle.
- - this is an alternative version of CreateMarkupHandle that won't build
- the markup UI element immediately.
- - instead, we use the stored XAML data (or data stream) to build the
- markup UI element on first draw.
- - this way we only need to actually build the markup when it is
- required for drawing. since we don't measure the UI element here
- either we don't need to worry about that.
- - for Micromine 2022 where we currently are loading ~5000 icons (~1250
- commands, large and small, normal and disabled) the differences are:
- Icon Load Time Initial Memory Usage
- Before ~7000ms ~560mb
- After ~27ms ~160mb
- - the big difference comes from not building icons that aren't actually
- visible yet including things in hidden ribbon tabs, some small icons,
- some large icons and so on. the memory usage grows as those icons are
- loaded on demand.
- diff --git a/Source/Common/XTPImageManager.cpp b/Source/Common/XTPImageManager.cpp
- index dfe106b..35b9d94 100644
- --- a/Source/Common/XTPImageManager.cpp
- +++ b/Source/Common/XTPImageManager.cpp
- @@ -1263,10 +1263,10 @@ CXTPImageManagerVectorImageHandle::CXTPImageManagerVectorImageHandle()
- CXTPImageManagerVectorImageHandle::CXTPImageManagerVectorImageHandle(
- CXTPMarkupContext* pContext, BOOL bSharedContext, CXTPMarkupUIElement* pMarkupElement,
- - HGLOBAL SerializationData)
- + HGLOBAL SerializationData, BOOL bWide)
- : m_pResource(NULL)
- {
- - ASSERT(NULL != pMarkupElement);
- + //ASSERT(NULL != pMarkupElement);
- ASSERT(NULL != pContext);
- m_pResource = new IMAGE_RESOURCE;
- @@ -1275,7 +1275,9 @@ CXTPImageManagerVectorImageHandle::CXTPImageManagerVectorImageHandle(
- m_pResource->u.markup.pContext = pContext;
- m_pResource->u.markup.bSharedContext = bSharedContext;
- m_pResource->u.markup.pMarkupElement = pMarkupElement;
- + m_pResource->u.markup.bDelayed = (pMarkupElement == NULL);
- m_pResource->SerializationData = SerializationData;
- + m_pResource->bWide = bWide;
- m_pResource->pSerializationDataStream = NULL;
- }
- @@ -1284,7 +1286,7 @@ CXTPImageManagerVectorImageHandle::CXTPImageManagerVectorImageHandle(
- IStream* pSerializationDataStream)
- : m_pResource(NULL)
- {
- - ASSERT(NULL != pMarkupElement);
- + //ASSERT(NULL != pMarkupElement);
- ASSERT(NULL != pContext);
- m_pResource = new IMAGE_RESOURCE;
- @@ -1293,7 +1295,9 @@ CXTPImageManagerVectorImageHandle::CXTPImageManagerVectorImageHandle(
- m_pResource->u.markup.pContext = pContext;
- m_pResource->u.markup.bSharedContext = bSharedContext;
- m_pResource->u.markup.pMarkupElement = pMarkupElement;
- + m_pResource->u.markup.bDelayed = (pMarkupElement == NULL);
- m_pResource->SerializationData = NULL;
- + m_pResource->bWide = FALSE;
- m_pResource->pSerializationDataStream = pSerializationDataStream;
- if (NULL != pSerializationDataStream)
- @@ -1395,7 +1399,7 @@ CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateMarku
- GlobalUnlock(hGlobal);
- return CXTPImageManagerVectorImageHandle(pContext, bSharedContext,
- - pMarkupElement, hGlobal);
- + pMarkupElement, hGlobal, FALSE);
- }
- GlobalFree(hGlobal);
- @@ -1452,7 +1456,7 @@ CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateMarku
- GlobalUnlock(hGlobal);
- return CXTPImageManagerVectorImageHandle(pContext, bSharedContext,
- - pMarkupElement, hGlobal);
- + pMarkupElement, hGlobal, TRUE);
- }
- GlobalFree(hGlobal);
- @@ -1465,6 +1469,135 @@ CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateMarku
- return CXTPImageManagerVectorImageHandle();
- }
- +CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateDelayedMarkupHandle(
- + CXTPMarkupContext* pContext, BOOL bSharedContext, IStream* pStream)
- +{
- + ASSERT(pContext);
- + ASSERT(pStream);
- +
- + LARGE_INTEGER pos = { 0 };
- + if (FAILED(pStream->Seek(pos, STREAM_SEEK_SET, 0)))
- + return CXTPImageManagerVectorImageHandle();
- +
- + //CXTPMarkupUIElement* pMarkupElement = XTPMarkupParseText(pContext, pStream);
- + if (/*!pMarkupElement*/ FALSE)
- + return CXTPImageManagerVectorImageHandle();
- +
- + return CXTPImageManagerVectorImageHandle(pContext, bSharedContext, NULL, pStream);
- +}
- +
- +CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateDelayedMarkupHandle(
- + CXTPMarkupContext* pContext, BOOL bSharedContext, HGLOBAL SerializationData)
- +{
- + ASSERT(pContext);
- + ASSERT(SerializationData);
- +
- + IStreamPtr pStream;
- + if (SUCCEEDED(CreateStreamOnHGlobal(SerializationData, TRUE, &pStream)))
- + {
- + CXTPImageManagerVectorImageHandle imgHandle = CreateDelayedMarkupHandle(pContext, bSharedContext,
- + pStream);
- + return imgHandle;
- + }
- +
- + GlobalFree(SerializationData);
- + return CXTPImageManagerVectorImageHandle();
- +}
- +
- +CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateDelayedMarkupHandle(
- + CXTPMarkupContext* pContext, BOOL bSharedContext, LPCSTR lpszCode, INT_PTR nLength)
- +{
- + ASSERT(pContext);
- + ASSERT(lpszCode);
- +
- + if (nLength < 0)
- + nLength = XTPToIntPtrChecked(strlen(lpszCode));
- +
- + if (nLength > 0)
- + {
- + // CXTPMarkupUIElement* pMarkupElement = XTPMarkupParseText(pContext, lpszCode, nLength);
- + if (/*pMarkupElement*/ TRUE)
- + {
- + HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED, XTPToSizeTChecked(nLength));
- + if (hGlobal)
- + {
- + PVOID pBuff = GlobalLock(hGlobal);
- + if (pBuff)
- + {
- + MEMCPY_S(pBuff, lpszCode, XTPToSizeTChecked(nLength));
- + GlobalUnlock(hGlobal);
- +
- + return CXTPImageManagerVectorImageHandle(pContext, bSharedContext,
- + NULL, hGlobal, FALSE);
- + }
- +
- + GlobalFree(hGlobal);
- + }
- +
- + //XTPMarkupReleaseElement(pMarkupElement);
- + }
- + }
- +
- + return CXTPImageManagerVectorImageHandle();
- +}
- +
- +CXTPImageManagerVectorImageHandle CXTPImageManagerVectorImageHandle::CreateDelayedMarkupHandle(
- + CXTPMarkupContext* pContext, BOOL bSharedContext, LPCWSTR lpszCode, INT_PTR nLength)
- +{
- + ASSERT(pContext);
- + ASSERT(lpszCode);
- +
- + if (nLength < 1)
- + nLength = XTPToIntPtrChecked(wcslen(lpszCode));
- +
- + if (nLength > 0)
- + {
- + LPCWSTR lpszInput = lpszCode;
- + const WCHAR UnicodeMarker = 0xFEFF;
- + BOOL hasUnicodeMarker = memcmp((const void*)lpszInput, &UnicodeMarker, sizeof(WCHAR)) == 0
- + ? TRUE
- + : FALSE;
- +
- + //CXTPMarkupUIElement* pMarkupElement = XTPMarkupParseText(pContext, hasUnicodeMarker
- + // ? ++lpszInput
- + // : lpszInput);
- + if (/*pMarkupElement*/ TRUE)
- + {
- + INT_PTR sz = XTPToIntPtrChecked(sizeof(WCHAR)
- + * (hasUnicodeMarker ? nLength : nLength + 1));
- +
- + HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED, XTPToSizeTChecked(sz));
- + if (hGlobal)
- + {
- + PVOID pBuff = GlobalLock(hGlobal);
- + if (pBuff)
- + {
- + if (hasUnicodeMarker)
- + {
- + MEMCPY_S((WCHAR*)pBuff, lpszCode, XTPToSizeTChecked(sz));
- + }
- + else
- + {
- + MEMCPY_S(pBuff, &UnicodeMarker, sizeof(WCHAR));
- + MEMCPY_S((WCHAR*)pBuff + 1, lpszCode, XTPToSizeTChecked(sz));
- + }
- +
- + GlobalUnlock(hGlobal);
- +
- + return CXTPImageManagerVectorImageHandle(pContext, bSharedContext,
- + NULL, hGlobal, TRUE);
- + }
- +
- + GlobalFree(hGlobal);
- + }
- +
- + //XTPMarkupReleaseElement(pMarkupElement);
- + }
- + }
- +
- + return CXTPImageManagerVectorImageHandle();
- +}
- +
- void CXTPImageManagerVectorImageHandle::Reset()
- {
- if (NULL != m_pResource)
- @@ -1516,6 +1649,61 @@ void CXTPImageManagerVectorImageHandle::Draw(CDC* pDC, CPoint pt, CSize szIcon)
- if (IsMarkupImage())
- {
- + if (NULL == m_pResource->u.markup.pMarkupElement && m_pResource->u.markup.bDelayed)
- + {
- + // If markup UI element hasn't been built yet and we are delayed building, build it from the
- + // input markup stored in our resource structure.
- +
- + if (NULL != m_pResource->SerializationData)
- + {
- + HGLOBAL hGlobal = m_pResource->SerializationData;
- + if (hGlobal)
- + {
- + LPVOID pBuff = GlobalLock(hGlobal);
- + if (pBuff)
- + {
- + SIZE_T sz = GlobalSize(hGlobal);
- +
- + if (m_pResource->bWide)
- + {
- + LPCWSTR lpszCode = (LPCWSTR)pBuff;
- + INT_PTR nLength = sz / sizeof(WCHAR);
- +
- + const WCHAR UnicodeMarker = 0xFEFF;
- + BOOL hasUnicodeMarker = memcmp((const void*)lpszCode, &UnicodeMarker, sizeof(WCHAR)) == 0
- + ? TRUE
- + : FALSE;
- + if (hasUnicodeMarker)
- + {
- + ++lpszCode;
- + --nLength;
- + }
- +
- + m_pResource->u.markup.pMarkupElement = XTPMarkupParseText(m_pResource->u.markup.pContext,
- + lpszCode, nLength);
- + }
- + else
- + {
- + LPCSTR lpszCode = (LPCSTR)pBuff;
- + INT_PTR nLength = sz / sizeof(CHAR);
- + m_pResource->u.markup.pMarkupElement = XTPMarkupParseText(m_pResource->u.markup.pContext,
- + lpszCode, nLength);
- + }
- +
- + GlobalUnlock(hGlobal);
- + }
- + }
- +
- + }
- + else if (NULL != m_pResource->pSerializationDataStream)
- + {
- + m_pResource->u.markup.pMarkupElement = XTPMarkupParseText(m_pResource->u.markup.pContext,
- + m_pResource->pSerializationDataStream);
- + }
- +
- + m_pResource->u.markup.bDelayed = FALSE;
- + }
- +
- XTPMarkupRenderElement(m_pResource->u.markup.pMarkupElement, pDC->GetSafeHdc(), rc);
- }
- }
- diff --git a/Source/Common/XTPImageManager.h b/Source/Common/XTPImageManager.h
- index 78abc99..355d031 100644
- --- a/Source/Common/XTPImageManager.h
- +++ b/Source/Common/XTPImageManager.h
- @@ -184,10 +184,26 @@ public:
- LPCWSTR lpszCode,
- INT_PTR nLength = -1);
- +public:
- + static CXTPImageManagerVectorImageHandle CreateDelayedMarkupHandle(CXTPMarkupContext *pContext,
- + BOOL bSharedContext,
- + HGLOBAL SerializationData);
- + static CXTPImageManagerVectorImageHandle CreateDelayedMarkupHandle(CXTPMarkupContext *pContext,
- + BOOL bSharedContext,
- + IStream *pStream);
- + static CXTPImageManagerVectorImageHandle CreateDelayedMarkupHandle(CXTPMarkupContext *pContext,
- + BOOL bSharedContext,
- + LPCSTR lpszCode,
- + INT_PTR nLength = -1);
- + static CXTPImageManagerVectorImageHandle CreateDelayedMarkupHandle(CXTPMarkupContext *pContext,
- + BOOL bSharedContext,
- + LPCWSTR lpszCode,
- + INT_PTR nLength = -1);
- +
- private:
- CXTPImageManagerVectorImageHandle(CXTPMarkupContext* pContext, BOOL bSharedContext,
- CXTPMarkupUIElement* pMarkupElement,
- - HGLOBAL SerializationData);
- + HGLOBAL SerializationData, BOOL bWide);
- CXTPImageManagerVectorImageHandle(CXTPMarkupContext* pContext, BOOL bSharedContext,
- CXTPMarkupUIElement* pMarkupElement,
- IStream* pSerializationData);
- @@ -203,6 +219,7 @@ private:
- MarkupType
- } nType;
- HGLOBAL SerializationData;
- + BOOL bWide;
- IStream* pSerializationDataStream;
- union {
- struct
- @@ -210,6 +227,7 @@ private:
- CXTPMarkupContext* pContext;
- BOOL bSharedContext;
- CXTPMarkupUIElement* pMarkupElement;
- + BOOL bDelayed;
- } markup;
- // more can be added
- } u;
Advertisement
Add Comment
Please, Sign In to add comment