Skip to content

Commit

Permalink
Remove hidden cursor from screen
Browse files Browse the repository at this point in the history
Currently ui/resources/cursors/none.cur is used to hide the cursor,
which is a dark 1x1 bit bmp. This may cause DWM to do composition
with the underlay video at very frame. To solve it, the hidden
cursor should be further removed from the screen.

Bug: 1069698
Change-Id: I4122a7a2085dbde5a78053e69f29f988a1b20de4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145234
Reviewed-by: Navid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Cr-Commit-Position: refs/heads/master@{#759481}
  • Loading branch information
jchen10 authored and Commit Bot committed Apr 16, 2020
1 parent cbd7326 commit 379274b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
36 changes: 22 additions & 14 deletions ui/base/cursor/cursor_loader_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) {
return MAKEINTRESOURCE(IDC_COPYCUR);
case mojom::CursorType::kAlias:
return MAKEINTRESOURCE(IDC_ALIAS);
case mojom::CursorType::kNone:
return MAKEINTRESOURCE(IDC_CURSOR_NONE);
case mojom::CursorType::kContextMenu:
case mojom::CursorType::kCustom:
case mojom::CursorType::kNone:
NOTIMPLEMENTED();
return IDC_ARROW;
default:
Expand Down Expand Up @@ -151,19 +150,28 @@ void CursorLoaderWin::UnloadAll() {
}

void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor* cursor) {
if (cursor->type() != mojom::CursorType::kCustom) {
if (cursor->platform()) {
cursor->SetPlatformCursor(cursor->platform());
} else {
const wchar_t* cursor_id = GetCursorId(*cursor);
PlatformCursor platform_cursor = LoadCursor(NULL, cursor_id);
if (!platform_cursor && !g_cursor_resource_module_name.Get().empty()) {
platform_cursor = LoadCursor(
GetModuleHandle(g_cursor_resource_module_name.Get().c_str()),
cursor_id);
}
cursor->SetPlatformCursor(platform_cursor);
if (cursor->type() == mojom::CursorType::kCustom)
return;

// Using a dark 1x1 bit bmp kNone cursor may still cause DWM to do composition
// work unnecessarily. Better to totally remove it from the screen.
// crbug.com/1069698
if (cursor->type() == mojom::CursorType::kNone) {
cursor->SetPlatformCursor(nullptr);
return;
}

if (cursor->platform()) {
cursor->SetPlatformCursor(cursor->platform());
} else {
const wchar_t* cursor_id = GetCursorId(*cursor);
PlatformCursor platform_cursor = LoadCursor(nullptr, cursor_id);
if (!platform_cursor && !g_cursor_resource_module_name.Get().empty()) {
platform_cursor = LoadCursor(
GetModuleHandle(g_cursor_resource_module_name.Get().c_str()),
cursor_id);
}
cursor->SetPlatformCursor(platform_cursor);
}
}

Expand Down
Binary file removed ui/resources/cursors/none.cur
Binary file not shown.
1 change: 0 additions & 1 deletion ui/resources/ui_unscaled_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<include name="IDC_CELL" file="cursors/cell.cur" type="CURSOR" />
<include name="IDC_COLRESIZE" file="cursors/col_resize.cur" type="CURSOR" />
<include name="IDC_COPYCUR" file="cursors/copy.cur" type="CURSOR" />
<include name="IDC_CURSOR_NONE" file="cursors/none.cur" type="CURSOR" />
<include name="IDC_HAND_GRAB" file="cursors/hand_grab.cur" type="CURSOR" />
<include name="IDC_HAND_GRABBING" file="cursors/hand_grabbing.cur" type="CURSOR" />
<include name="IDC_PAN_EAST" file="cursors/pan_east.cur" type="CURSOR" />
Expand Down
13 changes: 3 additions & 10 deletions ui/views/win/hwnd_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate,
use_system_default_icon_(false),
restored_enabled_(false),
current_cursor_(nullptr),
previous_cursor_(nullptr),
dpi_(0),
called_enable_non_client_dpi_scaling_(false),
active_mouse_tracking_flags_(0),
Expand Down Expand Up @@ -864,15 +863,9 @@ bool HWNDMessageHandler::SetTitle(const base::string16& title) {
}

void HWNDMessageHandler::SetCursor(HCURSOR cursor) {
TRACE_EVENT2("ui,input", "HWNDMessageHandler::SetCursor", "cursor", cursor,
"previous_cursor", previous_cursor_);
if (cursor) {
previous_cursor_ = ::SetCursor(cursor);
current_cursor_ = cursor;
} else if (previous_cursor_) {
::SetCursor(previous_cursor_);
previous_cursor_ = nullptr;
}
TRACE_EVENT1("ui,input", "HWNDMessageHandler::SetCursor", "cursor", cursor);
::SetCursor(cursor);
current_cursor_ = cursor;
}

void HWNDMessageHandler::FrameTypeChanged() {
Expand Down
4 changes: 0 additions & 4 deletions ui/views/win/hwnd_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,6 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
// The current cursor.
HCURSOR current_cursor_;

// The last cursor that was active before the current one was selected. Saved
// so that we can restore it.
HCURSOR previous_cursor_;

// The icon created from the bitmap image of the window icon.
base::win::ScopedHICON window_icon_;

Expand Down

0 comments on commit 379274b

Please sign in to comment.