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

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

Issue 249303002: Revert of Use platform's device scale factor for cursor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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
152 152
153 CursorLoaderX11::~CursorLoaderX11() { 153 CursorLoaderX11::~CursorLoaderX11() {
154 UnloadAll(); 154 UnloadAll();
155 } 155 }
156 156
157 void CursorLoaderX11::LoadImageCursor(int id, 157 void CursorLoaderX11::LoadImageCursor(int id,
158 int resource_id, 158 int resource_id,
159 const gfx::Point& hot) { 159 const gfx::Point& hot) {
160 const gfx::ImageSkia* image = 160 const gfx::ImageSkia* image =
161 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 161 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
162 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); 162 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
163 display().device_scale_factor());
163 SkBitmap bitmap = image_rep.sk_bitmap(); 164 SkBitmap bitmap = image_rep.sk_bitmap();
164 gfx::Point hotpoint = hot; 165 gfx::Point hotpoint = hot;
165 ScaleAndRotateCursorBitmapAndHotpoint( 166 ScaleAndRotateCursorBitmapAndHotpoint(
166 scale(), rotation(), &bitmap, &hotpoint); 167 scale(), display().rotation(), &bitmap, &hotpoint);
167 168
168 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); 169 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint);
169 cursors_[id] = CreateReffedCustomXCursor(x_image); 170 cursors_[id] = CreateReffedCustomXCursor(x_image);
170 // |image_rep| is owned by the resource bundle. So we do not need to free it. 171 // |image_rep| is owned by the resource bundle. So we do not need to free it.
171 } 172 }
172 173
173 void CursorLoaderX11::LoadAnimatedCursor(int id, 174 void CursorLoaderX11::LoadAnimatedCursor(int id,
174 int resource_id, 175 int resource_id,
175 const gfx::Point& hot, 176 const gfx::Point& hot,
176 int frame_delay_ms) { 177 int frame_delay_ms) {
177 const gfx::ImageSkia* image = 178 const gfx::ImageSkia* image =
178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 179 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
179 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); 180 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
181 display().device_scale_factor());
180 SkBitmap bitmap = image_rep.sk_bitmap(); 182 SkBitmap bitmap = image_rep.sk_bitmap();
181 int frame_width = bitmap.height(); 183 int frame_width = bitmap.height();
182 int frame_height = frame_width; 184 int frame_height = frame_width;
183 int total_width = bitmap.width(); 185 int total_width = bitmap.width();
184 DCHECK_EQ(total_width % frame_width, 0); 186 DCHECK_EQ(total_width % frame_width, 0);
185 int frame_count = total_width / frame_width; 187 int frame_count = total_width / frame_width;
186 DCHECK_GT(frame_count, 0); 188 DCHECK_GT(frame_count, 0);
187 XcursorImages* x_images = XcursorImagesCreate(frame_count); 189 XcursorImages* x_images = XcursorImagesCreate(frame_count);
188 x_images->nimage = frame_count; 190 x_images->nimage = frame_count;
189 191
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { 226 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) {
225 DCHECK(cursor); 227 DCHECK(cursor);
226 228
227 ::Cursor xcursor; 229 ::Cursor xcursor;
228 if (IsImageCursor(*cursor)) 230 if (IsImageCursor(*cursor))
229 xcursor = ImageCursorFromNative(*cursor); 231 xcursor = ImageCursorFromNative(*cursor);
230 else if (*cursor == kCursorNone) 232 else if (*cursor == kCursorNone)
231 xcursor = invisible_cursor_.get(); 233 xcursor = invisible_cursor_.get();
232 else if (*cursor == kCursorCustom) 234 else if (*cursor == kCursorCustom)
233 xcursor = cursor->platform(); 235 xcursor = cursor->platform();
234 else if (scale() == 1.0f && rotation() == gfx::Display::ROTATE_0) { 236 else if (display().device_scale_factor() == 1.0f &&
237 display().rotation() == gfx::Display::ROTATE_0) {
235 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); 238 xcursor = GetXCursor(CursorShapeFromNative(*cursor));
236 } else { 239 } else {
237 xcursor = ImageCursorFromNative(kCursorPointer); 240 xcursor = ImageCursorFromNative(kCursorPointer);
238 } 241 }
239 242
240 cursor->SetPlatformCursor(xcursor); 243 cursor->SetPlatformCursor(xcursor);
241 } 244 }
242 245
243 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { 246 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) {
244 int type = native_cursor.native_type(); 247 int type = native_cursor.native_type();
245 return cursors_.count(type) || animated_cursors_.count(type); 248 return cursors_.count(type) || animated_cursors_.count(type);
246 } 249 }
247 250
248 ::Cursor CursorLoaderX11::ImageCursorFromNative( 251 ::Cursor CursorLoaderX11::ImageCursorFromNative(
249 gfx::NativeCursor native_cursor) { 252 gfx::NativeCursor native_cursor) {
250 int type = native_cursor.native_type(); 253 int type = native_cursor.native_type();
251 if (animated_cursors_.count(type)) 254 if (animated_cursors_.count(type))
252 return animated_cursors_[type].first; 255 return animated_cursors_[type].first;
253 256
254 ImageCursorMap::iterator find = cursors_.find(type); 257 ImageCursorMap::iterator find = cursors_.find(type);
255 if (find != cursors_.end()) 258 if (find != cursors_.end())
256 return cursors_[type]; 259 return cursors_[type];
257 return GetXCursor(CursorShapeFromNative(native_cursor)); 260 return GetXCursor(CursorShapeFromNative(native_cursor));
258 } 261 }
259 262
260 } // namespace ui 263 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cursor/cursor_loader_ozone.cc ('k') | ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698