Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_surface_unittest.cc
blob1aaa4e36393c648a39e8291c6fe00800347b7855
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.
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/drm/gpu/crtc_controller.h"
11 #include "ui/ozone/platform/drm/gpu/drm_buffer.h"
12 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
13 #include "ui/ozone/platform/drm/gpu/drm_surface.h"
14 #include "ui/ozone/platform/drm/gpu/drm_window.h"
15 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
16 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
17 #include "ui/ozone/platform/drm/test/mock_drm_device.h"
19 namespace {
21 // Create a basic mode for a 6x4 screen.
22 const drmModeModeInfo kDefaultMode =
23 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
25 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1;
26 const uint32_t kDefaultCrtc = 1;
27 const uint32_t kDefaultConnector = 2;
28 const size_t kPlanesPerCrtc = 1;
29 const uint32_t kDefaultCursorSize = 64;
31 } // namespace
33 class DrmSurfaceTest : public testing::Test {
34 public:
35 DrmSurfaceTest() {}
37 void SetUp() override;
38 void TearDown() override;
40 protected:
41 scoped_ptr<base::MessageLoop> message_loop_;
42 scoped_refptr<ui::MockDrmDevice> drm_;
43 scoped_ptr<ui::DrmBufferGenerator> buffer_generator_;
44 scoped_ptr<ui::ScreenManager> screen_manager_;
45 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_;
46 scoped_ptr<ui::DrmSurface> surface_;
48 private:
49 DISALLOW_COPY_AND_ASSIGN(DrmSurfaceTest);
52 void DrmSurfaceTest::SetUp() {
53 message_loop_.reset(new base::MessageLoopForUI);
54 std::vector<uint32_t> crtcs;
55 crtcs.push_back(kDefaultCrtc);
56 drm_ = new ui::MockDrmDevice(true, crtcs, kPlanesPerCrtc);
57 buffer_generator_.reset(new ui::DrmBufferGenerator());
58 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get()));
59 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector);
60 screen_manager_->ConfigureDisplayController(
61 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode);
63 drm_device_manager_.reset(new ui::DrmDeviceManager(drm_));
64 scoped_ptr<ui::DrmWindow> window(new ui::DrmWindow(
65 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get()));
66 window->Initialize();
67 window->OnBoundsChanged(
68 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)));
69 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass());
71 surface_.reset(
72 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle)));
73 surface_->ResizeCanvas(
74 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay));
77 void DrmSurfaceTest::TearDown() {
78 surface_.reset();
79 scoped_ptr<ui::DrmWindow> window =
80 screen_manager_->RemoveWindow(kDefaultWidgetHandle);
81 window->Shutdown();
82 drm_ = nullptr;
83 message_loop_.reset();
86 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) {
87 surface_->PresentCanvas(gfx::Rect());
88 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset.
89 EXPECT_EQ(3u, drm_->current_framebuffer());
90 surface_->PresentCanvas(gfx::Rect());
91 EXPECT_EQ(2u, drm_->current_framebuffer());
94 TEST_F(DrmSurfaceTest, CheckSurfaceContents) {
95 SkPaint paint;
96 paint.setColor(SK_ColorWHITE);
97 SkRect rect =
98 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
99 surface_->GetSurface()->getCanvas()->drawRect(rect, paint);
100 surface_->PresentCanvas(
101 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
103 SkBitmap image;
104 std::vector<skia::RefPtr<SkSurface>> framebuffers;
105 for (const auto& buffer : drm_->buffers()) {
106 // Skip cursor buffers.
107 if (buffer->width() == kDefaultCursorSize &&
108 buffer->height() == kDefaultCursorSize)
109 continue;
111 framebuffers.push_back(buffer);
114 // Buffer 0 is the modesetting buffer, buffer 1 is the frontbuffer and buffer
115 // 2 is the backbuffer.
116 EXPECT_EQ(3u, framebuffers.size());
118 image.setInfo(framebuffers[2]->getCanvas()->imageInfo());
119 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0));
121 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
122 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
124 // Make sure the updates are correctly propagated to the native surface.
125 for (int i = 0; i < image.height(); ++i) {
126 for (int j = 0; j < image.width(); ++j) {
127 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
128 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
129 else
130 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));