Chromium Code Reviews| 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..8cce0ee95a5d9de7f7c6163698158bbf215e6b5f 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 alphaType) { |
| + if (bitmap->info().alphaType() == alphaType) { |
| + return false; |
| + } |
| + |
| + // Copy the bitmap into a temporary buffer. This will convert alpha type. |
| + SkImageInfo image_info = |
| + SkImageInfo::MakeN32(bitmap->width(), bitmap->height(), alphaType); |
| + 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 the bitmap to have premultiplied |
|
alexst (slow to review)
2015/12/17 20:56:28
double the
kylechar
2015/12/17 21:52:10
Done.
|
| + // alpha, so convert bitmap alpha type if need 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; |