OLD | NEW |
---|---|
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 "content/shell/renderer/test_runner/web_test_proxy.h" | 5 #include "content/shell/renderer/test_runner/web_test_proxy.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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); | 390 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); |
391 dataUtf8 += dumpFrameScrollPosition(frame, recursive); | 391 dataUtf8 += dumpFrameScrollPosition(frame, recursive); |
392 } | 392 } |
393 | 393 |
394 if (test_interfaces_->testRunner()->shouldDumpBackForwardList()) | 394 if (test_interfaces_->testRunner()->shouldDumpBackForwardList()) |
395 dataUtf8 += dumpAllBackForwardLists(test_interfaces_, delegate_); | 395 dataUtf8 += dumpAllBackForwardLists(test_interfaces_, delegate_); |
396 | 396 |
397 return dataUtf8; | 397 return dataUtf8; |
398 } | 398 } |
399 | 399 |
400 SkCanvas* WebTestProxyBase::CapturePixels() { | |
401 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixels"); | |
402 web_widget_->layout(); | |
403 if (test_interfaces_->testRunner()->isPrinting()) | |
404 PaintPagesWithBoundaries(); | |
405 else | |
406 PaintInvalidatedRegion(); | |
407 | |
408 DrawSelectionRect(GetCanvas()); | |
409 | |
410 return GetCanvas(); | |
411 } | |
412 | |
413 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | 400 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
414 // See if we need to draw the selection bounds rect. Selection bounds | 401 // See if we need to draw the selection bounds rect. Selection bounds |
415 // rect is the rect enclosing the (possibly transformed) selection. | 402 // rect is the rect enclosing the (possibly transformed) selection. |
416 // The rect should be drawn after everything is laid out and painted. | 403 // The rect should be drawn after everything is laid out and painted. |
417 if (!test_interfaces_->testRunner()->shouldDumpSelectionRect()) return; | 404 if (!test_interfaces_->testRunner()->shouldDumpSelectionRect()) return; |
418 // If there is a selection rect - draw a red 1px border enclosing rect | 405 // If there is a selection rect - draw a red 1px border enclosing rect |
419 WebRect wr = GetWebView()->mainFrame()->selectionBoundsRect(); | 406 WebRect wr = GetWebView()->mainFrame()->selectionBoundsRect(); |
420 if (wr.isEmpty()) return; | 407 if (wr.isEmpty()) return; |
421 // Render a red rectangle bounding selection rect | 408 // Render a red rectangle bounding selection rect |
422 SkPaint paint; | 409 SkPaint paint; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 } | 452 } |
466 | 453 |
467 composite_and_readback_callbacks_.push_back(callback); | 454 composite_and_readback_callbacks_.push_back(callback); |
468 web_widget_->compositeAndReadbackAsync(this); | 455 web_widget_->compositeAndReadbackAsync(this); |
469 } | 456 } |
470 | 457 |
471 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { | 458 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { |
472 log_console_output_ = enabled; | 459 log_console_output_ = enabled; |
473 } | 460 } |
474 | 461 |
475 void WebTestProxyBase::PaintRect(const WebRect& rect) { | |
476 DCHECK(!is_painting_); | |
477 DCHECK(GetCanvas()); | |
478 is_painting_ = true; | |
479 float deviceScaleFactor = GetWebView()->deviceScaleFactor(); | |
480 int scaledX = | |
481 static_cast<int>(static_cast<float>(rect.x) * deviceScaleFactor); | |
482 int scaledY = | |
483 static_cast<int>(static_cast<float>(rect.y) * deviceScaleFactor); | |
484 int scaledWidth = static_cast<int>( | |
485 ceil(static_cast<float>(rect.width) * deviceScaleFactor)); | |
486 int scaledHeight = static_cast<int>( | |
487 ceil(static_cast<float>(rect.height) * deviceScaleFactor)); | |
488 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight); | |
489 web_widget_->paint(GetCanvas(), deviceRect); | |
490 is_painting_ = false; | |
491 } | |
492 | |
493 void WebTestProxyBase::PaintInvalidatedRegion() { | |
494 web_widget_->animate(0.0); | |
495 web_widget_->layout(); | |
496 WebSize widgetSize = web_widget_->size(); | |
497 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height); | |
498 | |
499 // Paint the canvas if necessary. Allow painting to generate extra rects | |
500 // for the first two calls. This is necessary because some WebCore rendering | |
501 // objects update their layout only when painted. | |
502 // Store the total area painted in total_paint. Then tell the gdk window | |
503 // to update that area after we're done painting it. | |
504 for (int i = 0; i < 3; ++i) { | |
505 // rect = intersect(paint_rect_ , clientRect) | |
506 WebRect damageRect = paint_rect_; | |
507 int left = max(damageRect.x, clientRect.x); | |
508 int top = max(damageRect.y, clientRect.y); | |
509 int right = | |
510 min(damageRect.x + damageRect.width, clientRect.x + clientRect.width); | |
511 int bottom = | |
512 min(damageRect.y + damageRect.height, clientRect.y + clientRect.height); | |
513 WebRect rect; | |
514 if (left < right && top < bottom) | |
515 rect = WebRect(left, top, right - left, bottom - top); | |
516 | |
517 paint_rect_ = WebRect(); | |
518 if (rect.isEmpty()) continue; | |
519 PaintRect(rect); | |
520 } | |
521 DCHECK(paint_rect_.isEmpty()); | |
522 } | |
523 | |
524 void WebTestProxyBase::PaintPagesWithBoundaries() { | 462 void WebTestProxyBase::PaintPagesWithBoundaries() { |
525 DCHECK(!is_painting_); | 463 DCHECK(!is_painting_); |
526 DCHECK(GetCanvas()); | 464 DCHECK(GetCanvas()); |
527 is_painting_ = true; | 465 is_painting_ = true; |
528 | 466 |
529 WebSize pageSizeInPixels = web_widget_->size(); | 467 WebSize pageSizeInPixels = web_widget_->size(); |
530 WebFrame* webFrame = GetWebView()->mainFrame(); | 468 WebFrame* webFrame = GetWebView()->mainFrame(); |
531 | 469 |
532 int pageCount = webFrame->printBegin(pageSizeInPixels); | 470 int pageCount = webFrame->printBegin(pageSizeInPixels); |
533 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; | 471 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; |
(...skipping 22 matching lines...) Expand all Loading... | |
556 ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor)); | 494 ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor)); |
557 int scaledHeight = static_cast<int>( | 495 int scaledHeight = static_cast<int>( |
558 ceil(static_cast<float>(widgetSize.height) * deviceScaleFactor)); | 496 ceil(static_cast<float>(widgetSize.height) * deviceScaleFactor)); |
559 // We're allocating the canvas to be non-opaque (third parameter), so we | 497 // We're allocating the canvas to be non-opaque (third parameter), so we |
560 // don't end up with uninitialized memory if a layout test doesn't damage | 498 // don't end up with uninitialized memory if a layout test doesn't damage |
561 // the entire view. | 499 // the entire view. |
562 canvas_.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); | 500 canvas_.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); |
563 return canvas_.get(); | 501 return canvas_.get(); |
564 } | 502 } |
565 | 503 |
566 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { | |
567 const blink::WebSize& size = web_widget_->size(); | |
568 WebRect rect(0, 0, size.width, size.height); | |
569 paint_rect_ = rect; | |
570 PaintInvalidatedRegion(); | |
571 | |
572 if (!callback.is_null()) callback.Run(); | |
573 } | |
574 | |
575 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, | 504 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, |
576 const SkBitmap& bitmap) { | 505 const SkBitmap& bitmap) { |
577 // Verify we actually composited. | 506 // Verify we actually composited. |
578 CHECK_NE(0, bitmap.info().fWidth); | 507 CHECK_NE(0, bitmap.info().fWidth); |
579 CHECK_NE(0, bitmap.info().fHeight); | 508 CHECK_NE(0, bitmap.info().fHeight); |
580 if (!callback.is_null()) callback.Run(); | 509 if (!callback.is_null()) callback.Run(); |
581 } | 510 } |
582 | 511 |
583 void WebTestProxyBase::DisplayAsyncThen(const base::Closure& callback) { | 512 void WebTestProxyBase::DisplayAsyncThen(const base::Closure& callback) { |
584 TRACE_EVENT0("shell", "WebTestProxyBase::DisplayAsyncThen"); | 513 TRACE_EVENT0("shell", "WebTestProxyBase::DisplayAsyncThen"); |
585 | 514 |
586 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. | 515 CHECK(web_widget_->isAcceleratedCompositingActive()); |
danakj
2014/05/15 14:29:35
this could equivalently be a DCHECK i think, but w
| |
587 if (!web_widget_->isAcceleratedCompositingActive()) { | |
588 TRACE_EVENT0("shell", | |
589 "WebTestProxyBase::DisplayAsyncThen " | |
590 "isAcceleratedCompositingActive false"); | |
591 base::MessageLoopProxy::current()->PostTask( | |
592 FROM_HERE, base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, | |
593 base::Unretained(this), callback)); | |
594 return; | |
595 } | |
596 | |
597 CapturePixelsAsync(base::Bind(&WebTestProxyBase::DidDisplayAsync, | 516 CapturePixelsAsync(base::Bind(&WebTestProxyBase::DidDisplayAsync, |
598 base::Unretained(this), callback)); | 517 base::Unretained(this), callback)); |
599 } | 518 } |
600 | 519 |
601 void WebTestProxyBase::DiscardBackingStore() { canvas_.reset(); } | 520 void WebTestProxyBase::DiscardBackingStore() { canvas_.reset(); } |
602 | 521 |
603 WebMIDIClientMock* WebTestProxyBase::GetMIDIClientMock() { | 522 WebMIDIClientMock* WebTestProxyBase::GetMIDIClientMock() { |
604 if (!m_midiClient.get()) m_midiClient.reset(new WebMIDIClientMock); | 523 if (!m_midiClient.get()) m_midiClient.reset(new WebMIDIClientMock); |
605 return m_midiClient.get(); | 524 return m_midiClient.get(); |
606 } | 525 } |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 } | 1184 } |
1266 } | 1185 } |
1267 | 1186 |
1268 void WebTestProxyBase::ResetInputMethod() { | 1187 void WebTestProxyBase::ResetInputMethod() { |
1269 // If a composition text exists, then we need to let the browser process | 1188 // If a composition text exists, then we need to let the browser process |
1270 // to cancel the input method's ongoing composition session. | 1189 // to cancel the input method's ongoing composition session. |
1271 if (web_widget_) web_widget_->confirmComposition(); | 1190 if (web_widget_) web_widget_->confirmComposition(); |
1272 } | 1191 } |
1273 | 1192 |
1274 } // namespace content | 1193 } // namespace content |
OLD | NEW |