Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell/renderer/test_runner/WebTestProxy.h" | 5 #include "content/shell/renderer/test_runner/WebTestProxy.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 bitmap.info().fWidth, | 482 bitmap.info().fWidth, |
| 483 "y", | 483 "y", |
| 484 bitmap.info().fHeight); | 484 bitmap.info().fHeight); |
| 485 SkCanvas canvas(bitmap); | 485 SkCanvas canvas(bitmap); |
| 486 DrawSelectionRect(&canvas); | 486 DrawSelectionRect(&canvas); |
| 487 base::ResetAndReturn(&m_compositeAndReadbackCallback).Run(bitmap); | 487 base::ResetAndReturn(&m_compositeAndReadbackCallback).Run(bitmap); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void WebTestProxyBase::CapturePixelsAsync( | 490 void WebTestProxyBase::CapturePixelsAsync( |
| 491 base::Callback<void(const SkBitmap&)> callback) { | 491 base::Callback<void(const SkBitmap&)> callback) { |
| 492 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | |
| 493 | |
| 492 m_compositeAndReadbackCallback = callback; | 494 m_compositeAndReadbackCallback = callback; |
| 493 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | |
| 494 | 495 |
| 495 // Do a layout here because it might leave compositing mode! x.x | 496 // Do a layout here because it might leave compositing mode! x.x |
| 496 // TODO(danakj): Remove this when we have kForceCompositingMode everywhere. | 497 // TODO(danakj): Remove this when we have kForceCompositingMode everywhere. |
| 497 webWidget()->layout(); | 498 webWidget()->layout(); |
| 498 | 499 |
| 499 if (!webWidget()->compositeAndReadbackAsync(this)) { | 500 if (!webWidget()->isAcceleratedCompositingActive()) { |
|
danakj
2014/05/05 18:35:17
This was the only way that compositeAndReadbackAsy
| |
| 500 TRACE_EVENT0("shell", | 501 TRACE_EVENT0("shell", |
| 501 "WebTestProxyBase::CapturePixelsAsync " | 502 "WebTestProxyBase::CapturePixelsAsync " |
| 502 "compositeAndReadbackAsync failed"); | 503 "isAcceleratedCompositingActive false"); |
| 503 didCompositeAndReadback(SkBitmap()); | 504 didCompositeAndReadback(SkBitmap()); |
| 505 return; | |
| 504 } | 506 } |
| 507 | |
| 508 webWidget()->compositeAndReadbackAsync(this); | |
| 505 } | 509 } |
| 506 | 510 |
| 507 void WebTestProxyBase::setLogConsoleOutput(bool enabled) | 511 void WebTestProxyBase::setLogConsoleOutput(bool enabled) |
| 508 { | 512 { |
| 509 m_logConsoleOutput = enabled; | 513 m_logConsoleOutput = enabled; |
| 510 } | 514 } |
| 511 | 515 |
| 512 void WebTestProxyBase::paintRect(const WebRect& rect) | 516 void WebTestProxyBase::paintRect(const WebRect& rect) |
| 513 { | 517 { |
| 514 DCHECK(!m_isPainting); | 518 DCHECK(!m_isPainting); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 float deviceScaleFactor = webView()->deviceScaleFactor(); | 594 float deviceScaleFactor = webView()->deviceScaleFactor(); |
| 591 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor)); | 595 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor)); |
| 592 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh t) * deviceScaleFactor)); | 596 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh t) * deviceScaleFactor)); |
| 593 // We're allocating the canvas to be non-opaque (third parameter), so we | 597 // We're allocating the canvas to be non-opaque (third parameter), so we |
| 594 // don't end up with uninitialized memory if a layout test doesn't damage | 598 // don't end up with uninitialized memory if a layout test doesn't damage |
| 595 // the entire view. | 599 // the entire view. |
| 596 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); | 600 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); |
| 597 return m_canvas.get(); | 601 return m_canvas.get(); |
| 598 } | 602 } |
| 599 | 603 |
| 600 void WebTestProxyBase::display(base::Closure callback) | 604 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { |
| 601 { | |
| 602 const blink::WebSize& size = webWidget()->size(); | 605 const blink::WebSize& size = webWidget()->size(); |
| 603 WebRect rect(0, 0, size.width, size.height); | 606 WebRect rect(0, 0, size.width, size.height); |
| 604 m_paintRect = rect; | 607 m_paintRect = rect; |
| 605 paintInvalidatedRegion(); | 608 paintInvalidatedRegion(); |
| 606 | 609 |
| 607 if (!callback.is_null()) | 610 if (!callback.is_null()) |
| 608 callback.Run(); | 611 callback.Run(); |
| 609 } | 612 } |
| 610 | 613 |
| 614 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, | |
| 615 const SkBitmap& bitmap) { | |
| 616 if (!callback.is_null()) | |
| 617 callback.Run(); | |
| 618 } | |
| 619 | |
| 611 void WebTestProxyBase::displayAsyncThen(base::Closure callback) | 620 void WebTestProxyBase::displayAsyncThen(base::Closure callback) |
| 612 { | 621 { |
| 613 // TODO(enne): When compositing, this should invoke a real rAF, paint, | 622 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); |
| 614 // and commit. For now, just make sure that displayAsync is actually | 623 |
| 615 // async so that callers can't depend on synchronous behavior. | 624 // TODO(danakj): Just call CapturePixelsAsyc when we have |
| 616 m_delegate->postTask(new ClosureTask( | 625 // kForceCompositingMode everywhere. |
| 617 this, | 626 |
| 618 base::Bind( | 627 // Do a layout here because it might leave compositing mode! x.x |
| 619 &WebTestProxyBase::display, base::Unretained(this), callback))); | 628 webWidget()->layout(); |
| 629 | |
| 630 if (!webWidget()->isAcceleratedCompositingActive()) { | |
| 631 TRACE_EVENT0("shell", | |
| 632 "WebTestProxyBase::displayAsyncThen " | |
| 633 "isAcceleratedCompositingActive false"); | |
| 634 DisplayForSoftwareMode(callback); | |
| 635 return; | |
| 636 } | |
| 637 | |
| 638 m_compositeAndReadbackCallback = base::Bind( | |
|
danakj
2014/05/05 18:35:17
I could call CapturePixelsAsync here instead of se
enne (OOO)
2014/05/05 19:55:13
Yeah, I think that'd be cleaner. Can you just mov
| |
| 639 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback); | |
| 640 webWidget()->compositeAndReadbackAsync(this); | |
| 620 } | 641 } |
| 621 | 642 |
| 622 void WebTestProxyBase::discardBackingStore() | 643 void WebTestProxyBase::discardBackingStore() |
| 623 { | 644 { |
| 624 m_canvas.reset(); | 645 m_canvas.reset(); |
| 625 } | 646 } |
| 626 | 647 |
| 627 WebMIDIClientMock* WebTestProxyBase::midiClientMock() | 648 WebMIDIClientMock* WebTestProxyBase::midiClientMock() |
| 628 { | 649 { |
| 629 if (!m_midiClient.get()) | 650 if (!m_midiClient.get()) |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1296 | 1317 |
| 1297 void WebTestProxyBase::resetInputMethod() | 1318 void WebTestProxyBase::resetInputMethod() |
| 1298 { | 1319 { |
| 1299 // If a composition text exists, then we need to let the browser process | 1320 // If a composition text exists, then we need to let the browser process |
| 1300 // to cancel the input method's ongoing composition session. | 1321 // to cancel the input method's ongoing composition session. |
| 1301 if (m_webWidget) | 1322 if (m_webWidget) |
| 1302 m_webWidget->confirmComposition(); | 1323 m_webWidget->confirmComposition(); |
| 1303 } | 1324 } |
| 1304 | 1325 |
| 1305 } // namespace content | 1326 } // namespace content |
| OLD | NEW |