void LetterHunter::drawBackgroundImage(wchar_t* imageFile) { static ID2D1Bitmap* pBitmap = NULL; ID2D1RenderTarget* renderTarget = d2d_->getD2DHwndRenderTarget(); static bool isImageLoad = false; if(!isImageLoad) { // Create WIC factory IWICImagingFactory* pWICFactory = NULL ; HRESULT hr = CoCreateInstance( CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, reinterpret_cast<void **>(&pWICFactory) ) ; d2d_->LoadBitmapFromFile( renderTarget, pWICFactory, imageFile, 0, 0, &pBitmap ); isImageLoad = true; } RECT rect; GetWindowRect(hwnd_, &rect); renderTarget->DrawBitmap( pBitmap, D2D1::Rect(rect.left, rect.top, rect.right, rect.bottom) ); }
static void d2d_blit(int x, int y, int y1, int y2, int w, int h) { HRESULT hr = S_OK; void *srcdata; int yy; D2D1_RECT_U rectU; ID2D1Bitmap *fs_bitmap; ID2D1RenderTarget *RT; float fs_x, fs_y; float fs_w = w; float fs_h = h; d2d_log("Direct2D: d2d_blit(x=%d, y=%d, y1=%d, y2=%d, w=%d, h=%d)\n", x, y, y1, y2, w, h); // TODO: Detect double scanned mode and resize render target // appropriately for more clear picture if (w != d2d_width || h != d2d_height) { if (d2d_fs) { if (d2d_btmpRT) { d2d_btmpRT->Release(); d2d_btmpRT = NULL; } hr = d2d_hwndRT->CreateCompatibleRenderTarget( D2D1::SizeF(w, h), &d2d_btmpRT); if (SUCCEEDED(hr)) { d2d_width = w; d2d_height = h; } } else { hr = d2d_hwndRT->Resize(D2D1::SizeU(w, h)); if (SUCCEEDED(hr)) { d2d_width = w; d2d_height = h; } } } if (y1 == y2) { video_blit_complete(); return; } if (buffer32 == NULL) { video_blit_complete(); return; } // TODO: Copy data directly from buffer32 to d2d_bitmap srcdata = malloc(h * w * 4); for (yy = y1; yy < y2; yy++) { if ((y + yy) >= 0 && (y + yy) < buffer32->h) { if (video_grayscale || invert_display) video_transform_copy( (uint32_t *) &(((uint8_t *)srcdata)[yy * w * 4]), &(((uint32_t *)buffer32->line[y + yy])[x]), w); else memcpy( (uint32_t *) &(((uint8_t *)srcdata)[yy * w * 4]), &(((uint32_t *)buffer32->line[y + yy])[x]), w * 4); } } video_blit_complete(); rectU = D2D1::RectU(0, 0, w, h); hr = d2d_bitmap->CopyFromMemory(&rectU, srcdata, w * 4); // In fullscreen mode we first draw offscreen to an intermediate // BitmapRenderTarget, which then gets rendered to the actual // HwndRenderTarget in order to implement different scaling modes // In windowed mode we draw directly to the HwndRenderTarget if (SUCCEEDED(hr)) { RT = d2d_fs ? (ID2D1RenderTarget *) d2d_btmpRT : (ID2D1RenderTarget *) d2d_hwndRT; RT->BeginDraw(); RT->DrawBitmap( d2d_bitmap, D2D1::RectF(0, y1, w, y2), 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1::RectF(0, y1, w, y2)); hr = RT->EndDraw(); } if (d2d_fs) { if (SUCCEEDED(hr)) { hr = d2d_btmpRT->GetBitmap(&fs_bitmap); } if (SUCCEEDED(hr)) { d2d_stretch(&fs_w, &fs_h, &fs_x, &fs_y); d2d_hwndRT->BeginDraw(); d2d_hwndRT->Clear( D2D1::ColorF(D2D1::ColorF::Black)); d2d_hwndRT->DrawBitmap( fs_bitmap, D2D1::RectF(fs_x, fs_y, fs_x + fs_w, fs_y + fs_h), 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF(0, 0, w, h)); hr = d2d_hwndRT->EndDraw(); } } if (FAILED(hr)) { d2d_log("Direct2D: d2d_blit: error 0x%08lx\n", hr); } // Tidy up free(srcdata); srcdata = NULL; }