OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/webcursor.h" | 5 #include "webkit/glue/webcursor.h" |
6 | 6 |
7 #include <X11/Xcursor/Xcursor.h> | 7 #include <X11/Xcursor/Xcursor.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/cursorfont.h> | 9 #include <X11/cursorfont.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 13 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
13 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
14 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
15 | 16 |
16 const ui::PlatformCursor WebCursor::GetPlatformCursor() { | 17 const ui::PlatformCursor WebCursor::GetPlatformCursor() { |
17 if (platform_cursor_) | 18 if (platform_cursor_) |
18 return platform_cursor_; | 19 return platform_cursor_; |
19 | 20 |
20 SkBitmap bitmap; | 21 XcursorImage* image = |
21 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 22 XcursorImageCreate(custom_size_.width(), custom_size_.height()); |
22 custom_size_.width(), custom_size_.height()); | 23 image->xhot = hotspot_.x(); |
23 bitmap.allocPixels(); | 24 image->yhot = hotspot_.y(); |
24 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); | 25 uint32* pixels = image->pixels; |
25 | 26 |
26 XcursorImage* image = ui::SkBitmapToXcursorImage(&bitmap, hotspot_); | 27 if (custom_size_.width() && custom_size_.height()) { |
| 28 SkBitmap bitmap; |
| 29 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 30 custom_size_.width(), custom_size_.height()); |
| 31 bitmap.allocPixels(); |
| 32 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); |
| 33 |
| 34 bitmap.lockPixels(); |
| 35 int height = bitmap.height(), width = bitmap.width(); |
| 36 for (int y = 0, i = 0; y < height; y++) { |
| 37 for (int x = 0; x < width; x++) { |
| 38 uint32 pixel = bitmap.getAddr32(0, y)[x]; |
| 39 int alpha = SkColorGetA(pixel); |
| 40 if (alpha != 0 && alpha != 255) |
| 41 pixels[i] = SkUnPreMultiply::PMColorToColor(pixel); |
| 42 else |
| 43 pixels[i] = pixel; |
| 44 ++i; |
| 45 } |
| 46 } |
| 47 bitmap.unlockPixels(); |
| 48 } |
| 49 |
27 platform_cursor_ = ui::CreateReffedCustomXCursor(image); | 50 platform_cursor_ = ui::CreateReffedCustomXCursor(image); |
28 return platform_cursor_; | 51 return platform_cursor_; |
29 } | 52 } |
30 | 53 |
31 void WebCursor::InitPlatformData() { | 54 void WebCursor::InitPlatformData() { |
32 platform_cursor_ = 0; | 55 platform_cursor_ = 0; |
33 } | 56 } |
34 | 57 |
35 bool WebCursor::SerializePlatformData(Pickle* pickle) const { | 58 bool WebCursor::SerializePlatformData(Pickle* pickle) const { |
36 return true; | 59 return true; |
(...skipping 14 matching lines...) Expand all Loading... |
51 } | 74 } |
52 } | 75 } |
53 | 76 |
54 void WebCursor::CopyPlatformData(const WebCursor& other) { | 77 void WebCursor::CopyPlatformData(const WebCursor& other) { |
55 if (platform_cursor_) | 78 if (platform_cursor_) |
56 ui::UnrefCustomXCursor(platform_cursor_); | 79 ui::UnrefCustomXCursor(platform_cursor_); |
57 platform_cursor_ = other.platform_cursor_; | 80 platform_cursor_ = other.platform_cursor_; |
58 if (platform_cursor_) | 81 if (platform_cursor_) |
59 ui::RefCustomXCursor(platform_cursor_); | 82 ui::RefCustomXCursor(platform_cursor_); |
60 } | 83 } |
OLD | NEW |