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

Side by Side Diff: ui/base/cursor/cursor_util.cc

Issue 1917083002: Move gfx::Display/Screen to display::Display/Screen in ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « ui/base/cursor/cursor_util.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/cursor/cursor_util.h" 5 #include "ui/base/cursor/cursor_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "skia/ext/image_operations.h" 8 #include "skia/ext/image_operations.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/geometry/point_conversions.h" 10 #include "ui/gfx/geometry/point_conversions.h"
(...skipping 22 matching lines...) Expand all
33 bitmap->reset(); 33 bitmap->reset();
34 bitmap->allocPixels(image_info); 34 bitmap->allocPixels(image_info);
35 memcpy(bitmap->getPixels(), &buffer[0], buffer.size()); 35 memcpy(bitmap->getPixels(), &buffer[0], buffer.size());
36 36
37 return true; 37 return true;
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 void ScaleAndRotateCursorBitmapAndHotpoint(float scale, 42 void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
43 gfx::Display::Rotation rotation, 43 display::Display::Rotation rotation,
44 SkBitmap* bitmap, 44 SkBitmap* bitmap,
45 gfx::Point* hotpoint) { 45 gfx::Point* hotpoint) {
46 // SkBitmapOperations::Rotate() needs the bitmap to have premultiplied alpha, 46 // SkBitmapOperations::Rotate() needs the bitmap to have premultiplied alpha,
47 // so convert bitmap alpha type if we are going to rotate. 47 // so convert bitmap alpha type if we are going to rotate.
48 bool was_converted = false; 48 bool was_converted = false;
49 if (rotation != gfx::Display::ROTATE_0 && 49 if (rotation != display::Display::ROTATE_0 &&
50 bitmap->info().alphaType() == kUnpremul_SkAlphaType) { 50 bitmap->info().alphaType() == kUnpremul_SkAlphaType) {
51 ConvertSkBitmapAlphaType(bitmap, kPremul_SkAlphaType); 51 ConvertSkBitmapAlphaType(bitmap, kPremul_SkAlphaType);
52 was_converted = true; 52 was_converted = true;
53 } 53 }
54 54
55 switch (rotation) { 55 switch (rotation) {
56 case gfx::Display::ROTATE_0: 56 case display::Display::ROTATE_0:
57 break; 57 break;
58 case gfx::Display::ROTATE_90: 58 case display::Display::ROTATE_90:
59 hotpoint->SetPoint(bitmap->height() - hotpoint->y(), hotpoint->x()); 59 hotpoint->SetPoint(bitmap->height() - hotpoint->y(), hotpoint->x());
60 *bitmap = SkBitmapOperations::Rotate( 60 *bitmap = SkBitmapOperations::Rotate(
61 *bitmap, SkBitmapOperations::ROTATION_90_CW); 61 *bitmap, SkBitmapOperations::ROTATION_90_CW);
62 break; 62 break;
63 case gfx::Display::ROTATE_180: 63 case display::Display::ROTATE_180:
64 hotpoint->SetPoint( 64 hotpoint->SetPoint(
65 bitmap->width() - hotpoint->x(), bitmap->height() - hotpoint->y()); 65 bitmap->width() - hotpoint->x(), bitmap->height() - hotpoint->y());
66 *bitmap = SkBitmapOperations::Rotate( 66 *bitmap = SkBitmapOperations::Rotate(
67 *bitmap, SkBitmapOperations::ROTATION_180_CW); 67 *bitmap, SkBitmapOperations::ROTATION_180_CW);
68 break; 68 break;
69 case gfx::Display::ROTATE_270: 69 case display::Display::ROTATE_270:
70 hotpoint->SetPoint(hotpoint->y(), bitmap->width() - hotpoint->x()); 70 hotpoint->SetPoint(hotpoint->y(), bitmap->width() - hotpoint->x());
71 *bitmap = SkBitmapOperations::Rotate( 71 *bitmap = SkBitmapOperations::Rotate(
72 *bitmap, SkBitmapOperations::ROTATION_270_CW); 72 *bitmap, SkBitmapOperations::ROTATION_270_CW);
73 break; 73 break;
74 } 74 }
75 75
76 if (was_converted) { 76 if (was_converted) {
77 ConvertSkBitmapAlphaType(bitmap, kUnpremul_SkAlphaType); 77 ConvertSkBitmapAlphaType(bitmap, kUnpremul_SkAlphaType);
78 } 78 }
79 79
(...skipping 11 matching lines...) Expand all
91 *bitmap = skia::ImageOperations::Resize( 91 *bitmap = skia::ImageOperations::Resize(
92 *bitmap, 92 *bitmap,
93 skia::ImageOperations::RESIZE_BETTER, 93 skia::ImageOperations::RESIZE_BETTER,
94 scaled_size.width(), 94 scaled_size.width(),
95 scaled_size.height()); 95 scaled_size.height());
96 *hotpoint = gfx::ScaleToFlooredPoint(*hotpoint, scale); 96 *hotpoint = gfx::ScaleToFlooredPoint(*hotpoint, scale);
97 } 97 }
98 98
99 void GetImageCursorBitmap(int resource_id, 99 void GetImageCursorBitmap(int resource_id,
100 float scale, 100 float scale,
101 gfx::Display::Rotation rotation, 101 display::Display::Rotation rotation,
102 gfx::Point* hotspot, 102 gfx::Point* hotspot,
103 SkBitmap* bitmap) { 103 SkBitmap* bitmap) {
104 const gfx::ImageSkia* image = 104 const gfx::ImageSkia* image =
105 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 105 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
106 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); 106 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale);
107 // TODO(oshima): The cursor should use resource scale factor when 107 // TODO(oshima): The cursor should use resource scale factor when
108 // fractional scale factor is enabled. crbug.com/372212 108 // fractional scale factor is enabled. crbug.com/372212
109 (*bitmap) = image_rep.sk_bitmap(); 109 (*bitmap) = image_rep.sk_bitmap();
110 ScaleAndRotateCursorBitmapAndHotpoint( 110 ScaleAndRotateCursorBitmapAndHotpoint(
111 scale / image_rep.scale(), rotation, bitmap, hotspot); 111 scale / image_rep.scale(), rotation, bitmap, hotspot);
112 // |image_rep| is owned by the resource bundle. So we do not need to free it. 112 // |image_rep| is owned by the resource bundle. So we do not need to free it.
113 } 113 }
114 114
115 void GetAnimatedCursorBitmaps(int resource_id, 115 void GetAnimatedCursorBitmaps(int resource_id,
116 float scale, 116 float scale,
117 gfx::Display::Rotation rotation, 117 display::Display::Rotation rotation,
118 gfx::Point* hotspot, 118 gfx::Point* hotspot,
119 std::vector<SkBitmap>* bitmaps) { 119 std::vector<SkBitmap>* bitmaps) {
120 // TODO(oshima|tdanderson): Support rotation and fractional scale factor. 120 // TODO(oshima|tdanderson): Support rotation and fractional scale factor.
121 const gfx::ImageSkia* image = 121 const gfx::ImageSkia* image =
122 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 122 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
123 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); 123 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale);
124 SkBitmap bitmap = image_rep.sk_bitmap(); 124 SkBitmap bitmap = image_rep.sk_bitmap();
125 int frame_width = bitmap.height(); 125 int frame_width = bitmap.height();
126 int frame_height = frame_width; 126 int frame_height = frame_width;
127 int total_width = bitmap.width(); 127 int total_width = bitmap.width();
(...skipping 10 matching lines...) Expand all
138 SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap( 138 SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap(
139 bitmap, x_offset, 0, frame_width, frame_height); 139 bitmap, x_offset, 0, frame_width, frame_height);
140 DCHECK_EQ(frame_width, cropped.width()); 140 DCHECK_EQ(frame_width, cropped.width());
141 DCHECK_EQ(frame_height, cropped.height()); 141 DCHECK_EQ(frame_height, cropped.height());
142 142
143 (*bitmaps)[frame] = cropped; 143 (*bitmaps)[frame] = cropped;
144 } 144 }
145 } 145 }
146 146
147 } // namespace ui 147 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cursor/cursor_util.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698