1 // Copyright 2014 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.
5 #include "ui/base/cursor/cursor_util.h"
7 #include "base/logging.h"
8 #include "skia/ext/image_operations.h"
9 #include "ui/gfx/point_conversions.h"
10 #include "ui/gfx/size_conversions.h"
11 #include "ui/gfx/skbitmap_operations.h"
12 #include "ui/gfx/skia_util.h"
16 void ScaleAndRotateCursorBitmapAndHotpoint(float scale
,
17 gfx::Display::Rotation rotation
,
19 gfx::Point
* hotpoint
) {
21 case gfx::Display::ROTATE_0
:
23 case gfx::Display::ROTATE_90
:
24 hotpoint
->SetPoint(bitmap
->height() - hotpoint
->y(), hotpoint
->x());
25 *bitmap
= SkBitmapOperations::Rotate(
26 *bitmap
, SkBitmapOperations::ROTATION_90_CW
);
28 case gfx::Display::ROTATE_180
:
30 bitmap
->width() - hotpoint
->x(), bitmap
->height() - hotpoint
->y());
31 *bitmap
= SkBitmapOperations::Rotate(
32 *bitmap
, SkBitmapOperations::ROTATION_180_CW
);
34 case gfx::Display::ROTATE_270
:
35 hotpoint
->SetPoint(hotpoint
->y(), bitmap
->width() - hotpoint
->x());
36 *bitmap
= SkBitmapOperations::Rotate(
37 *bitmap
, SkBitmapOperations::ROTATION_270_CW
);
41 if (scale
< FLT_EPSILON
) {
42 NOTREACHED() << "Scale must be larger than 0.";
49 gfx::Size scaled_size
= gfx::ToFlooredSize(
50 gfx::ScaleSize(gfx::Size(bitmap
->width(), bitmap
->height()), scale
));
52 *bitmap
= skia::ImageOperations::Resize(
54 skia::ImageOperations::RESIZE_BETTER
,
56 scaled_size
.height());
57 *hotpoint
= gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint
, scale
));