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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 int frame_count = total_width / frame_width; | 225 int frame_count = total_width / frame_width; |
226 DCHECK_GT(frame_count, 0); | 226 DCHECK_GT(frame_count, 0); |
227 XcursorImages* x_images = XcursorImagesCreate(frame_count); | 227 XcursorImages* x_images = XcursorImagesCreate(frame_count); |
228 x_images->nimage = frame_count; | 228 x_images->nimage = frame_count; |
229 | 229 |
230 for (int frame = 0; frame < frame_count; ++frame) { | 230 for (int frame = 0; frame < frame_count; ++frame) { |
231 gfx::Point hotpoint = hot; | 231 gfx::Point hotpoint = hot; |
232 int x_offset = frame_width * frame; | 232 int x_offset = frame_width * frame; |
233 DCHECK_LE(x_offset + frame_width, total_width); | 233 DCHECK_LE(x_offset + frame_width, total_width); |
234 | 234 |
235 SkBitmap cropped; | 235 SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap( |
236 SkIRect rect = SkIRect::MakeXYWH(x_offset, 0, frame_width, frame_height); | 236 bitmap, x_offset, 0, frame_width, frame_height); |
237 bitmap.extractSubset(&cropped, rect); | |
238 DCHECK_EQ(frame_width, cropped.width()); | 237 DCHECK_EQ(frame_width, cropped.width()); |
239 DCHECK_EQ(frame_height, cropped.height()); | 238 DCHECK_EQ(frame_height, cropped.height()); |
240 | 239 |
241 if (scale() != 1.f) | 240 XcursorImage* x_image = SkBitmapToXcursorImage(&cropped, hotpoint); |
242 ScaleCursorImageAndHotpoint(scale(), &cropped, &hotpoint); | |
243 | 241 |
244 XcursorImage* x_image = SkBitmapToXcursorImage(&cropped, hotpoint); | |
245 x_image->delay = frame_delay_ms; | 242 x_image->delay = frame_delay_ms; |
246 x_images->images[frame] = x_image; | 243 x_images->images[frame] = x_image; |
247 } | 244 } |
248 | 245 |
249 animated_cursors_[id] = std::make_pair( | 246 animated_cursors_[id] = std::make_pair( |
250 XcursorImagesLoadCursor(GetXDisplay(), x_images), x_images); | 247 XcursorImagesLoadCursor(GetXDisplay(), x_images), x_images); |
251 // |bitmap| is owned by the resource bundle. So we do not need to free it. | 248 // |bitmap| is owned by the resource bundle. So we do not need to free it. |
252 } | 249 } |
253 | 250 |
254 void CursorLoaderX11::UnloadAll() { | 251 void CursorLoaderX11::UnloadAll() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (animated_cursors_.count(type)) | 292 if (animated_cursors_.count(type)) |
296 return animated_cursors_[type].first; | 293 return animated_cursors_[type].first; |
297 | 294 |
298 ImageCursorMap::iterator find = cursors_.find(type); | 295 ImageCursorMap::iterator find = cursors_.find(type); |
299 if (find != cursors_.end()) | 296 if (find != cursors_.end()) |
300 return cursors_[type]; | 297 return cursors_[type]; |
301 return GetXCursor(CursorShapeFromNative(native_cursor)); | 298 return GetXCursor(CursorShapeFromNative(native_cursor)); |
302 } | 299 } |
303 | 300 |
304 } // namespace ui | 301 } // namespace ui |
OLD | NEW |