[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/snapshot/snapshot.h" |
| 6 | |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 10 | #include "base/bind.h" |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 11 | #include "base/macros.h" |
Gabriel Charette | 078e366 | 2017-08-28 22:59:04 | [diff] [blame] | 12 | #include "base/run_loop.h" |
jonross | 1ec7d99 | 2018-08-31 03:55:54 | [diff] [blame] | 13 | #include "base/test/scoped_task_environment.h" |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 14 | #include "base/test/test_simple_task_runner.h" |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 15 | #include "base/win/windows_version.h" |
| 16 | #include "build/build_config.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 17 | #include "testing/gtest/include/gtest/gtest.h" |
fmalita | 577ac19 | 2017-01-10 15:33:03 | [diff] [blame] | 18 | #include "third_party/skia/include/core/SkPixelRef.h" |
[email protected] | 4cc33f40 | 2014-03-26 15:33:35 | [diff] [blame] | 19 | #include "ui/aura/test/aura_test_helper.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 20 | #include "ui/aura/test/test_screen.h" |
| 21 | #include "ui/aura/test/test_window_delegate.h" |
| 22 | #include "ui/aura/test/test_windows.h" |
| 23 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 24 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | fa69f2b6 | 2014-05-22 21:47:58 | [diff] [blame] | 25 | #include "ui/compositor/compositor.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 26 | #include "ui/compositor/layer.h" |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 27 | #include "ui/compositor/paint_recorder.h" |
[email protected] | b58081d | 2014-01-24 10:13:51 | [diff] [blame] | 28 | #include "ui/compositor/test/draw_waiter_for_test.h" |
Mohsen Izadi | b371018 | 2019-04-30 04:57:35 | [diff] [blame] | 29 | #include "ui/compositor/test/test_context_factories.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 30 | #include "ui/gfx/canvas.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 31 | #include "ui/gfx/geometry/rect.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 32 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 33 | #include "ui/gfx/image/image.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 34 | #include "ui/gfx/transform.h" |
| 35 | #include "ui/gl/gl_implementation.h" |
[email protected] | f3b1efd | 2014-04-30 04:48:20 | [diff] [blame] | 36 | #include "ui/wm/core/default_activation_client.h" |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 37 | |
| 38 | namespace ui { |
| 39 | namespace { |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 40 | |
| 41 | SkColor GetExpectedColorForPoint(int x, int y) { |
| 42 | return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0); |
| 43 | } |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 44 | |
| 45 | // Paint simple rectangle on the specified aura window. |
| 46 | class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate { |
| 47 | public: |
| 48 | explicit TestPaintingWindowDelegate(const gfx::Size& window_size) |
| 49 | : window_size_(window_size) { |
| 50 | } |
| 51 | |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 52 | ~TestPaintingWindowDelegate() override {} |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 53 | |
danakj | 85d970e | 2015-04-04 00:15:24 | [diff] [blame] | 54 | void OnPaint(const ui::PaintContext& context) override { |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 55 | ui::PaintRecorder recorder(context, window_size_); |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 56 | for (int y = 0; y < window_size_.height(); ++y) { |
danakj | 85d970e | 2015-04-04 00:15:24 | [diff] [blame] | 57 | for (int x = 0; x < window_size_.width(); ++x) { |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 58 | recorder.canvas()->FillRect(gfx::Rect(x, y, 1, 1), |
| 59 | GetExpectedColorForPoint(x, y)); |
danakj | 85d970e | 2015-04-04 00:15:24 | [diff] [blame] | 60 | } |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 61 | } |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | private: |
| 65 | gfx::Size window_size_; |
| 66 | |
| 67 | DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate); |
| 68 | }; |
| 69 | |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 70 | size_t GetFailedPixelsCountWithScaleFactor(const gfx::Image& image, |
| 71 | int scale_factor) { |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 72 | const SkBitmap* bitmap = image.ToSkBitmap(); |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 73 | uint32_t* bitmap_data = |
| 74 | reinterpret_cast<uint32_t*>(bitmap->pixelRef()->pixels()); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 75 | size_t result = 0; |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 76 | for (int y = 0; y < bitmap->height(); y += scale_factor) { |
| 77 | for (int x = 0; x < bitmap->width(); x += scale_factor) { |
| 78 | if (static_cast<SkColor>(bitmap_data[x + y * bitmap->width()]) != |
| 79 | GetExpectedColorForPoint(x / scale_factor, y / scale_factor)) { |
| 80 | ++result; |
| 81 | } |
| 82 | } |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 83 | } |
| 84 | return result; |
| 85 | } |
| 86 | |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 87 | size_t GetFailedPixelsCount(const gfx::Image& image) { |
| 88 | return GetFailedPixelsCountWithScaleFactor(image, 1); |
| 89 | } |
| 90 | |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 91 | } // namespace |
| 92 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 93 | class SnapshotAuraTest : public testing::Test { |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 94 | public: |
| 95 | SnapshotAuraTest() {} |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 96 | ~SnapshotAuraTest() override {} |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 97 | |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 98 | void SetUp() override { |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 99 | testing::Test::SetUp(); |
[email protected] | 380a8bdf | 2014-02-20 19:02:54 | [diff] [blame] | 100 | |
jonross | 1ec7d99 | 2018-08-31 03:55:54 | [diff] [blame] | 101 | scoped_task_environment_ = |
| 102 | std::make_unique<base::test::ScopedTaskEnvironment>( |
| 103 | base::test::ScopedTaskEnvironment::MainThreadType::UI); |
| 104 | |
[email protected] | 380a8bdf | 2014-02-20 19:02:54 | [diff] [blame] | 105 | // The ContextFactory must exist before any Compositors are created. |
| 106 | // Snapshot test tests real drawing and readback, so needs pixel output. |
Mohsen Izadi | b371018 | 2019-04-30 04:57:35 | [diff] [blame] | 107 | const bool enable_pixel_output = true; |
| 108 | context_factories_ = |
| 109 | std::make_unique<ui::TestContextFactories>(enable_pixel_output); |
fsamuel | a0bcfe1 | 2016-12-14 06:21:49 | [diff] [blame] | 110 | |
Mohsen Izadi | b371018 | 2019-04-30 04:57:35 | [diff] [blame] | 111 | helper_ = std::make_unique<aura::test::AuraTestHelper>(); |
| 112 | helper_->SetUp(context_factories_->GetContextFactory(), |
| 113 | context_factories_->GetContextFactoryPrivate()); |
[email protected] | f3b1efd | 2014-04-30 04:48:20 | [diff] [blame] | 114 | new ::wm::DefaultActivationClient(helper_->root_window()); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 115 | } |
| 116 | |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 117 | void TearDown() override { |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 118 | test_window_.reset(); |
| 119 | delegate_.reset(); |
| 120 | helper_->RunAllPendingInMessageLoop(); |
| 121 | helper_->TearDown(); |
Mohsen Izadi | b371018 | 2019-04-30 04:57:35 | [diff] [blame] | 122 | context_factories_.reset(); |
jonross | 1ec7d99 | 2018-08-31 03:55:54 | [diff] [blame] | 123 | scoped_task_environment_.reset(); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 124 | testing::Test::TearDown(); |
| 125 | } |
| 126 | |
| 127 | protected: |
| 128 | aura::Window* test_window() { return test_window_.get(); } |
[email protected] | 688c225e | 2013-11-10 06:16:08 | [diff] [blame] | 129 | aura::Window* root_window() { return helper_->root_window(); } |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 130 | aura::TestScreen* test_screen() { return helper_->test_screen(); } |
| 131 | |
| 132 | void WaitForDraw() { |
[email protected] | a0695522 | 2014-03-10 22:47:32 | [diff] [blame] | 133 | helper_->host()->compositor()->ScheduleDraw(); |
staraz | b14cc10cc | 2017-04-13 18:06:39 | [diff] [blame] | 134 | ui::DrawWaiterForTest::WaitForCompositingEnded( |
weiliangc | 5efa0a1 | 2015-01-29 19:56:46 | [diff] [blame] | 135 | helper_->host()->compositor()); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void SetupTestWindow(const gfx::Rect& window_bounds) { |
| 139 | delegate_.reset(new TestPaintingWindowDelegate(window_bounds.size())); |
| 140 | test_window_.reset(aura::test::CreateTestWindowWithDelegate( |
| 141 | delegate_.get(), 0, window_bounds, root_window())); |
| 142 | } |
| 143 | |
| 144 | gfx::Image GrabSnapshotForTestWindow() { |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 145 | gfx::Rect source_rect(test_window_->bounds().size()); |
[email protected] | f51a712 | 2014-06-12 10:06:51 | [diff] [blame] | 146 | aura::Window::ConvertRectToTarget( |
| 147 | test_window(), root_window(), &source_rect); |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 148 | |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 149 | scoped_refptr<SnapshotHolder> holder(new SnapshotHolder); |
| 150 | ui::GrabWindowSnapshotAsync( |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 151 | root_window(), source_rect, |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 152 | base::Bind(&SnapshotHolder::SnapshotCallback, holder)); |
| 153 | |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 154 | holder->WaitForSnapshot(); |
| 155 | DCHECK(holder->completed()); |
| 156 | return holder->image(); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private: |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 160 | class SnapshotHolder : public base::RefCountedThreadSafe<SnapshotHolder> { |
| 161 | public: |
| 162 | SnapshotHolder() : completed_(false) {} |
| 163 | |
Xiaohui Chen | 5913da3 | 2017-11-16 18:10:09 | [diff] [blame] | 164 | void SnapshotCallback(gfx::Image image) { |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 165 | DCHECK(!completed_); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 166 | image_ = image; |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 167 | completed_ = true; |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 168 | run_loop_.Quit(); |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 169 | } |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 170 | void WaitForSnapshot() { run_loop_.Run(); } |
Xiaohui Chen | 5913da3 | 2017-11-16 18:10:09 | [diff] [blame] | 171 | bool completed() const { return completed_; } |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 172 | const gfx::Image& image() const { return image_; } |
| 173 | |
| 174 | private: |
| 175 | friend class base::RefCountedThreadSafe<SnapshotHolder>; |
| 176 | |
| 177 | virtual ~SnapshotHolder() {} |
| 178 | |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 179 | base::RunLoop run_loop_; |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 180 | gfx::Image image_; |
| 181 | bool completed_; |
| 182 | }; |
| 183 | |
jonross | 1ec7d99 | 2018-08-31 03:55:54 | [diff] [blame] | 184 | std::unique_ptr<base::test::ScopedTaskEnvironment> scoped_task_environment_; |
Mohsen Izadi | b371018 | 2019-04-30 04:57:35 | [diff] [blame] | 185 | std::unique_ptr<ui::TestContextFactories> context_factories_; |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 186 | std::unique_ptr<aura::test::AuraTestHelper> helper_; |
| 187 | std::unique_ptr<aura::Window> test_window_; |
| 188 | std::unique_ptr<TestPaintingWindowDelegate> delegate_; |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 189 | std::vector<unsigned char> png_representation_; |
| 190 | |
| 191 | DISALLOW_COPY_AND_ASSIGN(SnapshotAuraTest); |
| 192 | }; |
| 193 | |
Nico Weber | e29a31ae | 2018-06-13 23:00:36 | [diff] [blame] | 194 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 195 | // https://crbug.com/852512 |
| 196 | #define MAYBE_FullScreenWindow DISABLED_FullScreenWindow |
| 197 | #else |
| 198 | #define MAYBE_FullScreenWindow FullScreenWindow |
| 199 | #endif |
| 200 | TEST_F(SnapshotAuraTest, MAYBE_FullScreenWindow) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 201 | #if defined(OS_WIN) |
| 202 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 203 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 204 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 205 | return; |
| 206 | #endif |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 207 | SetupTestWindow(root_window()->bounds()); |
| 208 | WaitForDraw(); |
| 209 | |
| 210 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 211 | EXPECT_EQ(test_window()->bounds().size().ToString(), |
| 212 | snapshot.Size().ToString()); |
| 213 | EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); |
| 214 | } |
| 215 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 216 | TEST_F(SnapshotAuraTest, PartialBounds) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 217 | #if defined(OS_WIN) |
| 218 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 219 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 220 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 221 | return; |
| 222 | #endif |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 223 | gfx::Rect test_bounds(100, 100, 300, 200); |
| 224 | SetupTestWindow(test_bounds); |
| 225 | WaitForDraw(); |
| 226 | |
| 227 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 228 | EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString()); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 229 | EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); |
| 230 | } |
| 231 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 232 | TEST_F(SnapshotAuraTest, Rotated) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 233 | #if defined(OS_WIN) |
| 234 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 235 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 236 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 237 | return; |
| 238 | #endif |
oshima | 5245e49 | 2016-04-26 16:47:55 | [diff] [blame] | 239 | test_screen()->SetDisplayRotation(display::Display::ROTATE_90); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 240 | |
| 241 | gfx::Rect test_bounds(100, 100, 300, 200); |
| 242 | SetupTestWindow(test_bounds); |
| 243 | WaitForDraw(); |
| 244 | |
| 245 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 246 | EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString()); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 247 | EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); |
| 248 | } |
| 249 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 250 | TEST_F(SnapshotAuraTest, UIScale) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 251 | #if defined(OS_WIN) |
| 252 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 253 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 254 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 255 | return; |
| 256 | #endif |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 257 | const float kUIScale = 0.5f; |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 258 | test_screen()->SetUIScale(kUIScale); |
| 259 | |
| 260 | gfx::Rect test_bounds(100, 100, 300, 200); |
| 261 | SetupTestWindow(test_bounds); |
| 262 | WaitForDraw(); |
| 263 | |
| 264 | // Snapshot always captures the physical pixels. |
| 265 | gfx::SizeF snapshot_size(test_bounds.size()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 266 | snapshot_size.Scale(1 / kUIScale); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 267 | |
| 268 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 269 | EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), |
| 270 | snapshot.Size().ToString()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 271 | EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 1 / kUIScale)); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 272 | } |
| 273 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 274 | TEST_F(SnapshotAuraTest, DeviceScaleFactor) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 275 | #if defined(OS_WIN) |
| 276 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 277 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 278 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 279 | return; |
| 280 | #endif |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 281 | test_screen()->SetDeviceScaleFactor(2.0f); |
| 282 | |
| 283 | gfx::Rect test_bounds(100, 100, 150, 100); |
| 284 | SetupTestWindow(test_bounds); |
| 285 | WaitForDraw(); |
| 286 | |
| 287 | // Snapshot always captures the physical pixels. |
| 288 | gfx::SizeF snapshot_size(test_bounds.size()); |
| 289 | snapshot_size.Scale(2.0f); |
| 290 | |
| 291 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 292 | EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), |
| 293 | snapshot.Size().ToString()); |
[email protected] | 7cfd3d2 | 2014-01-24 07:26:15 | [diff] [blame] | 294 | EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 297 | TEST_F(SnapshotAuraTest, RotateAndUIScale) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 298 | #if defined(OS_WIN) |
| 299 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 300 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 301 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 302 | return; |
| 303 | #endif |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 304 | const float kUIScale = 0.5f; |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 305 | test_screen()->SetUIScale(kUIScale); |
oshima | 5245e49 | 2016-04-26 16:47:55 | [diff] [blame] | 306 | test_screen()->SetDisplayRotation(display::Display::ROTATE_90); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 307 | |
| 308 | gfx::Rect test_bounds(100, 100, 300, 200); |
| 309 | SetupTestWindow(test_bounds); |
| 310 | WaitForDraw(); |
| 311 | |
| 312 | // Snapshot always captures the physical pixels. |
| 313 | gfx::SizeF snapshot_size(test_bounds.size()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 314 | snapshot_size.Scale(1 / kUIScale); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 315 | |
| 316 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 317 | EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), |
| 318 | snapshot.Size().ToString()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 319 | EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 1 / kUIScale)); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 320 | } |
| 321 | |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 322 | TEST_F(SnapshotAuraTest, RotateAndUIScaleAndScaleFactor) { |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 323 | #if defined(OS_WIN) |
| 324 | // TODO(https://crbug.com/850556): Make work on Win10. |
| 325 | base::win::Version version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 326 | if (version >= base::win::Version::WIN10) |
Nico Weber | a79a119 | 2018-06-13 14:13:28 | [diff] [blame] | 327 | return; |
| 328 | #endif |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 329 | test_screen()->SetDeviceScaleFactor(2.0f); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 330 | const float kUIScale = 0.5f; |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 331 | test_screen()->SetUIScale(kUIScale); |
oshima | 5245e49 | 2016-04-26 16:47:55 | [diff] [blame] | 332 | test_screen()->SetDisplayRotation(display::Display::ROTATE_90); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 333 | |
| 334 | gfx::Rect test_bounds(20, 30, 150, 100); |
| 335 | SetupTestWindow(test_bounds); |
| 336 | WaitForDraw(); |
| 337 | |
| 338 | // Snapshot always captures the physical pixels. |
| 339 | gfx::SizeF snapshot_size(test_bounds.size()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 340 | snapshot_size.Scale(2.0f / kUIScale); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 341 | |
| 342 | gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 343 | EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), |
| 344 | snapshot.Size().ToString()); |
eseckler | 7233c1a7 | 2017-01-25 15:07:54 | [diff] [blame] | 345 | EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2 / kUIScale)); |
[email protected] | f9580547 | 2013-05-25 04:31:19 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | } // namespace ui |