| 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 481 |
| 482 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { | 482 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { |
| 483 TRACE_EVENT2("shell", | 483 TRACE_EVENT2("shell", |
| 484 "WebTestProxyBase::didCompositeAndReadback", | 484 "WebTestProxyBase::didCompositeAndReadback", |
| 485 "x", | 485 "x", |
| 486 bitmap.info().fWidth, | 486 bitmap.info().fWidth, |
| 487 "y", | 487 "y", |
| 488 bitmap.info().fHeight); | 488 bitmap.info().fHeight); |
| 489 SkCanvas canvas(bitmap); | 489 SkCanvas canvas(bitmap); |
| 490 DrawSelectionRect(&canvas); | 490 DrawSelectionRect(&canvas); |
| 491 DCHECK(!m_compositeAndReadbackCallback.is_null()); | 491 DCHECK(!m_compositeAndReadbackCallbacks.empty()); |
| 492 base::ResetAndReturn(&m_compositeAndReadbackCallback).Run(bitmap); | 492 m_compositeAndReadbackCallbacks.front().Run(bitmap); |
| 493 m_compositeAndReadbackCallbacks.pop_front(); |
| 493 } | 494 } |
| 494 | 495 |
| 495 void WebTestProxyBase::CapturePixelsAsync( | 496 void WebTestProxyBase::CapturePixelsAsync( |
| 496 base::Callback<void(const SkBitmap&)> callback) { | 497 base::Callback<void(const SkBitmap&)> callback) { |
| 497 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | 498 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); |
| 498 | 499 |
| 499 DCHECK(webWidget()->isAcceleratedCompositingActive()); | 500 DCHECK(webWidget()->isAcceleratedCompositingActive()); |
| 500 DCHECK(!callback.is_null()); | 501 DCHECK(!callback.is_null()); |
| 501 DCHECK(m_compositeAndReadbackCallback.is_null()); | 502 m_compositeAndReadbackCallbacks.push_back(callback); |
| 502 m_compositeAndReadbackCallback = callback; | |
| 503 webWidget()->compositeAndReadbackAsync(this); | 503 webWidget()->compositeAndReadbackAsync(this); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void WebTestProxyBase::setLogConsoleOutput(bool enabled) | 506 void WebTestProxyBase::setLogConsoleOutput(bool enabled) |
| 507 { | 507 { |
| 508 m_logConsoleOutput = enabled; | 508 m_logConsoleOutput = enabled; |
| 509 } | 509 } |
| 510 | 510 |
| 511 void WebTestProxyBase::paintRect(const WebRect& rect) | 511 void WebTestProxyBase::paintRect(const WebRect& rect) |
| 512 { | 512 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 float deviceScaleFactor = webView()->deviceScaleFactor(); | 589 float deviceScaleFactor = webView()->deviceScaleFactor(); |
| 590 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width)
* deviceScaleFactor)); | 590 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width)
* deviceScaleFactor)); |
| 591 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh
t) * deviceScaleFactor)); | 591 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh
t) * deviceScaleFactor)); |
| 592 // We're allocating the canvas to be non-opaque (third parameter), so we | 592 // We're allocating the canvas to be non-opaque (third parameter), so we |
| 593 // don't end up with uninitialized memory if a layout test doesn't damage | 593 // don't end up with uninitialized memory if a layout test doesn't damage |
| 594 // the entire view. | 594 // the entire view. |
| 595 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); | 595 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); |
| 596 return m_canvas.get(); | 596 return m_canvas.get(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void WebTestProxyBase::display(base::Closure callback) | 599 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { |
| 600 { | 600 const blink::WebSize& size = webWidget()->size(); |
| 601 const blink::WebSize& size = webWidget()->size(); | 601 WebRect rect(0, 0, size.width, size.height); |
| 602 WebRect rect(0, 0, size.width, size.height); | 602 m_paintRect = rect; |
| 603 m_paintRect = rect; | 603 paintInvalidatedRegion(); |
| 604 paintInvalidatedRegion(); | |
| 605 | 604 |
| 606 if (!callback.is_null()) | 605 if (!callback.is_null()) |
| 607 callback.Run(); | 606 callback.Run(); |
| 608 } | 607 } |
| 609 | 608 |
| 610 void WebTestProxyBase::displayAsyncThen(base::Closure callback) | 609 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, |
| 611 { | 610 const SkBitmap& bitmap) { |
| 612 // TODO(enne): When compositing, this should invoke a real rAF, paint, | 611 // Verify we actually composited. |
| 613 // and commit. For now, just make sure that displayAsync is actually | 612 CHECK_NE(0, bitmap.info().fWidth); |
| 614 // async so that callers can't depend on synchronous behavior. | 613 CHECK_NE(0, bitmap.info().fHeight); |
| 615 m_delegate->postTask(new ClosureTask( | 614 if (!callback.is_null()) |
| 616 this, | 615 callback.Run(); |
| 617 base::Bind( | 616 } |
| 618 &WebTestProxyBase::display, base::Unretained(this), callback))); | 617 |
| 618 void WebTestProxyBase::displayAsyncThen(base::Closure callback) { |
| 619 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); |
| 620 |
| 621 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. |
| 622 if (!webWidget()->isAcceleratedCompositingActive()) { |
| 623 TRACE_EVENT0("shell", |
| 624 "WebTestProxyBase::displayAsyncThen " |
| 625 "isAcceleratedCompositingActive false"); |
| 626 m_delegate->postTask( |
| 627 new ClosureTask(this, |
| 628 base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, |
| 629 base::Unretained(this), |
| 630 callback))); |
| 631 return; |
| 632 } |
| 633 |
| 634 CapturePixelsAsync(base::Bind( |
| 635 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback)); |
| 619 } | 636 } |
| 620 | 637 |
| 621 void WebTestProxyBase::discardBackingStore() | 638 void WebTestProxyBase::discardBackingStore() |
| 622 { | 639 { |
| 623 m_canvas.reset(); | 640 m_canvas.reset(); |
| 624 } | 641 } |
| 625 | 642 |
| 626 WebMIDIClientMock* WebTestProxyBase::midiClientMock() | 643 WebMIDIClientMock* WebTestProxyBase::midiClientMock() |
| 627 { | 644 { |
| 628 if (!m_midiClient.get()) | 645 if (!m_midiClient.get()) |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 | 1312 |
| 1296 void WebTestProxyBase::resetInputMethod() | 1313 void WebTestProxyBase::resetInputMethod() |
| 1297 { | 1314 { |
| 1298 // If a composition text exists, then we need to let the browser process | 1315 // If a composition text exists, then we need to let the browser process |
| 1299 // to cancel the input method's ongoing composition session. | 1316 // to cancel the input method's ongoing composition session. |
| 1300 if (m_webWidget) | 1317 if (m_webWidget) |
| 1301 m_webWidget->confirmComposition(); | 1318 m_webWidget->confirmComposition(); |
| 1302 } | 1319 } |
| 1303 | 1320 |
| 1304 } // namespace content | 1321 } // namespace content |
| OLD | NEW |