[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / cursors / webcursor_aurax11.cc
blob8f25225e8ef140d19ba2900c0918800088a967a0
1 // Copyright (c) 2012 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 <X11/cursorfont.h>
8 #include <X11/Xcursor/Xcursor.h>
9 #include <X11/Xlib.h>
11 #include "base/logging.h"
12 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
13 #include "ui/base/cursor/cursor.h"
14 #include "ui/base/cursor/cursor_loader_x11.h"
15 #include "ui/base/cursor/cursor_util.h"
16 #include "ui/base/x/x11_util.h"
18 namespace content {
20 const ui::PlatformCursor WebCursor::GetPlatformCursor() {
21 if (platform_cursor_)
22 return platform_cursor_;
24 if (custom_data_.size() == 0)
25 return 0;
27 SkBitmap bitmap;
28 bitmap.allocN32Pixels(custom_size_.width(), custom_size_.height());
29 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size());
30 gfx::Point hotspot = hotspot_;
31 ui::ScaleAndRotateCursorBitmapAndHotpoint(
32 device_scale_factor_, rotation_, &bitmap, &hotspot);
34 XcursorImage* image = ui::SkBitmapToXcursorImage(&bitmap, hotspot);
35 platform_cursor_ = ui::CreateReffedCustomXCursor(image);
36 return platform_cursor_;
39 void WebCursor::SetDisplayInfo(const gfx::Display& display) {
40 if (rotation_ == display.rotation() &&
41 device_scale_factor_ == display.device_scale_factor())
42 return;
44 device_scale_factor_ = display.device_scale_factor();
45 rotation_ = display.rotation();
46 if (platform_cursor_)
47 ui::UnrefCustomXCursor(platform_cursor_);
48 platform_cursor_ = 0;
49 // It is not necessary to recreate platform_cursor_ yet, since it will be
50 // recreated on demand when GetPlatformCursor is called.
53 void WebCursor::InitPlatformData() {
54 platform_cursor_ = 0;
55 device_scale_factor_ = 1.f;
56 rotation_ = gfx::Display::ROTATE_0;
59 bool WebCursor::SerializePlatformData(Pickle* pickle) const {
60 return true;
63 bool WebCursor::DeserializePlatformData(PickleIterator* iter) {
64 return true;
67 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
68 return true;
71 void WebCursor::CleanupPlatformData() {
72 if (platform_cursor_) {
73 ui::UnrefCustomXCursor(platform_cursor_);
74 platform_cursor_ = 0;
78 void WebCursor::CopyPlatformData(const WebCursor& other) {
79 if (platform_cursor_)
80 ui::UnrefCustomXCursor(platform_cursor_);
81 platform_cursor_ = other.platform_cursor_;
82 if (platform_cursor_)
83 ui::RefCustomXCursor(platform_cursor_);
85 device_scale_factor_ = other.device_scale_factor_;
88 } // namespace content