[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / base / cursor / cursor_util.cc
bloba17d94479596a0af88c83c77c867f9f6f94406ab
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"
14 namespace ui {
16 void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
17 gfx::Display::Rotation rotation,
18 SkBitmap* bitmap,
19 gfx::Point* hotpoint) {
20 switch (rotation) {
21 case gfx::Display::ROTATE_0:
22 break;
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);
27 break;
28 case gfx::Display::ROTATE_180:
29 hotpoint->SetPoint(
30 bitmap->width() - hotpoint->x(), bitmap->height() - hotpoint->y());
31 *bitmap = SkBitmapOperations::Rotate(
32 *bitmap, SkBitmapOperations::ROTATION_180_CW);
33 break;
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);
38 break;
41 if (scale < FLT_EPSILON) {
42 NOTREACHED() << "Scale must be larger than 0.";
43 scale = 1.0f;
46 if (scale == 1.0f)
47 return;
49 gfx::Size scaled_size = gfx::ToFlooredSize(
50 gfx::ScaleSize(gfx::Size(bitmap->width(), bitmap->height()), scale));
52 *bitmap = skia::ImageOperations::Resize(
53 *bitmap,
54 skia::ImageOperations::RESIZE_BETTER,
55 scaled_size.width(),
56 scaled_size.height());
57 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale));
60 } // namespace ui