Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 gfx::Size size_; | 144 gfx::Size size_; |
| 145 base::Callback<void(bool)> callback_; | 145 base::Callback<void(bool)> callback_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 148 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
| 149 public: | 149 public: |
| 150 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) | 150 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) |
| 151 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} | 151 : RenderWidgetHostViewAura(widget), |
| 152 has_resize_lock_(false) {} | |
| 152 | 153 |
| 153 virtual ~FakeRenderWidgetHostViewAura() {} | 154 virtual ~FakeRenderWidgetHostViewAura() {} |
| 154 | 155 |
| 156 const blink::WebInputEvent* last_input_event() const { | |
| 157 return last_input_event_.get(); | |
| 158 } | |
| 159 | |
| 160 scoped_ptr<cc::CopyOutputRequest> ReleaseLastCopyRequest() { | |
| 161 return last_copy_request_.Pass(); | |
| 162 } | |
| 163 | |
| 164 void RunOnCompositingDidCommit() { | |
| 165 OnCompositingDidCommit(window()->GetHost()->compositor()); | |
| 166 } | |
| 167 | |
| 155 virtual bool ShouldCreateResizeLock() OVERRIDE { | 168 virtual bool ShouldCreateResizeLock() OVERRIDE { |
| 156 gfx::Size desired_size = window()->bounds().size(); | 169 gfx::Size desired_size = window()->bounds().size(); |
| 157 return desired_size != current_frame_size_in_dip(); | 170 return desired_size != current_frame_size_in_dip(); |
| 158 } | 171 } |
| 159 | 172 |
| 160 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) | 173 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) |
| 161 OVERRIDE { | 174 OVERRIDE { |
| 162 gfx::Size desired_size = window()->bounds().size(); | 175 gfx::Size desired_size = window()->bounds().size(); |
| 163 return scoped_ptr<ResizeLock>( | 176 return scoped_ptr<ResizeLock>( |
| 164 new FakeResizeLock(desired_size, defer_compositor_lock)); | 177 new FakeResizeLock(desired_size, defer_compositor_lock)); |
| 165 } | 178 } |
| 166 | 179 |
| 167 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) | 180 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) |
| 168 OVERRIDE { | 181 OVERRIDE { |
| 169 last_copy_request_ = request.Pass(); | 182 last_copy_request_ = request.Pass(); |
| 170 if (last_copy_request_->has_texture_mailbox()) { | 183 if (last_copy_request_->has_texture_mailbox()) { |
| 171 // Give the resulting texture a size. | 184 // Give the resulting texture a size. |
| 172 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 185 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 173 GLuint texture = gl_helper->ConsumeMailboxToTexture( | 186 GLuint texture = gl_helper->ConsumeMailboxToTexture( |
| 174 last_copy_request_->texture_mailbox().mailbox(), | 187 last_copy_request_->texture_mailbox().mailbox(), |
| 175 last_copy_request_->texture_mailbox().sync_point()); | 188 last_copy_request_->texture_mailbox().sync_point()); |
| 176 gl_helper->ResizeTexture(texture, window()->bounds().size()); | 189 gl_helper->ResizeTexture(texture, window()->bounds().size()); |
| 177 gl_helper->DeleteTexture(texture); | 190 gl_helper->DeleteTexture(texture); |
| 178 } | 191 } |
| 179 } | 192 } |
| 180 | 193 |
| 181 void RunOnCompositingDidCommit() { | 194 virtual InputEventAckState FilterInputEvent( |
| 182 OnCompositingDidCommit(window()->GetHost()->compositor()); | 195 const blink::WebInputEvent& input_event) OVERRIDE { |
|
Daniel Erat
2014/04/21 23:26:39
please let me know if there's a better way to capt
| |
| 196 last_input_event_.reset(new blink::WebInputEvent(input_event)); | |
| 197 return RenderWidgetHostViewAura::FilterInputEvent(input_event); | |
| 183 } | 198 } |
| 184 | 199 |
| 200 private: | |
| 185 // A lock that doesn't actually do anything to the compositor, and does not | 201 // A lock that doesn't actually do anything to the compositor, and does not |
| 186 // time out. | 202 // time out. |
| 187 class FakeResizeLock : public ResizeLock { | 203 class FakeResizeLock : public ResizeLock { |
| 188 public: | 204 public: |
| 189 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) | 205 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) |
| 190 : ResizeLock(new_size, defer_compositor_lock) {} | 206 : ResizeLock(new_size, defer_compositor_lock) {} |
| 191 }; | 207 }; |
| 192 | 208 |
| 193 bool has_resize_lock_; | 209 bool has_resize_lock_; |
| 194 gfx::Size last_frame_size_; | 210 gfx::Size last_frame_size_; |
| 195 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; | 211 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; |
| 212 scoped_ptr<blink::WebInputEvent> last_input_event_; | |
| 213 | |
| 214 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura); | |
| 196 }; | 215 }; |
| 197 | 216 |
| 198 class RenderWidgetHostViewAuraTest : public testing::Test { | 217 class RenderWidgetHostViewAuraTest : public testing::Test { |
| 199 public: | 218 public: |
| 200 RenderWidgetHostViewAuraTest() | 219 RenderWidgetHostViewAuraTest() |
| 201 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 220 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
| 202 | 221 |
| 203 void SetUpEnvironment() { | 222 void SetUpEnvironment() { |
| 204 ImageTransportFactory::InitializeForUnitTests( | 223 ImageTransportFactory::InitializeForUnitTests( |
| 205 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); | 224 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 // scale on it. | 1261 // scale on it. |
| 1243 view_->OnSwapCompositorFrame( | 1262 view_->OnSwapCompositorFrame( |
| 1244 1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size))); | 1263 1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size))); |
| 1245 | 1264 |
| 1246 // When we get a new frame with the same frame size in physical pixels, but a | 1265 // When we get a new frame with the same frame size in physical pixels, but a |
| 1247 // different scale, we should generate a new frame provider, as the final | 1266 // different scale, we should generate a new frame provider, as the final |
| 1248 // result will need to be scaled differently to the screen. | 1267 // result will need to be scaled differently to the screen. |
| 1249 EXPECT_NE(frame_provider.get(), view_->frame_provider_.get()); | 1268 EXPECT_NE(frame_provider.get(), view_->frame_provider_.get()); |
| 1250 } | 1269 } |
| 1251 | 1270 |
| 1271 TEST_F(RenderWidgetHostViewAuraTest, ClearControlOnScrollEvent) { | |
| 1272 view_->InitAsChild(NULL); | |
| 1273 view_->Show(); | |
| 1274 ui::ScrollEvent event(ui::ET_SCROLL, | |
| 1275 gfx::Point(30, 30), | |
| 1276 ui::EventTimeForNow(), | |
| 1277 ui::EF_CONTROL_DOWN, | |
| 1278 0, 0, 0, 0, | |
| 1279 2 /* finger_count */); | |
| 1280 | |
| 1281 // The Control modifier should be cleared in the forwarded event. | |
| 1282 view_->OnScrollEvent(&event); | |
| 1283 const blink::WebInputEvent* web_event = view_->last_input_event(); | |
| 1284 ASSERT_TRUE(web_event); | |
| 1285 EXPECT_EQ(blink::WebInputEvent::MouseWheel, web_event->type); | |
| 1286 EXPECT_EQ(0, web_event->modifiers); | |
| 1287 } | |
| 1288 | |
| 1289 TEST_F(RenderWidgetHostViewAuraTest, | |
| 1290 PreserveControlOnScrollEventWithOtherModifiers) { | |
| 1291 view_->InitAsChild(NULL); | |
| 1292 view_->Show(); | |
| 1293 ui::ScrollEvent event(ui::ET_SCROLL, | |
| 1294 gfx::Point(30, 30), | |
| 1295 ui::EventTimeForNow(), | |
| 1296 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, | |
| 1297 0, 0, 0, 0, | |
| 1298 2 /* finger_count */); | |
| 1299 | |
| 1300 // The Control modifier should be preserved since Alt was also down. | |
| 1301 view_->OnScrollEvent(&event); | |
| 1302 const blink::WebInputEvent* web_event = view_->last_input_event(); | |
| 1303 ASSERT_TRUE(web_event); | |
| 1304 EXPECT_EQ(blink::WebInputEvent::MouseWheel, web_event->type); | |
| 1305 EXPECT_EQ(blink::WebInputEvent::ControlKey | blink::WebInputEvent::AltKey, | |
| 1306 web_event->modifiers); | |
| 1307 } | |
| 1308 | |
| 1252 class RenderWidgetHostViewAuraCopyRequestTest | 1309 class RenderWidgetHostViewAuraCopyRequestTest |
| 1253 : public RenderWidgetHostViewAuraShutdownTest { | 1310 : public RenderWidgetHostViewAuraShutdownTest { |
| 1254 public: | 1311 public: |
| 1255 RenderWidgetHostViewAuraCopyRequestTest() | 1312 RenderWidgetHostViewAuraCopyRequestTest() |
| 1256 : callback_count_(0), result_(false) {} | 1313 : callback_count_(0), result_(false) {} |
| 1257 | 1314 |
| 1258 void CallbackMethod(const base::Closure& quit_closure, bool result) { | 1315 void CallbackMethod(const base::Closure& quit_closure, bool result) { |
| 1259 result_ = result; | 1316 result_ = result; |
| 1260 callback_count_++; | 1317 callback_count_++; |
| 1261 quit_closure.Run(); | 1318 quit_closure.Run(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1282 view_->SetSize(view_rect.size()); | 1339 view_->SetSize(view_rect.size()); |
| 1283 view_->WasShown(); | 1340 view_->WasShown(); |
| 1284 | 1341 |
| 1285 scoped_ptr<FakeFrameSubscriber> frame_subscriber(new FakeFrameSubscriber( | 1342 scoped_ptr<FakeFrameSubscriber> frame_subscriber(new FakeFrameSubscriber( |
| 1286 view_rect.size(), | 1343 view_rect.size(), |
| 1287 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod, | 1344 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod, |
| 1288 base::Unretained(this), | 1345 base::Unretained(this), |
| 1289 run_loop.QuitClosure()))); | 1346 run_loop.QuitClosure()))); |
| 1290 | 1347 |
| 1291 EXPECT_EQ(0, callback_count_); | 1348 EXPECT_EQ(0, callback_count_); |
| 1292 EXPECT_FALSE(view_->last_copy_request_); | 1349 request = view_->ReleaseLastCopyRequest(); |
| 1350 EXPECT_FALSE(request); | |
| 1293 | 1351 |
| 1294 view_->BeginFrameSubscription( | 1352 view_->BeginFrameSubscription( |
| 1295 frame_subscriber.PassAs<RenderWidgetHostViewFrameSubscriber>()); | 1353 frame_subscriber.PassAs<RenderWidgetHostViewFrameSubscriber>()); |
| 1296 view_->OnSwapCompositorFrame( | 1354 view_->OnSwapCompositorFrame( |
| 1297 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect))); | 1355 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect))); |
| 1298 | 1356 |
| 1299 EXPECT_EQ(0, callback_count_); | 1357 EXPECT_EQ(0, callback_count_); |
| 1300 EXPECT_TRUE(view_->last_copy_request_); | 1358 request = view_->ReleaseLastCopyRequest(); |
| 1301 EXPECT_TRUE(view_->last_copy_request_->has_texture_mailbox()); | 1359 ASSERT_TRUE(request); |
| 1302 request = view_->last_copy_request_.Pass(); | 1360 EXPECT_TRUE(request->has_texture_mailbox()); |
| 1303 | 1361 |
| 1304 // There should be one subscriber texture in flight. | 1362 // There should be one subscriber texture in flight. |
| 1305 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size()); | 1363 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size()); |
| 1306 | 1364 |
| 1307 // Send back the mailbox included in the request. There's no release callback | 1365 // Send back the mailbox included in the request. There's no release callback |
| 1308 // since the mailbox came from the RWHVA originally. | 1366 // since the mailbox came from the RWHVA originally. |
| 1309 request->SendTextureResult(view_rect.size(), | 1367 request->SendTextureResult(view_rect.size(), |
| 1310 request->texture_mailbox(), | 1368 request->texture_mailbox(), |
| 1311 scoped_ptr<cc::SingleReleaseCallback>()); | 1369 scoped_ptr<cc::SingleReleaseCallback>()); |
| 1312 | 1370 |
| 1313 // This runs until the callback happens. | 1371 // This runs until the callback happens. |
| 1314 run_loop.Run(); | 1372 run_loop.Run(); |
| 1315 | 1373 |
| 1316 // The callback should succeed. | 1374 // The callback should succeed. |
| 1317 EXPECT_EQ(0u, view_->active_frame_subscriber_textures_.size()); | 1375 EXPECT_EQ(0u, view_->active_frame_subscriber_textures_.size()); |
| 1318 EXPECT_EQ(1, callback_count_); | 1376 EXPECT_EQ(1, callback_count_); |
| 1319 EXPECT_TRUE(result_); | 1377 EXPECT_TRUE(result_); |
| 1320 | 1378 |
| 1321 view_->OnSwapCompositorFrame( | 1379 view_->OnSwapCompositorFrame( |
| 1322 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect))); | 1380 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect))); |
| 1323 | 1381 |
| 1324 EXPECT_EQ(1, callback_count_); | 1382 EXPECT_EQ(1, callback_count_); |
| 1325 request = view_->last_copy_request_.Pass(); | 1383 request = view_->ReleaseLastCopyRequest(); |
| 1326 | 1384 |
| 1327 // There should be one subscriber texture in flight again. | 1385 // There should be one subscriber texture in flight again. |
| 1328 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size()); | 1386 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size()); |
| 1329 | 1387 |
| 1330 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory. | 1388 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory. |
| 1331 TearDownEnvironment(); | 1389 TearDownEnvironment(); |
| 1332 | 1390 |
| 1333 // Send back the mailbox included in the request. There's no release callback | 1391 // Send back the mailbox included in the request. There's no release callback |
| 1334 // since the mailbox came from the RWHVA originally. | 1392 // since the mailbox came from the RWHVA originally. |
| 1335 request->SendTextureResult(view_rect.size(), | 1393 request->SendTextureResult(view_rect.size(), |
| 1336 request->texture_mailbox(), | 1394 request->texture_mailbox(), |
| 1337 scoped_ptr<cc::SingleReleaseCallback>()); | 1395 scoped_ptr<cc::SingleReleaseCallback>()); |
| 1338 | 1396 |
| 1339 // Because the copy request callback may be holding state within it, that | 1397 // Because the copy request callback may be holding state within it, that |
| 1340 // state must handle the RWHVA and ImageTransportFactory going away before the | 1398 // state must handle the RWHVA and ImageTransportFactory going away before the |
| 1341 // callback is called. This test passes if it does not crash as a result of | 1399 // callback is called. This test passes if it does not crash as a result of |
| 1342 // these things being destroyed. | 1400 // these things being destroyed. |
| 1343 EXPECT_EQ(2, callback_count_); | 1401 EXPECT_EQ(2, callback_count_); |
| 1344 EXPECT_FALSE(result_); | 1402 EXPECT_FALSE(result_); |
| 1345 } | 1403 } |
| 1346 | 1404 |
| 1347 } // namespace content | 1405 } // namespace content |
| OLD | NEW |