Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: ui/base/cursor/cursor_util.cc

Issue 1514723003: Fix bug where custom cursors would dissappear when screen was rotated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change DCHECK to DCHECK_NE Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/skbitmap_operations.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | ui/gfx/skbitmap_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698