Codebase list mozc / e253375
Fix missing D2DERR_RECREATE_TARGET handling The root cause of #348 is the lack of D2DERR_RECREATE_TARGET handling in |DirectWriteTextRenderer::dc_render_target_|. We can easily reproduce this issue by manually disabling a display adaptor on the device manager. Note that we actually have had D2DERR_RECREATE_TARGET handling for |dc_render_target_->EndDraw()|, which, however, has never worked because any failure of |dc_render_target_->BindDC(dc, &total_rect)| can cause early exit. With this CL, we can more reliably recover from D2DERR_RECREATE_TARGET state. BUG=#348 TEST=manually done REF_BUG=23803925 REF_CL=137123575 REF_TIME=2016-10-24T23:53:42-07:00 REF_TIME_RAW=1477378422 -0700 Yohei Yukawa 7 years ago
2 changed file(s) with 26 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
2929
3030 MAJOR=2
3131 MINOR=19
32 BUILD=2655
32 BUILD=2656
3333 REVISION=102
3434 # This version represents the version of Mozc IME engine (converter, predictor,
3535 # etc.). This version info is included both in the Mozc server and in the Mozc
368368 virtual void RenderTextList(CDCHandle dc,
369369 const vector<TextRenderingInfo> &display_list,
370370 FONT_TYPE font_type) const {
371 CreateRenderTargetIfNecessary();
372 if (dc_render_target_ == nullptr) {
371 const size_t kMaxTrial = 3;
372 size_t trial = 0;
373 while (true) {
374 CreateRenderTargetIfNecessary();
375 if (dc_render_target_ == nullptr) {
376 // This is not a recoverable error.
377 return;
378 }
379 const HRESULT hr = RenderTextListImpl(dc, display_list, font_type);
380 if (hr == D2DERR_RECREATE_TARGET && trial < kMaxTrial) {
381 // This is a recoverable error just by recreating the render target.
382 dc_render_target_.Release();
383 ++trial;
384 continue;
385 }
386 // For other error codes (including S_OK and S_FALSE), or if we exceed the
387 // maximum number of trials, we simply accept the result here.
373388 return;
374389 }
390 }
391
392 HRESULT RenderTextListImpl(CDCHandle dc,
393 const vector<TextRenderingInfo> &display_list,
394 FONT_TYPE font_type) const {
375395 CRect total_rect;
376396 for (const auto &item : display_list) {
377397 const auto &item_rect = ToCRect(item.rect);
381401 HRESULT hr = S_OK;
382402 hr = dc_render_target_->BindDC(dc, &total_rect);
383403 if (FAILED(hr)) {
384 return;
404 return hr;
385405 }
386406 CComPtr<ID2D1SolidColorBrush> brush;
387407 hr = dc_render_target_->CreateSolidColorBrush(
388408 ToD2DColor(render_info_[font_type].color),
389409 &brush);
390410 if (FAILED(hr)) {
391 return;
411 return hr;
392412 }
393413 D2D1_DRAW_TEXT_OPTIONS option = D2D1_DRAW_TEXT_OPTIONS_NONE;
394414 if (SystemUtil::IsWindows8_1OrLater()) {
411431 brush,
412432 option);
413433 }
414 hr = dc_render_target_->EndDraw();
415 if (hr == D2DERR_RECREATE_TARGET) {
416 dc_render_target_.Release();
417 }
434 return dc_render_target_->EndDraw();
418435 }
419436
420437 Size MeasureStringImpl(FONT_TYPE font_type, const wstring &str,