OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_loader_x11.h" | 5 #include "ui/base/cursor/cursor_loader_x11.h" |
6 | 6 |
7 #include <float.h> | 7 #include <float.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/cursorfont.h> | 9 #include <X11/cursorfont.h> |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 CursorLoaderX11::~CursorLoaderX11() { | 152 CursorLoaderX11::~CursorLoaderX11() { |
153 UnloadAll(); | 153 UnloadAll(); |
154 } | 154 } |
155 | 155 |
156 void CursorLoaderX11::LoadImageCursor(int id, | 156 void CursorLoaderX11::LoadImageCursor(int id, |
157 int resource_id, | 157 int resource_id, |
158 const gfx::Point& hot) { | 158 const gfx::Point& hot) { |
159 const gfx::ImageSkia* image = | 159 const gfx::ImageSkia* image = |
160 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 160 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
161 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( | 161 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( |
162 GetScaleFactorFromScale(display().device_scale_factor())); | 162 display().device_scale_factor()); |
163 SkBitmap bitmap = image_rep.sk_bitmap(); | 163 SkBitmap bitmap = image_rep.sk_bitmap(); |
164 gfx::Point hotpoint = hot; | 164 gfx::Point hotpoint = hot; |
165 ScaleAndRotateCursorBitmapAndHotpoint( | 165 ScaleAndRotateCursorBitmapAndHotpoint( |
166 scale(), display().rotation(), &bitmap, &hotpoint); | 166 scale(), display().rotation(), &bitmap, &hotpoint); |
167 | 167 |
168 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); | 168 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); |
169 cursors_[id] = CreateReffedCustomXCursor(x_image); | 169 cursors_[id] = CreateReffedCustomXCursor(x_image); |
170 // |image_rep| is owned by the resource bundle. So we do not need to free it. | 170 // |image_rep| is owned by the resource bundle. So we do not need to free it. |
171 } | 171 } |
172 | 172 |
173 void CursorLoaderX11::LoadAnimatedCursor(int id, | 173 void CursorLoaderX11::LoadAnimatedCursor(int id, |
174 int resource_id, | 174 int resource_id, |
175 const gfx::Point& hot, | 175 const gfx::Point& hot, |
176 int frame_delay_ms) { | 176 int frame_delay_ms) { |
177 const gfx::ImageSkia* image = | 177 const gfx::ImageSkia* image = |
178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
179 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( | 179 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( |
180 GetScaleFactorFromScale(display().device_scale_factor())); | 180 display().device_scale_factor()); |
181 SkBitmap bitmap = image_rep.sk_bitmap(); | 181 SkBitmap bitmap = image_rep.sk_bitmap(); |
182 int frame_width = bitmap.height(); | 182 int frame_width = bitmap.height(); |
183 int frame_height = frame_width; | 183 int frame_height = frame_width; |
184 int total_width = bitmap.width(); | 184 int total_width = bitmap.width(); |
185 DCHECK_EQ(total_width % frame_width, 0); | 185 DCHECK_EQ(total_width % frame_width, 0); |
186 int frame_count = total_width / frame_width; | 186 int frame_count = total_width / frame_width; |
187 DCHECK_GT(frame_count, 0); | 187 DCHECK_GT(frame_count, 0); |
188 XcursorImages* x_images = XcursorImagesCreate(frame_count); | 188 XcursorImages* x_images = XcursorImagesCreate(frame_count); |
189 x_images->nimage = frame_count; | 189 x_images->nimage = frame_count; |
190 | 190 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 297 |
298 *bitmap = skia::ImageOperations::Resize( | 298 *bitmap = skia::ImageOperations::Resize( |
299 *bitmap, | 299 *bitmap, |
300 skia::ImageOperations::RESIZE_BETTER, | 300 skia::ImageOperations::RESIZE_BETTER, |
301 scaled_size.width(), | 301 scaled_size.width(), |
302 scaled_size.height()); | 302 scaled_size.height()); |
303 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); | 303 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); |
304 } | 304 } |
305 | 305 |
306 } // namespace ui | 306 } // namespace ui |
OLD | NEW |