dwrite: Update cached bitmap size on Resize() as well.

This commit is contained in:
Nikolay Sivov 2015-07-22 11:54:53 +03:00 committed by Alexandre Julliard
parent a66ba8957e
commit 5178c8b111
2 changed files with 32 additions and 8 deletions

View File

@ -47,12 +47,15 @@ struct rendertarget {
HDC hdc; HDC hdc;
}; };
static HRESULT create_target_dibsection(HDC hdc, UINT32 width, UINT32 height) static HRESULT create_target_dibsection(struct rendertarget *target, UINT32 width, UINT32 height)
{ {
char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])]; char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
BITMAPINFO *bmi = (BITMAPINFO*)bmibuf; BITMAPINFO *bmi = (BITMAPINFO*)bmibuf;
HBITMAP hbm; HBITMAP hbm;
target->size.cx = width;
target->size.cy = height;
memset(bmi, 0, sizeof(bmibuf)); memset(bmi, 0, sizeof(bmibuf));
bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader); bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
bmi->bmiHeader.biHeight = -height; bmi->bmiHeader.biHeight = -height;
@ -61,11 +64,11 @@ static HRESULT create_target_dibsection(HDC hdc, UINT32 width, UINT32 height)
bmi->bmiHeader.biPlanes = 1; bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biCompression = BI_RGB; bmi->bmiHeader.biCompression = BI_RGB;
hbm = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, NULL, NULL, 0); hbm = CreateDIBSection(target->hdc, bmi, DIB_RGB_COLORS, NULL, NULL, 0);
if (!hbm) if (!hbm)
hbm = CreateBitmap(1, 1, 1, 1, NULL); hbm = CreateBitmap(1, 1, 1, 1, NULL);
DeleteObject(SelectObject(hdc, hbm)); DeleteObject(SelectObject(target->hdc, hbm));
return S_OK; return S_OK;
} }
@ -199,7 +202,7 @@ static HRESULT WINAPI rendertarget_Resize(IDWriteBitmapRenderTarget1 *iface, UIN
if (This->size.cx == width && This->size.cy == height) if (This->size.cx == width && This->size.cy == height)
return S_OK; return S_OK;
return create_target_dibsection(This->hdc, width, height); return create_target_dibsection(This, width, height);
} }
static DWRITE_TEXT_ANTIALIAS_MODE WINAPI rendertarget_GetTextAntialiasMode(IDWriteBitmapRenderTarget1 *iface) static DWRITE_TEXT_ANTIALIAS_MODE WINAPI rendertarget_GetTextAntialiasMode(IDWriteBitmapRenderTarget1 *iface)
@ -251,11 +254,8 @@ static HRESULT create_rendertarget(HDC hdc, UINT32 width, UINT32 height, IDWrite
target->IDWriteBitmapRenderTarget1_iface.lpVtbl = &rendertargetvtbl; target->IDWriteBitmapRenderTarget1_iface.lpVtbl = &rendertargetvtbl;
target->ref = 1; target->ref = 1;
target->size.cx = width;
target->size.cy = height;
target->hdc = CreateCompatibleDC(hdc); target->hdc = CreateCompatibleDC(hdc);
hr = create_target_dibsection(target->hdc, width, height); hr = create_target_dibsection(target, width, height);
if (FAILED(hr)) { if (FAILED(hr)) {
IDWriteBitmapRenderTarget1_Release(&target->IDWriteBitmapRenderTarget1_iface); IDWriteBitmapRenderTarget1_Release(&target->IDWriteBitmapRenderTarget1_iface);
return hr; return hr;

View File

@ -849,18 +849,36 @@ if (0) /* crashes on native */
hr = IDWriteBitmapRenderTarget_Resize(target, 5, 5); hr = IDWriteBitmapRenderTarget_Resize(target, 5, 5);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
size.cx = size.cy = -1;
hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size.cx == 5, "got %d\n", size.cx);
ok(size.cy == 5, "got %d\n", size.cy);
hbm2 = GetCurrentObject(hdc, OBJ_BITMAP); hbm2 = GetCurrentObject(hdc, OBJ_BITMAP);
ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm); ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm);
hr = IDWriteBitmapRenderTarget_Resize(target, 20, 5); hr = IDWriteBitmapRenderTarget_Resize(target, 20, 5);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
size.cx = size.cy = -1;
hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size.cx == 20, "got %d\n", size.cx);
ok(size.cy == 5, "got %d\n", size.cy);
hbm2 = GetCurrentObject(hdc, OBJ_BITMAP); hbm2 = GetCurrentObject(hdc, OBJ_BITMAP);
ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm); ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm);
hr = IDWriteBitmapRenderTarget_Resize(target, 1, 5); hr = IDWriteBitmapRenderTarget_Resize(target, 1, 5);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
size.cx = size.cy = -1;
hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size.cx == 1, "got %d\n", size.cx);
ok(size.cy == 5, "got %d\n", size.cy);
hbm2 = GetCurrentObject(hdc, OBJ_BITMAP); hbm2 = GetCurrentObject(hdc, OBJ_BITMAP);
ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm); ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm);
@ -876,6 +894,12 @@ if (0) /* crashes on native */
hr = IDWriteBitmapRenderTarget_Resize(target, 0, 5); hr = IDWriteBitmapRenderTarget_Resize(target, 0, 5);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
size.cx = size.cy = -1;
hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size.cx == 0, "got %d\n", size.cx);
ok(size.cy == 5, "got %d\n", size.cy);
hbm2 = GetCurrentObject(hdc, OBJ_BITMAP); hbm2 = GetCurrentObject(hdc, OBJ_BITMAP);
ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm); ok(hbm2 != hbm, "got %p, %p\n", hbm2, hbm);