Skip to content

Commit

Permalink
Merge branch 'feature/fix-d2d' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zao committed Jan 9, 2015
2 parents 24946de + 4157780 commit f28c9dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion frontend_direct2d/Direct2D.h
Expand Up @@ -67,7 +67,7 @@ namespace wave
boost::condition_variable pump_alert;
boost::thread* pump_thread;
std::deque<task_data> tasks;
boost::atomic<long> should_terminate;
boost::atomic<bool> should_terminate;

CComPtr<IWICImagingFactory> wic_factory;
CComPtr<IWICBitmap> last_bitmap;
Expand Down Expand Up @@ -96,6 +96,7 @@ namespace wave
visual_frontend_callback& callback;
HWND wnd;

FLOAT dpi[2];
CComPtr<ID2D1Factory> factory;
CComPtr<ID2D1HwndRenderTarget> rt;
CComPtr<ID2D1Bitmap> wave_bitmap;
Expand Down
15 changes: 12 additions & 3 deletions frontend_direct2d/Direct2D1.cc
Expand Up @@ -42,6 +42,8 @@ namespace wave
D2D1_FACTORY_OPTIONS const opts = { };

image_cache::image_cache()
: should_terminate(false)
, bitmap_serial(0)
{
D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, opts, &factory);
CoCreateInstance(CLSID_WICImagingFactory, 0, CLSCTX_ALL, __uuidof(IWICImagingFactory), (void**)&wic_factory);
Expand Down Expand Up @@ -106,6 +108,7 @@ namespace wave
factory.Attach(create_d2d1_factory_func(opts)());
if (!factory)
throw std::runtime_error("Direct2D not found. Ensure you're running Vista SP2 or later with the Platform Update pack.");
factory->GetDesktopDpi(&dpi[0], &dpi[1]);

cache.reset(new image_cache);
cache->start();
Expand All @@ -130,7 +133,10 @@ namespace wave
if (! rt)
{
auto sz = callback.get_size();
factory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(wnd, D2D1::SizeU(sz.cx, sz.cy)), &rt);
D2D1_RENDER_TARGET_PROPERTIES rt_props = D2D1::RenderTargetProperties();
rt_props.dpiX = dpi[0];
rt_props.dpiY = dpi[1];
factory->CreateHwndRenderTarget(rt_props, D2D1::HwndRenderTargetProperties(wnd, D2D1::SizeU(sz.cx, sz.cy)), &rt);
brushes = create_brush_set(rt, colors);
}

Expand Down Expand Up @@ -161,7 +167,10 @@ namespace wave
if (cache->last_bitmap && bitmap_serial < cache->bitmap_serial)
{
wave_bitmap.Release();
rt->CreateBitmapFromWicBitmap(cache->last_bitmap, &wave_bitmap);
D2D1_BITMAP_PROPERTIES bitmap_props = D2D1::BitmapProperties();
bitmap_props.dpiX = dpi[0];
bitmap_props.dpiY = dpi[1];
rt->CreateBitmapFromWicBitmap(cache->last_bitmap, &bitmap_props, &wave_bitmap);
}
if (wave_bitmap)
{
Expand Down Expand Up @@ -298,7 +307,7 @@ namespace wave
while (! SUCCEEDED(hr))
{
CComPtr<ID2D1RenderTarget> temp_target;
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat()); //, dpi[0], dpi[1]);
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat(), dpi[0], dpi[1]);
factory->CreateWicBitmapRenderTarget(bm, props, &temp_target);

brush_set brushes = create_brush_set(temp_target, colors);
Expand Down

0 comments on commit f28c9dd

Please sign in to comment.