Chromium Code Reviews| Index: webkit/glue/webcursor_aurax11.cc |
| diff --git a/webkit/glue/webcursor_aurax11.cc b/webkit/glue/webcursor_aurax11.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae5333a7051079abe33ca2eff9d4077d217c676c |
| --- /dev/null |
| +++ b/webkit/glue/webcursor_aurax11.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/glue/webcursor.h" |
| + |
| +#include <X11/Xlib.h> |
| +#include <X11/Xcursor/Xcursor.h> |
| +#include <X11/cursorfont.h> |
| + |
| +#include "base/logging.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| +#include "third_party/skia/include/core/SkUnPreMultiply.h" |
| +#include "ui/aura/cursor.h" |
| +#include "ui/base/x/x11_util.h" |
| + |
| +const gfx::PlatformCursor& WebCursor::GetPlatformCursor() { |
| + if (platform_cursor_) |
| + return platform_cursor_; |
| + |
| + SkBitmap bitmap; |
| + bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| + custom_size_.width(), custom_size_.height()); |
| + bitmap.allocPixels(); |
| + memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); |
| + |
| + Display* xdisplay = ui::GetXDisplay(); |
| + image_ = XcursorImageCreate(custom_size_.width(), custom_size_.height()); |
| + image_->xhot = hotspot_.x(); |
| + image_->yhot = hotspot_.y(); |
| + uint8* pixels = (uint8*)image_->pixels; |
|
darin (slow to review)
2012/02/24 06:32:35
nit: use C++ style cast
|
| + // 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
|
| + const int kBytesPerPixel = 4; |
| + |
| + bitmap.lockPixels(); |
| + int height = bitmap.height(), width = bitmap.width(); |
| + for (int y = 0, i = 0; y < height; y++) { |
| + for (int x = 0; x < width; x++) { |
| + uint32 pixel = bitmap.getAddr32(0, y)[x]; |
| + |
| + int alpha = SkColorGetA(pixel); |
| + if (alpha != 0 && alpha != 255) { |
| + SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); |
| + pixels[i + 0] = SkColorGetR(unmultiplied); |
| + pixels[i + 1] = SkColorGetG(unmultiplied); |
| + pixels[i + 2] = SkColorGetB(unmultiplied); |
| + pixels[i + 3] = alpha; |
| + } else { |
| + pixels[i + 0] = SkColorGetR(pixel); |
| + pixels[i + 1] = SkColorGetG(pixel); |
| + pixels[i + 2] = SkColorGetB(pixel); |
| + pixels[i + 3] = alpha; |
| + } |
| + i += kBytesPerPixel; |
| + } |
| + } |
| + bitmap.unlockPixels(); |
| + |
| + platform_cursor_ = XcursorImageLoadCursor(xdisplay, image_); |
| + return platform_cursor_; |
| +} |
| + |
| +void WebCursor::InitPlatformData() { |
| + platform_cursor_ = 0; |
| + image_ = NULL; |
| +} |
| + |
| +bool WebCursor::SerializePlatformData(Pickle* pickle) const { |
| + 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
|
| +} |
| + |
| +bool WebCursor::DeserializePlatformData(const Pickle* pickle, void** iter) { |
| + return true; |
| +} |
| + |
| +bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { |
| + return true; |
| +} |
| + |
| +void WebCursor::CleanupPlatformData() { |
| + if (platform_cursor_) { |
| + XFreeCursor(ui::GetXDisplay(), platform_cursor_); |
| + platform_cursor_ = 0; |
| + } |
| + |
| + if (image_) { |
| + XcursorImageDestroy(image_); |
| + image_ = NULL; |
| + } |
| +} |
| + |
| +void WebCursor::CopyPlatformData(const WebCursor& other) { |
| + platform_cursor_ = other.platform_cursor_; |
| +} |