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

Side by Side Diff: ui/snapshot/snapshot_aura_unittest.cc

Issue 1057873004: Pass a ui::PaintContext from ui::Layer to layer delegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layer-paintcontext: mac Created 5 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
« no previous file with comments | « ui/keyboard/keyboard_controller.cc ('k') | ui/views/bubble/tray_bubble_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/test/aura_test_helper.h" 10 #include "ui/aura/test/aura_test_helper.h"
11 #include "ui/aura/test/test_screen.h" 11 #include "ui/aura/test/test_screen.h"
12 #include "ui/aura/test/test_window_delegate.h" 12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h" 13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h" 15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/compositor/compositor.h" 16 #include "ui/compositor/compositor.h"
17 #include "ui/compositor/layer.h" 17 #include "ui/compositor/layer.h"
18 #include "ui/compositor/paint_context.h"
18 #include "ui/compositor/test/context_factories_for_test.h" 19 #include "ui/compositor/test/context_factories_for_test.h"
19 #include "ui/compositor/test/draw_waiter_for_test.h" 20 #include "ui/compositor/test/draw_waiter_for_test.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/size_conversions.h" 23 #include "ui/gfx/geometry/size_conversions.h"
23 #include "ui/gfx/gfx_paths.h" 24 #include "ui/gfx/gfx_paths.h"
24 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
26 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
27 #include "ui/wm/core/default_activation_client.h" 28 #include "ui/wm/core/default_activation_client.h"
28 29
29 namespace ui { 30 namespace ui {
30 namespace { 31 namespace {
31 32
32 SkColor GetExpectedColorForPoint(int x, int y) { 33 SkColor GetExpectedColorForPoint(int x, int y) {
33 return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0); 34 return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0);
34 } 35 }
35 36
36 // Paint simple rectangle on the specified aura window. 37 // Paint simple rectangle on the specified aura window.
37 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate { 38 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate {
38 public: 39 public:
39 explicit TestPaintingWindowDelegate(const gfx::Size& window_size) 40 explicit TestPaintingWindowDelegate(const gfx::Size& window_size)
40 : window_size_(window_size) { 41 : window_size_(window_size) {
41 } 42 }
42 43
43 ~TestPaintingWindowDelegate() override {} 44 ~TestPaintingWindowDelegate() override {}
44 45
45 void OnPaint(gfx::Canvas* canvas) override { 46 void OnPaint(const ui::PaintContext& context) override {
46 for (int y = 0; y < window_size_.height(); ++y) { 47 for (int y = 0; y < window_size_.height(); ++y) {
47 for (int x = 0; x < window_size_.width(); ++x) 48 for (int x = 0; x < window_size_.width(); ++x) {
48 canvas->FillRect(gfx::Rect(x, y, 1, 1), GetExpectedColorForPoint(x, y)); 49 context.canvas()->FillRect(gfx::Rect(x, y, 1, 1),
50 GetExpectedColorForPoint(x, y));
51 }
49 } 52 }
50 } 53 }
51 54
52 private: 55 private:
53 gfx::Size window_size_; 56 gfx::Size window_size_;
54 57
55 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate); 58 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate);
56 }; 59 };
57 60
58 size_t GetFailedPixelsCountWithScaleFactor(const gfx::Image& image, 61 size_t GetFailedPixelsCountWithScaleFactor(const gfx::Image& image,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 gfx::SizeF snapshot_size(test_bounds.size()); 287 gfx::SizeF snapshot_size(test_bounds.size());
285 snapshot_size.Scale(2.0f); 288 snapshot_size.Scale(2.0f);
286 289
287 gfx::Image snapshot = GrabSnapshotForTestWindow(); 290 gfx::Image snapshot = GrabSnapshotForTestWindow();
288 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 291 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
289 snapshot.Size().ToString()); 292 snapshot.Size().ToString());
290 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); 293 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
291 } 294 }
292 295
293 } // namespace ui 296 } // namespace ui
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_controller.cc ('k') | ui/views/bubble/tray_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698