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

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

Issue 1064133003: ui: Use a PaintRecorder to access the Canvas for painting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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/paint_recorder.h"
19 #include "ui/compositor/test/context_factories_for_test.h" 19 #include "ui/compositor/test/context_factories_for_test.h"
20 #include "ui/compositor/test/draw_waiter_for_test.h" 20 #include "ui/compositor/test/draw_waiter_for_test.h"
21 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/geometry/size_conversions.h" 23 #include "ui/gfx/geometry/size_conversions.h"
24 #include "ui/gfx/gfx_paths.h" 24 #include "ui/gfx/gfx_paths.h"
25 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
27 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
28 #include "ui/wm/core/default_activation_client.h" 28 #include "ui/wm/core/default_activation_client.h"
29 29
30 namespace ui { 30 namespace ui {
31 namespace { 31 namespace {
32 32
33 SkColor GetExpectedColorForPoint(int x, int y) { 33 SkColor GetExpectedColorForPoint(int x, int y) {
34 return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0); 34 return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0);
35 } 35 }
36 36
37 // Paint simple rectangle on the specified aura window. 37 // Paint simple rectangle on the specified aura window.
38 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate { 38 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate {
39 public: 39 public:
40 explicit TestPaintingWindowDelegate(const gfx::Size& window_size) 40 explicit TestPaintingWindowDelegate(const gfx::Size& window_size)
41 : window_size_(window_size) { 41 : window_size_(window_size) {
42 } 42 }
43 43
44 ~TestPaintingWindowDelegate() override {} 44 ~TestPaintingWindowDelegate() override {}
45 45
46 void OnPaint(const ui::PaintContext& context) override { 46 void OnPaint(const ui::PaintContext& context) override {
47 ui::PaintRecorder recorder(context);
47 for (int y = 0; y < window_size_.height(); ++y) { 48 for (int y = 0; y < window_size_.height(); ++y) {
48 for (int x = 0; x < window_size_.width(); ++x) { 49 for (int x = 0; x < window_size_.width(); ++x) {
49 context.canvas()->FillRect(gfx::Rect(x, y, 1, 1), 50 recorder.canvas()->FillRect(gfx::Rect(x, y, 1, 1),
50 GetExpectedColorForPoint(x, y)); 51 GetExpectedColorForPoint(x, y));
51 } 52 }
52 } 53 }
53 } 54 }
54 55
55 private: 56 private:
56 gfx::Size window_size_; 57 gfx::Size window_size_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate); 59 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate);
59 }; 60 };
60 61
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 gfx::SizeF snapshot_size(test_bounds.size()); 288 gfx::SizeF snapshot_size(test_bounds.size());
288 snapshot_size.Scale(2.0f); 289 snapshot_size.Scale(2.0f);
289 290
290 gfx::Image snapshot = GrabSnapshotForTestWindow(); 291 gfx::Image snapshot = GrabSnapshotForTestWindow();
291 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 292 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
292 snapshot.Size().ToString()); 293 snapshot.Size().ToString());
293 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); 294 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
294 } 295 }
295 296
296 } // namespace ui 297 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698