| Index: ui/base/cursor/cursor_util.cc
|
| diff --git a/ui/base/cursor/cursor_util.cc b/ui/base/cursor/cursor_util.cc
|
| index 193ab7361909507b4569d624b88b5885d672c303..0e1d36e5838fb0b6ffcb06e6fe75b1571f13bd0f 100644
|
| --- a/ui/base/cursor/cursor_util.cc
|
| +++ b/ui/base/cursor/cursor_util.cc
|
| @@ -15,10 +15,43 @@
|
|
|
| namespace ui {
|
|
|
| +namespace {
|
| +
|
| +// Converts the SkBitmap to use a different alpha type. Returns true if bitmap
|
| +// was modified, otherwise returns false.
|
| +bool ConvertSkBitmapAlphaType(SkBitmap* bitmap, SkAlphaType alpha_type) {
|
| + if (bitmap->info().alphaType() == alpha_type) {
|
| + return false;
|
| + }
|
| +
|
| + // Copy the bitmap into a temporary buffer. This will convert alpha type.
|
| + SkImageInfo image_info =
|
| + SkImageInfo::MakeN32(bitmap->width(), bitmap->height(), alpha_type);
|
| + std::vector<char> buffer(bitmap->getSize());
|
| + bitmap->readPixels(image_info, &buffer[0], image_info.minRowBytes(), 0, 0);
|
| + // Read the temporary buffer back into the original bitmap.
|
| + bitmap->reset();
|
| + bitmap->allocPixels(image_info);
|
| + memcpy(bitmap->getPixels(), &buffer[0], buffer.size());
|
| +
|
| + return true;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
|
| gfx::Display::Rotation rotation,
|
| SkBitmap* bitmap,
|
| gfx::Point* hotpoint) {
|
| + // SkBitmapOperations::Rotate() needs the bitmap to have premultiplied alpha,
|
| + // so convert bitmap alpha type if we are going to rotate.
|
| + bool was_converted = false;
|
| + if (rotation != gfx::Display::ROTATE_0 &&
|
| + bitmap->info().alphaType() == kUnpremul_SkAlphaType) {
|
| + ConvertSkBitmapAlphaType(bitmap, kPremul_SkAlphaType);
|
| + was_converted = true;
|
| + }
|
| +
|
| switch (rotation) {
|
| case gfx::Display::ROTATE_0:
|
| break;
|
| @@ -40,6 +73,10 @@ void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
|
| break;
|
| }
|
|
|
| + if (was_converted) {
|
| + ConvertSkBitmapAlphaType(bitmap, kUnpremul_SkAlphaType);
|
| + }
|
| +
|
| if (scale < FLT_EPSILON) {
|
| NOTREACHED() << "Scale must be larger than 0.";
|
| scale = 1.0f;
|
|
|