Commit 5b9b2db5 authored by oshima@chromium.org's avatar oshima@chromium.org

Do not scale cursor image for 2x image

It's regressed in  https://codereview.chromium.org/226293005.

BUG=368365
TEST=CursorLoaderX11Test.Scale, also tested manually
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/280133002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270028 0039d316-1c4b-4281-b951-d872f2087c98
parent 414dd168
......@@ -22,6 +22,11 @@
#include "ui/base/cursor/cursor_loader_win.h"
#endif
#if defined(USE_X11)
#include "grit/ui_resources.h"
#include "ui/base/cursor/cursor_loader_x11.h"
#endif
namespace ash {
namespace test {
......@@ -175,5 +180,28 @@ TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) {
EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
}
#if defined(USE_X11)
// This test is in ash_unittests becuase ui_unittests does not include
// 2x assets. crbug.com/372541.
TEST_F(AshNativeCursorManagerTest, CursorLoaderX11Test) {
const int kCursorId = 1;
ui::CursorLoaderX11 loader;
loader.set_scale(1.0f);
loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
const XcursorImage* image = loader.GetXcursorImageForTest(kCursorId);
int height = image->height;
int width = image->width;
loader.UnloadAll();
// Load 2x cursor and make sure its size is 2x of the 1x cusor.
loader.set_scale(2.0f);
loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
image = loader.GetXcursorImageForTest(kCursorId);
EXPECT_EQ(height * 2, static_cast<int>(image->height));
EXPECT_EQ(width * 2, static_cast<int>(image->width));
}
#endif
} // namespace test
} // namespace ash
......@@ -94,7 +94,7 @@ void AuraTestHelper::TearDown() {
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
#if defined(USE_X11)
ui::ResetXCursorCache();
ui::test::ResetXCursorCache();
#endif
ui::ShutdownInputMethodForTesting();
......
......@@ -162,8 +162,10 @@ void CursorLoaderX11::LoadImageCursor(int id,
const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale());
SkBitmap bitmap = image_rep.sk_bitmap();
gfx::Point hotpoint = hot;
// TODO(oshima): The cursor should use resource scale factor when
// fractional scale factor is enabled. crbug.com/372212
ScaleAndRotateCursorBitmapAndHotpoint(
scale(), rotation(), &bitmap, &hotpoint);
scale() / image_rep.scale(), rotation(), &bitmap, &hotpoint);
XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint);
cursors_[id] = CreateReffedCustomXCursor(x_image);
......@@ -174,6 +176,7 @@ void CursorLoaderX11::LoadAnimatedCursor(int id,
int resource_id,
const gfx::Point& hot,
int frame_delay_ms) {
// TODO(oshima|tdanderson): Support rotation and fractional scale factor.
const gfx::ImageSkia* image =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale());
......@@ -240,6 +243,10 @@ void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) {
cursor->SetPlatformCursor(xcursor);
}
const XcursorImage* CursorLoaderX11::GetXcursorImageForTest(int id) {
return test::GetCachedXcursorImage(cursors_[id]);
}
bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) {
int type = native_cursor.native_type();
return cursors_.count(type) || animated_cursors_.count(type);
......
......@@ -33,6 +33,8 @@ class UI_BASE_EXPORT CursorLoaderX11 : public CursorLoader {
virtual void UnloadAll() OVERRIDE;
virtual void SetPlatformCursor(gfx::NativeCursor* cursor) OVERRIDE;
const XcursorImage* GetXcursorImageForTest(int id);
private:
// Returns true if we have an image resource loaded for the |native_cursor|.
bool IsImageCursor(gfx::NativeCursor native_cursor);
......
......@@ -167,6 +167,10 @@ class XCustomCursorCache {
cache_.clear();
}
const XcursorImage* GetXcursorImage(::Cursor cursor) const {
return cache_.find(cursor)->second->image();
}
private:
friend struct DefaultSingletonTraits<XCustomCursorCache>;
......@@ -199,6 +203,10 @@ class XCustomCursorCache {
return false;
}
const XcursorImage* image() const {
return image_;
};
private:
XcursorImage* image_;
int ref_;
......@@ -315,11 +323,6 @@ bool QueryRenderSupport(Display* dpy) {
return cursor_cache->GetCursor(cursor_shape);
}
void ResetXCursorCache() {
delete cursor_cache;
cursor_cache = NULL;
}
::Cursor CreateReffedCustomXCursor(XcursorImage* image) {
return XCustomCursorCache::GetInstance()->InstallCustomCursor(image);
}
......@@ -1271,6 +1274,18 @@ void XScopedCursor::reset(::Cursor cursor) {
cursor_ = cursor;
}
namespace test {
void ResetXCursorCache() {
delete cursor_cache;
cursor_cache = NULL;
}
const XcursorImage* GetCachedXcursorImage(::Cursor cursor) {
return XCustomCursorCache::GetInstance()->GetXcursorImage(cursor);
}
}
// ----------------------------------------------------------------------------
// These functions are declared in x11_util_internal.h because they require
// XLib.h to be included, and it conflicts with many other headers.
......
......@@ -65,10 +65,6 @@ UI_BASE_EXPORT bool QueryRenderSupport(XDisplay* dpy);
// |cursor_shape| is an X font cursor shape, see XCreateFontCursor().
UI_BASE_EXPORT ::Cursor GetXCursor(int cursor_shape);
// Resets the cache used by GetXCursor(). Only useful for tests that may delete
// the display.
UI_BASE_EXPORT void ResetXCursorCache();
// Creates a custom X cursor from the image. This takes ownership of image. The
// caller must not free/modify the image. The refcount of the newly created
// cursor is set to 1.
......@@ -339,6 +335,16 @@ class UI_BASE_EXPORT XScopedCursor {
DISALLOW_COPY_AND_ASSIGN(XScopedCursor);
};
namespace test {
// Resets the cache used by GetXCursor(). Only useful for tests that may delete
// the display.
UI_BASE_EXPORT void ResetXCursorCache();
// Returns the cached XcursorImage for |cursor|.
UI_BASE_EXPORT const XcursorImage* GetCachedXcursorImage(::Cursor cursor);
} // namespace test
} // namespace ui
#endif // UI_BASE_X_X11_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment