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

Side by Side Diff: ui/ozone/platform/dri/dri_surface_unittest.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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/ozone/platform/dri/dri_surface_factory_unittest.cc ('k') | ui/ozone/platform/dri/dri_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "base/message_loop/message_loop.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "ui/ozone/platform/dri/crtc_controller.h"
11 #include "ui/ozone/platform/dri/dri_buffer.h"
12 #include "ui/ozone/platform/dri/dri_surface.h"
13 #include "ui/ozone/platform/dri/dri_window_delegate.h"
14 #include "ui/ozone/platform/dri/hardware_display_controller.h"
15 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h"
16
17 namespace {
18
19 // Create a basic mode for a 6x4 screen.
20 const drmModeModeInfo kDefaultMode =
21 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
22
23 const uint32_t kDefaultCrtc = 1;
24 const uint32_t kDefaultConnector = 2;
25
26 class MockDriWindowDelegate : public ui::DriWindowDelegate {
27 public:
28 MockDriWindowDelegate(ui::DriWrapper* drm) {
29 controller_.reset(new ui::HardwareDisplayController(make_scoped_ptr(
30 new ui::CrtcController(drm, kDefaultCrtc, kDefaultConnector))));
31 scoped_refptr<ui::DriBuffer> buffer(new ui::DriBuffer(drm));
32 SkImageInfo info = SkImageInfo::MakeN32Premul(kDefaultMode.hdisplay,
33 kDefaultMode.vdisplay);
34 EXPECT_TRUE(buffer->Initialize(info));
35 EXPECT_TRUE(controller_->Modeset(ui::OverlayPlane(buffer), kDefaultMode));
36 }
37 virtual ~MockDriWindowDelegate() {}
38
39 // DriWindowDelegate:
40 virtual void Initialize() override {}
41 virtual void Shutdown() override {}
42 virtual gfx::AcceleratedWidget GetAcceleratedWidget() override { return 1; }
43 virtual ui::HardwareDisplayController* GetController() override {
44 return controller_.get();
45 }
46 virtual void OnBoundsChanged(const gfx::Rect& bounds) override {}
47
48 private:
49 scoped_ptr<ui::HardwareDisplayController> controller_;
50
51 DISALLOW_COPY_AND_ASSIGN(MockDriWindowDelegate);
52 };
53
54 } // namespace
55
56 class DriSurfaceTest : public testing::Test {
57 public:
58 DriSurfaceTest() {}
59
60 virtual void SetUp() override;
61 virtual void TearDown() override;
62
63 protected:
64 scoped_ptr<base::MessageLoop> message_loop_;
65 scoped_ptr<ui::MockDriWrapper> drm_;
66 scoped_ptr<MockDriWindowDelegate> window_delegate_;
67 scoped_ptr<ui::DriSurface> surface_;
68
69 private:
70 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest);
71 };
72
73 void DriSurfaceTest::SetUp() {
74 message_loop_.reset(new base::MessageLoopForUI);
75 drm_.reset(new ui::MockDriWrapper(3));
76 window_delegate_.reset(new MockDriWindowDelegate(drm_.get()));
77 surface_.reset(new ui::DriSurface(window_delegate_.get(), drm_.get()));
78 surface_->ResizeCanvas(gfx::Size(kDefaultMode.hdisplay,
79 kDefaultMode.vdisplay));
80 }
81
82 void DriSurfaceTest::TearDown() {
83 surface_.reset();
84 window_delegate_.reset();
85 drm_.reset();
86 message_loop_.reset();
87 }
88
89 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) {
90 surface_->PresentCanvas(gfx::Rect());
91 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset.
92 EXPECT_EQ(3u, drm_->current_framebuffer());
93 surface_->PresentCanvas(gfx::Rect());
94 EXPECT_EQ(2u, drm_->current_framebuffer());
95 }
96
97 TEST_F(DriSurfaceTest, CheckSurfaceContents) {
98 SkPaint paint;
99 paint.setColor(SK_ColorWHITE);
100 SkRect rect = SkRect::MakeWH(kDefaultMode.hdisplay / 2,
101 kDefaultMode.vdisplay / 2);
102 surface_->GetCanvas()->drawRect(rect, paint);
103 surface_->PresentCanvas(
104 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
105
106 SkBitmap image;
107 // Buffer 0 is the buffer used in SetUp for modesetting and buffer 1 is the
108 // frontbuffer.
109 // Buffer 2 is the backbuffer we just painted in, so we want to make sure its
110 // contents are correct.
111 image.setInfo(drm_->buffers()[2]->getCanvas()->imageInfo());
112 EXPECT_TRUE(drm_->buffers()[2]->getCanvas()->readPixels(&image, 0, 0));
113
114 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
115 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
116
117 // Make sure the updates are correctly propagated to the native surface.
118 for (int i = 0; i < image.height(); ++i) {
119 for (int j = 0; j < image.width(); ++j) {
120 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
121 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
122 else
123 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
124 }
125 }
126 }
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_surface_factory_unittest.cc ('k') | ui/ozone/platform/dri/dri_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698