Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "webkit/glue/webcursor.h" | |
| 6 | |
| 7 #include <X11/Xlib.h> | |
| 8 #include <X11/Xcursor/Xcursor.h> | |
| 9 #include <X11/cursorfont.h> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | |
| 13 #include "third_party/skia/include/core/SkUnPreMultiply.h" | |
| 14 #include "ui/aura/cursor.h" | |
| 15 #include "ui/base/x/x11_util.h" | |
| 16 | |
| 17 const gfx::PlatformCursor& WebCursor::GetPlatformCursor() { | |
| 18 if (platform_cursor_) | |
| 19 return platform_cursor_; | |
| 20 | |
| 21 SkBitmap bitmap; | |
| 22 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 23 custom_size_.width(), custom_size_.height()); | |
| 24 bitmap.allocPixels(); | |
| 25 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); | |
| 26 | |
| 27 Display* xdisplay = ui::GetXDisplay(); | |
| 28 image_ = XcursorImageCreate(custom_size_.width(), custom_size_.height()); | |
| 29 image_->xhot = hotspot_.x(); | |
| 30 image_->yhot = hotspot_.y(); | |
| 31 uint8* pixels = (uint8*)image_->pixels; | |
|
darin (slow to review)
2012/02/24 06:32:35
nit: use C++ style cast
| |
| 32 // SkBitmaps are premultiplied, we need to unpremultiply them. | |
|
darin (slow to review)
2012/02/24 06:32:35
is there really no common routine somewhere to unp
sadrul
2012/02/24 17:38:19
Indeed there is, for GTK+. In my effort to refacto
| |
| 33 const int kBytesPerPixel = 4; | |
| 34 | |
| 35 bitmap.lockPixels(); | |
| 36 int height = bitmap.height(), width = bitmap.width(); | |
| 37 for (int y = 0, i = 0; y < height; y++) { | |
| 38 for (int x = 0; x < width; x++) { | |
| 39 uint32 pixel = bitmap.getAddr32(0, y)[x]; | |
| 40 | |
| 41 int alpha = SkColorGetA(pixel); | |
| 42 if (alpha != 0 && alpha != 255) { | |
| 43 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); | |
| 44 pixels[i + 0] = SkColorGetR(unmultiplied); | |
| 45 pixels[i + 1] = SkColorGetG(unmultiplied); | |
| 46 pixels[i + 2] = SkColorGetB(unmultiplied); | |
| 47 pixels[i + 3] = alpha; | |
| 48 } else { | |
| 49 pixels[i + 0] = SkColorGetR(pixel); | |
| 50 pixels[i + 1] = SkColorGetG(pixel); | |
| 51 pixels[i + 2] = SkColorGetB(pixel); | |
| 52 pixels[i + 3] = alpha; | |
| 53 } | |
| 54 i += kBytesPerPixel; | |
| 55 } | |
| 56 } | |
| 57 bitmap.unlockPixels(); | |
| 58 | |
| 59 platform_cursor_ = XcursorImageLoadCursor(xdisplay, image_); | |
| 60 return platform_cursor_; | |
| 61 } | |
| 62 | |
| 63 void WebCursor::InitPlatformData() { | |
| 64 platform_cursor_ = 0; | |
| 65 image_ = NULL; | |
| 66 } | |
| 67 | |
| 68 bool WebCursor::SerializePlatformData(Pickle* pickle) const { | |
| 69 return true; | |
|
darin (slow to review)
2012/02/24 06:32:35
nit: should these assert not reached?
sadrul
2012/02/24 17:38:19
I am unsure if we want to NOTREACHED here. So I ke
| |
| 70 } | |
| 71 | |
| 72 bool WebCursor::DeserializePlatformData(const Pickle* pickle, void** iter) { | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 void WebCursor::CleanupPlatformData() { | |
| 81 if (platform_cursor_) { | |
| 82 XFreeCursor(ui::GetXDisplay(), platform_cursor_); | |
| 83 platform_cursor_ = 0; | |
| 84 } | |
| 85 | |
| 86 if (image_) { | |
| 87 XcursorImageDestroy(image_); | |
| 88 image_ = NULL; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void WebCursor::CopyPlatformData(const WebCursor& other) { | |
| 93 platform_cursor_ = other.platform_cursor_; | |
| 94 } | |
| OLD | NEW |