diff options
Diffstat (limited to 'core/fxge/win32')
-rw-r--r-- | core/fxge/win32/fx_win32_device.cpp | 14 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_dib.cpp | 15 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_dwrite.cpp | 81 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_gdipext.cpp | 82 | ||||
-rw-r--r-- | core/fxge/win32/win32_int.h | 6 |
5 files changed, 135 insertions, 63 deletions
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index c2084f2877..2df5c1c4ce 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -939,6 +939,10 @@ FX_BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect) { return ::GetClipBox(m_hDC, (RECT*)pRect); } +void* CGdiDeviceDriver::GetPlatformSurface() const { + return (void*)m_hDC; +} + void CGdiDeviceDriver::DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, @@ -1363,6 +1367,16 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource, dest_height, flags, nullptr); } +FX_BOOL CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap, + int bitmap_alpha, + uint32_t color, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + void*& handle, + int blend_type) { + return FALSE; +} + CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC) { SetDeviceDriver(CreateDriver(hDC)); } diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp index 7221d10536..0e79399357 100644 --- a/core/fxge/win32/fx_win32_dib.cpp +++ b/core/fxge/win32/fx_win32_dib.cpp @@ -51,6 +51,7 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) { result.ReleaseBuffer(len); return result; } + CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData, FX_BOOL bAlpha) { @@ -97,21 +98,25 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, } return pBitmap; } + CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) { return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, FALSE); } + HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) { CFX_ByteString info = GetBitmapInfo(pBitmap); return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT, pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); } + void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) { BITMAP bmp; GetObject(hBitmap, sizeof bmp, &bmp); w = bmp.bmWidth; h = bmp.bmHeight; } + CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_WCHAR* filename) { CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); @@ -145,6 +150,11 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_WCHAR* filename) { DeleteDC(hDC); return pDIBitmap; } + +CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_CHAR* filename) { + return LoadFromFile(CFX_WideString::FromLocal(filename).c_str()); +} + CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) { CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); @@ -178,6 +188,7 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) { DeleteDC(hDC); return pDIBitmap; } + CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, HBITMAP hBitmap, uint32_t* pPalette, @@ -259,6 +270,7 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, } return pDIBitmap; } + CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) { Create(width, height, FXDIB_Rgb, (uint8_t*)1); BITMAPINFOHEADER bmih; @@ -273,14 +285,17 @@ CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) { m_hMemDC = CreateCompatibleDC(hDC); m_hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap); } + CFX_WindowsDIB::~CFX_WindowsDIB() { SelectObject(m_hMemDC, m_hOldBitmap); DeleteDC(m_hMemDC); DeleteObject(m_hBitmap); } + void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) { ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); } + void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) { ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); } diff --git a/core/fxge/win32/fx_win32_dwrite.cpp b/core/fxge/win32/fx_win32_dwrite.cpp index 5f620cba4c..b3ba28cfc7 100644 --- a/core/fxge/win32/fx_win32_dwrite.cpp +++ b/core/fxge/win32/fx_win32_dwrite.cpp @@ -30,22 +30,29 @@ inline InterfaceType* SafeAcquire(InterfaceType* newObject) { } return newObject; } + class CDwFontFileStream final : public IDWriteFontFileStream { public: explicit CDwFontFileStream(void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize); - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, - void** ppvObject); - virtual ULONG STDMETHODCALLTYPE AddRef(); - virtual ULONG STDMETHODCALLTYPE Release(); - virtual HRESULT STDMETHODCALLTYPE + + // IUnknown. + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, + void** ppvObject) override; + ULONG STDMETHODCALLTYPE AddRef() override; + ULONG STDMETHODCALLTYPE Release() override; + + // IDWriteFontFileStream. + HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart, UINT64 fileOffset, UINT64 fragmentSize, - OUT void** fragmentContext); - virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); - virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize); - virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime); + OUT void** fragmentContext) override; + void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext) override; + HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize) override; + HRESULT STDMETHODCALLTYPE + GetLastWriteTime(OUT UINT64* lastWriteTime) override; + bool IsInitialized() { return !!resourcePtr_; } private: @@ -53,16 +60,20 @@ class CDwFontFileStream final : public IDWriteFontFileStream { void const* resourcePtr_; DWORD resourceSize_; }; + class CDwFontFileLoader final : public IDWriteFontFileLoader { public: - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, - void** ppvObject); - virtual ULONG STDMETHODCALLTYPE AddRef(); - virtual ULONG STDMETHODCALLTYPE Release(); - virtual HRESULT STDMETHODCALLTYPE + // IUnknown. + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, + void** ppvObject) override; + ULONG STDMETHODCALLTYPE AddRef() override; + ULONG STDMETHODCALLTYPE Release() override; + + // IDWriteFontFileLoader. + HRESULT STDMETHODCALLTYPE CreateStreamFromKey(void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize, - OUT IDWriteFontFileStream** fontFileStream); + OUT IDWriteFontFileStream** fontFileStream) override; static IDWriteFontFileLoader* GetLoader() { if (!instance_) { @@ -77,10 +88,12 @@ class CDwFontFileLoader final : public IDWriteFontFileLoader { ULONG refCount_; static IDWriteFontFileLoader* instance_; }; + class CDwFontContext { public: CDwFontContext(IDWriteFactory* dwriteFactory); ~CDwFontContext(); + HRESULT Initialize(); private: @@ -89,12 +102,14 @@ class CDwFontContext { HRESULT hr_; IDWriteFactory* dwriteFactory_; }; + class CDwGdiTextRenderer { public: CDwGdiTextRenderer(CFX_DIBitmap* pBitmap, IDWriteBitmapRenderTarget* bitmapRenderTarget, IDWriteRenderingParams* renderingParams); ~CDwGdiTextRenderer(); + HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox, __in_opt CFX_ClipRgn* pClipRgn, __in_opt DWRITE_MATRIX const* pMatrix, @@ -109,13 +124,15 @@ class CDwGdiTextRenderer { IDWriteBitmapRenderTarget* pRenderTarget_; IDWriteRenderingParams* pRenderingParams_; }; -CDWriteExt::CDWriteExt() { - m_hModule = nullptr; - m_pDWriteFactory = nullptr; - m_pDwFontContext = nullptr; - m_pDwTextRenderer = nullptr; -} + +CDWriteExt::CDWriteExt() + : m_hModule(nullptr), + m_pDWriteFactory(nullptr), + m_pDwFontContext(nullptr), + m_pDwTextRenderer(nullptr) {} + void CDWriteExt::Load() {} + void CDWriteExt::Unload() { if (m_pDwFontContext) { delete (CDwFontContext*)m_pDwFontContext; @@ -123,9 +140,11 @@ void CDWriteExt::Unload() { } SafeRelease((IDWriteFactory**)&m_pDWriteFactory); } + CDWriteExt::~CDWriteExt() { Unload(); } + LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, uint32_t size, int simulation_style) { @@ -162,6 +181,7 @@ failed: SafeRelease(&pDwFontFile); return nullptr; } + FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, void** renderTarget) { if (pBitmap->GetFormat() > FXDIB_Argb) { @@ -203,6 +223,7 @@ failed: SafeRelease(&pRenderingParams); return FALSE; } + FX_BOOL CDWriteExt::DwRendingString(void* renderTarget, CFX_ClipRgn* pClipRgn, FX_RECT& stringRect, @@ -245,20 +266,24 @@ FX_BOOL CDWriteExt::DwRendingString(void* renderTarget, RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); return SUCCEEDED(hr); } + void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { delete (CDwGdiTextRenderer*)renderTarget; } + void CDWriteExt::DwDeleteFont(void* pFont) { if (pFont) { SafeRelease((IDWriteFontFace**)&pFont); } } + CDwFontFileStream::CDwFontFileStream(void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize) { refCount_ = 0; resourcePtr_ = fontFileReferenceKey; resourceSize_ = fontFileReferenceKeySize; } + HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, void** ppvObject) { if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { @@ -269,9 +294,11 @@ HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, *ppvObject = nullptr; return E_NOINTERFACE; } + ULONG STDMETHODCALLTYPE CDwFontFileStream::AddRef() { return InterlockedIncrement((long*)(&refCount_)); } + ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { ULONG newCount = InterlockedDecrement((long*)(&refCount_)); if (newCount == 0) { @@ -279,6 +306,7 @@ ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { } return newCount; } + HRESULT STDMETHODCALLTYPE CDwFontFileStream::ReadFileFragment(void const** fragmentStart, UINT64 fileOffset, @@ -295,17 +323,20 @@ CDwFontFileStream::ReadFileFragment(void const** fragmentStart, *fragmentContext = nullptr; return E_FAIL; } + void STDMETHODCALLTYPE CDwFontFileStream::ReleaseFileFragment(void* fragmentContext) {} HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetFileSize(OUT UINT64* fileSize) { *fileSize = resourceSize_; return S_OK; } + HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetLastWriteTime(OUT UINT64* lastWriteTime) { *lastWriteTime = 0; return E_NOTIMPL; } + IDWriteFontFileLoader* CDwFontFileLoader::instance_ = nullptr; CDwFontFileLoader::CDwFontFileLoader() : refCount_(0) {} HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, @@ -318,9 +349,11 @@ HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, *ppvObject = nullptr; return E_NOINTERFACE; } + ULONG STDMETHODCALLTYPE CDwFontFileLoader::AddRef() { return InterlockedIncrement((long*)(&refCount_)); } + ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { ULONG newCount = InterlockedDecrement((long*)(&refCount_)); if (newCount == 0) { @@ -329,6 +362,7 @@ ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { } return newCount; } + HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize, @@ -343,14 +377,17 @@ HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( *fontFileStream = SafeAcquire(stream); return S_OK; } + CDwFontContext::CDwFontContext(IDWriteFactory* dwriteFactory) : hr_(S_FALSE), dwriteFactory_(SafeAcquire(dwriteFactory)) {} + CDwFontContext::~CDwFontContext() { if (dwriteFactory_ && hr_ == S_OK) { dwriteFactory_->UnregisterFontFileLoader(CDwFontFileLoader::GetLoader()); } SafeRelease(&dwriteFactory_); } + HRESULT CDwFontContext::Initialize() { if (hr_ == S_FALSE) { return hr_ = dwriteFactory_->RegisterFontFileLoader( @@ -358,6 +395,7 @@ HRESULT CDwFontContext::Initialize() { } return hr_; } + CDwGdiTextRenderer::CDwGdiTextRenderer( CFX_DIBitmap* pBitmap, IDWriteBitmapRenderTarget* bitmapRenderTarget, @@ -369,6 +407,7 @@ CDwGdiTextRenderer::~CDwGdiTextRenderer() { SafeRelease(&pRenderTarget_); SafeRelease(&pRenderingParams_); } + STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun( const FX_RECT& text_bbox, __in_opt CFX_ClipRgn* pClipRgn, diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp index 68b9aaa80e..3de1b5a8d5 100644 --- a/core/fxge/win32/fx_win32_gdipext.cpp +++ b/core/fxge/win32/fx_win32_gdipext.cpp @@ -1258,18 +1258,14 @@ FX_BOOL CGdiplusExt::DrawPath(HDC hDC, CallFunc(GdipDeleteGraphics)(pGraphics); return TRUE; } -class GpStream final : public IStream { - LONG m_RefCount; - int m_ReadPos; - CFX_ByteTextBuf m_InterStream; +class GpStream final : public IStream { public: - GpStream() { - m_RefCount = 1; - m_ReadPos = 0; - } - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, - void** ppvObject) { + GpStream() : m_RefCount(1), m_ReadPos(0) {} + + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, + void** ppvObject) override { if (iid == __uuidof(IUnknown) || iid == __uuidof(IStream) || iid == __uuidof(ISequentialStream)) { *ppvObject = static_cast<IStream*>(this); @@ -1278,10 +1274,10 @@ class GpStream final : public IStream { } return E_NOINTERFACE; } - virtual ULONG STDMETHODCALLTYPE AddRef(void) { + ULONG STDMETHODCALLTYPE AddRef(void) override { return (ULONG)InterlockedIncrement(&m_RefCount); } - virtual ULONG STDMETHODCALLTYPE Release(void) { + ULONG STDMETHODCALLTYPE Release(void) override { ULONG res = (ULONG)InterlockedDecrement(&m_RefCount); if (res == 0) { delete this; @@ -1289,10 +1285,10 @@ class GpStream final : public IStream { return res; } - public: - virtual HRESULT STDMETHODCALLTYPE Read(void* Output, - ULONG cb, - ULONG* pcbRead) { + // ISequentialStream + HRESULT STDMETHODCALLTYPE Read(void* Output, + ULONG cb, + ULONG* pcbRead) override { size_t bytes_left; size_t bytes_out; if (pcbRead) { @@ -1310,9 +1306,9 @@ class GpStream final : public IStream { } return S_OK; } - virtual HRESULT STDMETHODCALLTYPE Write(void const* Input, - ULONG cb, - ULONG* pcbWritten) { + HRESULT STDMETHODCALLTYPE Write(void const* Input, + ULONG cb, + ULONG* pcbWritten) override { if (cb <= 0) { if (pcbWritten) { *pcbWritten = 0; @@ -1326,34 +1322,34 @@ class GpStream final : public IStream { return S_OK; } - public: - virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER) { + // IStream + HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER) override { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream*, - ULARGE_INTEGER, - ULARGE_INTEGER*, - ULARGE_INTEGER*) { + HRESULT STDMETHODCALLTYPE CopyTo(IStream*, + ULARGE_INTEGER, + ULARGE_INTEGER*, + ULARGE_INTEGER*) override { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE Commit(DWORD) { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE Revert(void) { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER, - ULARGE_INTEGER, - DWORD) { + HRESULT STDMETHODCALLTYPE Commit(DWORD) override { return E_NOTIMPL; } + HRESULT STDMETHODCALLTYPE Revert(void) override { return E_NOTIMPL; } + HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER, + ULARGE_INTEGER, + DWORD) override { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER, - ULARGE_INTEGER, - DWORD) { + HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER, + ULARGE_INTEGER, + DWORD) override { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE Clone(IStream** stream) { + HRESULT STDMETHODCALLTYPE Clone(IStream** stream) override { return E_NOTIMPL; } - virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove, - DWORD dwOrigin, - ULARGE_INTEGER* lpNewFilePointer) { + HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove, + DWORD dwOrigin, + ULARGE_INTEGER* lpNewFilePointer) override { long start = 0; long new_read_position; switch (dwOrigin) { @@ -1381,7 +1377,8 @@ class GpStream final : public IStream { } return S_OK; } - virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg, DWORD grfStatFlag) { + HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg, + DWORD grfStatFlag) override { if (!pStatstg) { return STG_E_INVALIDFUNCTION; } @@ -1389,7 +1386,13 @@ class GpStream final : public IStream { pStatstg->cbSize.QuadPart = m_InterStream.GetLength(); return S_OK; } + + private: + LONG m_RefCount; + int m_ReadPos; + CFX_ByteTextBuf m_InterStream; }; + typedef struct { BITMAPINFO* pbmi; int Stride; @@ -1398,6 +1401,7 @@ typedef struct { BitmapData* pBitmapData; GpStream* pStream; } PREVIEW3_DIBITMAP; + static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args) { GpBitmap* pBitmap; GpStream* pStream = nullptr; @@ -1477,6 +1481,7 @@ static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args) { pInfo->pStream = pStream; return pInfo; } + static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) { CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; @@ -1489,6 +1494,7 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) { } FX_Free(pInfo); } + CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData, FX_BOOL bAlpha); diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index e0952706fa..b09c4ebbd5 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h @@ -137,7 +137,7 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver { uint32_t color, int blend_type) override; FX_BOOL GetClipBox(FX_RECT* pRect) override; - void* GetPlatformSurface() const override { return (void*)m_hDC; } + void* GetPlatformSurface() const override; void DrawLine(FX_FLOAT x1, FX_FLOAT y1, @@ -203,9 +203,7 @@ class CGdiDisplayDriver : public CGdiDeviceDriver { const CFX_Matrix* pMatrix, uint32_t render_flags, void*& handle, - int blend_type) override { - return FALSE; - } + int blend_type) override; FX_BOOL UseFoxitStretchEngine(const CFX_DIBSource* pSource, uint32_t color, int dest_left, |