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

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_surface_unittest.cc

Issue 1334483002: Force buffer re-allocation when the backing display changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment Created 5 years, 3 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/drm/gpu/drm_surface.cc ('k') | ui/ozone/platform/drm/gpu/drm_window.h » ('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 2014 The Chromium Authors. All rights reserved. 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 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/skia/include/core/SkCanvas.h" 7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/core/SkDevice.h" 9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "ui/ozone/platform/drm/gpu/crtc_controller.h" 10 #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get())); 66 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get()));
67 window->Initialize(); 67 window->Initialize();
68 window->OnBoundsChanged( 68 window->OnBoundsChanged(
69 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); 69 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)));
70 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass()); 70 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass());
71 71
72 surface_.reset( 72 surface_.reset(
73 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle))); 73 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle)));
74 surface_->ResizeCanvas( 74 surface_->ResizeCanvas(
75 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)); 75 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay));
76
77 // The window has been remapped to a controller. The first swap will cause the
78 // SWAP_NAK_RECREATE_BUFFERS without actually using the buffers.
79 surface_->PresentCanvas(gfx::Rect());
76 } 80 }
77 81
78 void DrmSurfaceTest::TearDown() { 82 void DrmSurfaceTest::TearDown() {
79 surface_.reset(); 83 surface_.reset();
80 scoped_ptr<ui::DrmWindow> window = 84 scoped_ptr<ui::DrmWindow> window =
81 screen_manager_->RemoveWindow(kDefaultWidgetHandle); 85 screen_manager_->RemoveWindow(kDefaultWidgetHandle);
82 window->Shutdown(); 86 window->Shutdown();
83 drm_ = nullptr; 87 drm_ = nullptr;
84 message_loop_.reset(); 88 message_loop_.reset();
85 } 89 }
86 90
87 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) { 91 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) {
88 surface_->PresentCanvas(gfx::Rect()); 92 surface_->PresentCanvas(gfx::Rect());
89 drm_->RunCallbacks(); 93 drm_->RunCallbacks();
90 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset. 94 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset.
91 EXPECT_EQ(3u, drm_->current_framebuffer()); 95 EXPECT_EQ(2u, drm_->current_framebuffer());
92 surface_->PresentCanvas(gfx::Rect()); 96 surface_->PresentCanvas(gfx::Rect());
93 drm_->RunCallbacks(); 97 drm_->RunCallbacks();
94 EXPECT_EQ(2u, drm_->current_framebuffer()); 98 EXPECT_EQ(3u, drm_->current_framebuffer());
95 } 99 }
96 100
97 TEST_F(DrmSurfaceTest, CheckSurfaceContents) { 101 TEST_F(DrmSurfaceTest, CheckSurfaceContents) {
98 SkPaint paint; 102 SkPaint paint;
99 paint.setColor(SK_ColorWHITE); 103 paint.setColor(SK_ColorWHITE);
100 SkRect rect = 104 SkRect rect =
101 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2); 105 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
102 surface_->GetSurface()->getCanvas()->drawRect(rect, paint); 106 surface_->GetSurface()->getCanvas()->drawRect(rect, paint);
103 surface_->PresentCanvas( 107 surface_->PresentCanvas(
104 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); 108 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
105 drm_->RunCallbacks(); 109 drm_->RunCallbacks();
106 110
107 SkBitmap image; 111 SkBitmap image;
108 std::vector<skia::RefPtr<SkSurface>> framebuffers; 112 std::vector<skia::RefPtr<SkSurface>> framebuffers;
109 for (const auto& buffer : drm_->buffers()) { 113 for (const auto& buffer : drm_->buffers()) {
110 // Skip cursor buffers. 114 // Skip cursor buffers.
111 if (buffer->width() == kDefaultCursorSize && 115 if (buffer->width() == kDefaultCursorSize &&
112 buffer->height() == kDefaultCursorSize) 116 buffer->height() == kDefaultCursorSize)
113 continue; 117 continue;
114 118
115 framebuffers.push_back(buffer); 119 framebuffers.push_back(buffer);
116 } 120 }
117 121
118 // Buffer 0 is the modesetting buffer, buffer 1 is the frontbuffer and buffer 122 // Buffer 0 is the modesetting buffer, buffer 2 is the frontbuffer and buffer
119 // 2 is the backbuffer. 123 // 1 is the backbuffer.
120 EXPECT_EQ(3u, framebuffers.size()); 124 EXPECT_EQ(3u, framebuffers.size());
121 125
122 image.setInfo(framebuffers[2]->getCanvas()->imageInfo()); 126 image.setInfo(framebuffers[1]->getCanvas()->imageInfo());
123 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0)); 127 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0));
124 128
125 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); 129 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
126 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); 130 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
127 131
128 // Make sure the updates are correctly propagated to the native surface. 132 // Make sure the updates are correctly propagated to the native surface.
129 for (int i = 0; i < image.height(); ++i) { 133 for (int i = 0; i < image.height(); ++i) {
130 for (int j = 0; j < image.width(); ++j) { 134 for (int j = 0; j < image.width(); ++j) {
131 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) 135 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
132 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); 136 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
133 else 137 else
(...skipping 26 matching lines...) Expand all
160 std::vector<skia::RefPtr<SkSurface>> framebuffers; 164 std::vector<skia::RefPtr<SkSurface>> framebuffers;
161 for (const auto& buffer : drm_->buffers()) { 165 for (const auto& buffer : drm_->buffers()) {
162 // Skip cursor buffers. 166 // Skip cursor buffers.
163 if (buffer->width() == kDefaultCursorSize && 167 if (buffer->width() == kDefaultCursorSize &&
164 buffer->height() == kDefaultCursorSize) 168 buffer->height() == kDefaultCursorSize)
165 continue; 169 continue;
166 170
167 framebuffers.push_back(buffer); 171 framebuffers.push_back(buffer);
168 } 172 }
169 173
170 // Buffer 0 is the modesetting buffer, buffer 1 is the backbuffer and buffer 174 // Buffer 0 is the modesetting buffer, buffer 2 is the backbuffer and buffer
171 // 2 is the frontbuffer. 175 // 1 is the frontbuffer.
172 EXPECT_EQ(3u, framebuffers.size()); 176 EXPECT_EQ(3u, framebuffers.size());
173 177
174 image.setInfo(framebuffers[1]->getCanvas()->imageInfo()); 178 image.setInfo(framebuffers[2]->getCanvas()->imageInfo());
175 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0)); 179 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0));
176 180
177 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); 181 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
178 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); 182 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
179 183
180 // Make sure the updates are correctly propagated to the native surface. 184 // Make sure the updates are correctly propagated to the native surface.
181 for (int i = 0; i < image.height(); ++i) { 185 for (int i = 0; i < image.height(); ++i) {
182 for (int j = 0; j < image.width(); ++j) { 186 for (int j = 0; j < image.width(); ++j) {
183 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) 187 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
184 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); 188 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
185 else if (j < kDefaultMode.hdisplay / 2) 189 else if (j < kDefaultMode.hdisplay / 2)
186 EXPECT_EQ(SK_ColorRED, image.getColor(j, i)); 190 EXPECT_EQ(SK_ColorRED, image.getColor(j, i));
187 else 191 else
188 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); 192 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
189 } 193 }
190 } 194 }
191 } 195 }
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_surface.cc ('k') | ui/ozone/platform/drm/gpu/drm_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698