| 6 | using namespace OpenGlass; |
| 7 | |
| 8 | HRESULT CMaterialRealizer::LoadEffect(ID2D1DeviceContext* context) |
| 9 | { |
| 10 | winrt::com_ptr<IStream> stream{ nullptr }; |
| 11 | if ( |
| 12 | Shared::g_materialTexturePath.empty() || |
| 13 | PathIsRelativeW(Shared::g_materialTexturePath.data()) || |
| 14 | PathIsNetworkPathW(Shared::g_materialTexturePath.data()) || |
| 15 | !PathFileExistsW(Shared::g_materialTexturePath.data()) |
| 16 | ) |
| 17 | { |
| 18 | wil::unique_hmodule wucModule |
| 19 | { |
| 20 | LoadLibraryExW( |
| 21 | L"Windows.UI.Xaml.Controls.dll", |
| 22 | nullptr, |
| 23 | LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_SEARCH_SYSTEM32 |
| 24 | ) |
| 25 | }; |
| 26 | |
| 27 | std::span<const UCHAR> materialBytes{}; |
| 28 | RETURN_IF_FAILED(Util::GetResDataView(materialBytes, 2000, wucModule.get())); |
| 29 | |
| 30 | stream = { SHCreateMemStream(materialBytes.data(), static_cast<UINT>(materialBytes.size_bytes())), winrt::take_ownership_from_abi}; |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | wil::unique_hfile file{ CreateFileW(Shared::g_materialTexturePath.data(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0) }; |
| 35 | RETURN_LAST_ERROR_IF(!file.is_valid()); |
| 36 | |
| 37 | LARGE_INTEGER fileSize{}; |
| 38 | RETURN_IF_WIN32_BOOL_FALSE(GetFileSizeEx(file.get(), &fileSize)); |
| 39 | |
| 40 | auto buffer{ std::make_unique<BYTE[]>(static_cast<size_t>(fileSize.QuadPart)) }; |
| 41 | RETURN_IF_WIN32_BOOL_FALSE(ReadFile(file.get(), buffer.get(), static_cast<DWORD>(fileSize.QuadPart), nullptr, nullptr)); |
| 42 | stream = { SHCreateMemStream(buffer.get(), static_cast<UINT>(fileSize.QuadPart)), winrt::take_ownership_from_abi }; |
| 43 | } |
| 44 | RETURN_HR_IF_NULL(E_OUTOFMEMORY, stream); |
| 45 | |
| 46 | winrt::com_ptr<IWICImagingFactory> wicFactory{ nullptr }; |
| 47 | wicFactory.copy_from(uDWM::CDesktopManager::GetInstance()->GetWICFactory()); |
| 48 | winrt::com_ptr<IWICBitmapDecoder> wicDecoder{ nullptr }; |
| 49 | RETURN_IF_FAILED(wicFactory->CreateDecoderFromStream(stream.get(), &GUID_VendorMicrosoft, WICDecodeMetadataCacheOnDemand, wicDecoder.put())); |
| 50 | winrt::com_ptr<IWICBitmapFrameDecode> wicFrame{ nullptr }; |
| 51 | RETURN_IF_FAILED(wicDecoder->GetFrame(0, wicFrame.put())); |
| 52 | winrt::com_ptr<IWICFormatConverter> wicConverter{ nullptr }; |
| 53 | RETURN_IF_FAILED(wicFactory->CreateFormatConverter(wicConverter.put())); |
| 54 | RETURN_IF_FAILED( |
| 55 | wicConverter->Initialize( |
| 56 | wicFrame.get(), |
| 57 | GUID_WICPixelFormat32bppPBGRA, |
| 58 | WICBitmapDitherTypeNone, |
| 59 | nullptr, |
| 60 | 0, |
| 61 | WICBitmapPaletteTypeCustom |
| 62 | ) |
| 63 | ); |
| 64 | |
| 65 | winrt::com_ptr<ID2D1Effect> bitmapSourceEffect{ nullptr }; |
nothing calls this directly
no test coverage detected