1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "ui/ozone/platform/drm/gpu/crtc_controller.h"
#include "ui/ozone/platform/drm/gpu/drm_buffer.h"
#include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
#include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
#include "ui/ozone/platform/drm/gpu/drm_surface.h"
#include "ui/ozone/platform/drm/gpu/drm_window.h"
#include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
#include "ui/ozone/platform/drm/gpu/screen_manager.h"
#include "ui/ozone/platform/drm/test/mock_drm_device.h"
namespace {
// Create a basic mode for a 6x4 screen.
const drmModeModeInfo kDefaultMode =
{0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
const gfx::AcceleratedWidget kDefaultWidgetHandle = 1;
const uint32_t kDefaultCrtc = 1;
const uint32_t kDefaultConnector = 2;
const size_t kPlanesPerCrtc = 1;
const uint32_t kDefaultCursorSize = 64;
} // namespace
class DrmSurfaceTest : public testing::Test {
public:
DrmSurfaceTest() {}
void SetUp() override;
void TearDown() override;
protected:
scoped_ptr<base::MessageLoop> message_loop_;
scoped_refptr<ui::MockDrmDevice> drm_;
scoped_ptr<ui::DrmBufferGenerator> buffer_generator_;
scoped_ptr<ui::ScreenManager> screen_manager_;
scoped_ptr<ui::DrmDeviceManager> drm_device_manager_;
scoped_ptr<ui::DrmSurface> surface_;
private:
DISALLOW_COPY_AND_ASSIGN(DrmSurfaceTest);
};
void DrmSurfaceTest::SetUp() {
message_loop_.reset(new base::MessageLoopForUI);
std::vector<uint32_t> crtcs;
crtcs.push_back(kDefaultCrtc);
drm_ = new ui::MockDrmDevice(true, crtcs, kPlanesPerCrtc);
buffer_generator_.reset(new ui::DrmBufferGenerator());
screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get()));
screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector);
screen_manager_->ConfigureDisplayController(
drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode);
drm_device_manager_.reset(new ui::DrmDeviceManager(nullptr));
scoped_ptr<ui::DrmWindow> window(new ui::DrmWindow(
kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get()));
window->Initialize();
window->OnBoundsChanged(
gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)));
screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass());
surface_.reset(
new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle)));
surface_->ResizeCanvas(
gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay));
}
void DrmSurfaceTest::TearDown() {
surface_.reset();
scoped_ptr<ui::DrmWindow> window =
screen_manager_->RemoveWindow(kDefaultWidgetHandle);
window->Shutdown();
drm_ = nullptr;
message_loop_.reset();
}
TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) {
surface_->PresentCanvas(gfx::Rect());
// Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset.
EXPECT_EQ(3u, drm_->current_framebuffer());
surface_->PresentCanvas(gfx::Rect());
EXPECT_EQ(2u, drm_->current_framebuffer());
}
TEST_F(DrmSurfaceTest, CheckSurfaceContents) {
SkPaint paint;
paint.setColor(SK_ColorWHITE);
SkRect rect =
SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
surface_->GetSurface()->getCanvas()->drawRect(rect, paint);
surface_->PresentCanvas(
gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
SkBitmap image;
std::vector<skia::RefPtr<SkSurface>> framebuffers;
for (const auto& buffer : drm_->buffers()) {
// Skip cursor buffers.
if (buffer->width() == kDefaultCursorSize &&
buffer->height() == kDefaultCursorSize)
continue;
framebuffers.push_back(buffer);
}
// Buffer 0 is the modesetting buffer, buffer 1 is the frontbuffer and buffer
// 2 is the backbuffer.
EXPECT_EQ(3u, framebuffers.size());
image.setInfo(framebuffers[2]->getCanvas()->imageInfo());
EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0));
EXPECT_EQ(kDefaultMode.hdisplay, image.width());
EXPECT_EQ(kDefaultMode.vdisplay, image.height());
// Make sure the updates are correctly propagated to the native surface.
for (int i = 0; i < image.height(); ++i) {
for (int j = 0; j < image.width(); ++j) {
if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
else
EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
}
}
}
|