[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / cursors / webcursor_ozone.cc
blob0fb17cb38915d58a086cc81ad8230ca0d1a2c2e1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/cursors/webcursor.h"
7 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
8 #include "ui/base/cursor/cursor.h"
9 #include "ui/base/cursor/cursor_util.h"
10 #include "ui/ozone/public/cursor_factory_ozone.h"
12 namespace {
13 const float kMaxCursorWidth = 64.f;
14 const float kMaxCursorHeight = 64.f;
17 namespace content {
19 ui::PlatformCursor WebCursor::GetPlatformCursor() {
20 if (platform_cursor_)
21 return platform_cursor_;
23 SkBitmap bitmap;
24 ImageFromCustomData(&bitmap);
25 gfx::Point hotspot = hotspot_;
27 // TODO(spang): Consider allowing larger cursors if the hardware supports it.
28 float scale = device_scale_factor_ / custom_scale_;
29 scale = std::min(scale, kMaxCursorWidth / bitmap.width());
30 scale = std::min(scale, kMaxCursorHeight / bitmap.height());
32 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, rotation_, &bitmap,
33 &hotspot);
35 platform_cursor_ =
36 ui::CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap, hotspot);
37 return platform_cursor_;
40 void WebCursor::SetDisplayInfo(const gfx::Display& display) {
41 if (rotation_ == display.rotation() &&
42 device_scale_factor_ == display.device_scale_factor())
43 return;
45 device_scale_factor_ = display.device_scale_factor();
46 rotation_ = display.rotation();
47 if (platform_cursor_)
48 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_);
49 platform_cursor_ = NULL;
50 // It is not necessary to recreate platform_cursor_ yet, since it will be
51 // recreated on demand when GetPlatformCursor is called.
54 void WebCursor::InitPlatformData() {
55 platform_cursor_ = NULL;
56 device_scale_factor_ = 1.f;
57 rotation_ = gfx::Display::ROTATE_0;
60 bool WebCursor::SerializePlatformData(base::Pickle* pickle) const {
61 return true;
64 bool WebCursor::DeserializePlatformData(base::PickleIterator* iter) {
65 return true;
68 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
69 return true;
72 void WebCursor::CleanupPlatformData() {
73 if (platform_cursor_) {
74 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_);
75 platform_cursor_ = NULL;
79 void WebCursor::CopyPlatformData(const WebCursor& other) {
80 if (platform_cursor_)
81 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_);
82 platform_cursor_ = other.platform_cursor_;
83 if (platform_cursor_)
84 ui::CursorFactoryOzone::GetInstance()->RefImageCursor(platform_cursor_);
86 device_scale_factor_ = other.device_scale_factor_;
89 } // namespace content