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

Side by Side Diff: content/shell/webkit_test_runner.cc

Issue 12207175: [content shell] remove paint methods from WebKitTestRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « content/shell/webkit_test_runner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell/webkit_test_runner.h" 5 #include "content/shell/webkit_test_runner.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/md5.h" 10 #include "base/md5.h"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 WebFrame::RenderAsTextNormal; 484 WebFrame::RenderAsTextNormal;
485 if (printing_) 485 if (printing_)
486 render_text_behavior |= WebFrame::RenderAsTextPrinting; 486 render_text_behavior |= WebFrame::RenderAsTextPrinting;
487 dump = frame->renderTreeAsText(render_text_behavior).utf8(); 487 dump = frame->renderTreeAsText(render_text_behavior).utf8();
488 dump.append(DumpFrameScrollPosition(frame, dump_child_frames_as_text_)); 488 dump.append(DumpFrameScrollPosition(frame, dump_child_frames_as_text_));
489 } 489 }
490 Send(new ShellViewHostMsg_TextDump(routing_id(), dump)); 490 Send(new ShellViewHostMsg_TextDump(routing_id(), dump));
491 } 491 }
492 492
493 void WebKitTestRunner::CaptureImageDump() { 493 void WebKitTestRunner::CaptureImageDump() {
494 SkBitmap snapshot; 494 SkBitmap empty_image;
495 PaintInvalidatedRegion();
496 CopyCanvasToBitmap(GetCanvas(), &snapshot);
497
498 SkAutoLockPixels snapshot_lock(snapshot);
499 base::MD5Digest digest;
500 #if defined(OS_ANDROID)
501 // On Android, pixel layout is RGBA, however, other Chrome platforms use BGRA.
502 const uint8_t* raw_pixels =
503 reinterpret_cast<const uint8_t*>(snapshot.getPixels());
504 size_t snapshot_size = snapshot.getSize();
505 scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]);
506 for (size_t i = 0; i < snapshot_size; i += 4) {
507 reordered_pixels[i] = raw_pixels[i + 2];
508 reordered_pixels[i + 1] = raw_pixels[i + 1];
509 reordered_pixels[i + 2] = raw_pixels[i];
510 reordered_pixels[i + 3] = raw_pixels[i + 3];
511 }
512 base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest);
513 #else
514 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
515 #endif
516 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
517
518 if (actual_pixel_hash == expected_pixel_hash_) {
519 SkBitmap empty_image;
520 Send(new ShellViewHostMsg_ImageDump(
521 routing_id(), actual_pixel_hash, empty_image));
522 return;
523 }
524 Send(new ShellViewHostMsg_ImageDump( 495 Send(new ShellViewHostMsg_ImageDump(
525 routing_id(), actual_pixel_hash, snapshot)); 496 routing_id(), expected_pixel_hash_, empty_image));
526 } 497 }
527 498
528 void WebKitTestRunner::OnSetTestConfiguration( 499 void WebKitTestRunner::OnSetTestConfiguration(
529 const base::FilePath& current_working_directory, 500 const base::FilePath& current_working_directory,
530 bool enable_pixel_dumping, 501 bool enable_pixel_dumping,
531 int layout_test_timeout, 502 int layout_test_timeout,
532 bool allow_external_pages, 503 bool allow_external_pages,
533 const std::string& expected_pixel_hash) { 504 const std::string& expected_pixel_hash) {
534 current_working_directory_ = current_working_directory; 505 current_working_directory_ = current_working_directory;
535 enable_pixel_dumping_ = enable_pixel_dumping; 506 enable_pixel_dumping_ = enable_pixel_dumping;
536 layout_test_timeout_ = layout_test_timeout; 507 layout_test_timeout_ = layout_test_timeout;
537 allow_external_pages_ = allow_external_pages; 508 allow_external_pages_ = allow_external_pages;
538 expected_pixel_hash_ = expected_pixel_hash; 509 expected_pixel_hash_ = expected_pixel_hash;
539 } 510 }
540 511
541 SkCanvas* WebKitTestRunner::GetCanvas() {
542 WebView* view = render_view()->GetWebView();
543 const WebSize& size = view->size();
544 float device_scale_factor = view->deviceScaleFactor();
545 int width = std::ceil(device_scale_factor * size.width);
546 int height = std::ceil(device_scale_factor * size.height);
547
548 if (canvas_ &&
549 canvas_->getDeviceSize().width() == width &&
550 canvas_->getDeviceSize().height() == height) {
551 return canvas_.get();
552 }
553 canvas_.reset(skia::CreatePlatformCanvas(
554 size.width, size.height, true, 0, skia::RETURN_NULL_ON_FAILURE));
555 return canvas_.get();
556 }
557
558 void WebKitTestRunner::PaintRect(const WebRect& rect) {
559 WebView* view = render_view()->GetWebView();
560 float device_scale_factor = view->deviceScaleFactor();
561 int scaled_x = device_scale_factor * rect.x;
562 int scaled_y = device_scale_factor * rect.y;
563 int scaled_width = std::ceil(device_scale_factor * rect.width);
564 int scaled_height = std::ceil(device_scale_factor * rect.height);
565 // TODO(jochen): Verify that the scaling is correct once the HiDPI tests
566 // actually work.
567 WebRect device_rect(scaled_x, scaled_y, scaled_width, scaled_height);
568 view->paint(webkit_glue::ToWebCanvas(GetCanvas()), device_rect);
569 }
570
571 void WebKitTestRunner::PaintInvalidatedRegion() {
572 WebView* view = render_view()->GetWebView();
573 view->animate(0.0);
574 view->layout();
575 const WebSize& widget_size = view->size();
576 WebRect client_rect(0, 0, widget_size.width, widget_size.height);
577
578 // Paint the canvas if necessary. Allow painting to generate extra rects
579 // for the first two calls. This is necessary because some WebCore rendering
580 // objects update their layout only when painted.
581 for (int i = 0; i < 3; ++i) {
582 // Make sure that paint_rect is always inside the RenderView's visible
583 // area.
584 WebRect paint_rect = proxy_->paintRect();
585 int left = std::max(paint_rect.x, client_rect.x);
586 int top = std::max(paint_rect.y, client_rect.y);
587 int right = std::min(paint_rect.x + paint_rect.width,
588 client_rect.x + client_rect.width);
589 int bottom = std::min(paint_rect.y + paint_rect.height,
590 client_rect.y + client_rect.height);
591 WebRect rect;
592 if (left < right && top < bottom)
593 rect = WebRect(left, top, right - left, bottom - top);
594 proxy_->setPaintRect(WebRect());
595 if (rect.isEmpty())
596 continue;
597 PaintRect(rect);
598 }
599 CHECK(proxy_->paintRect().isEmpty());
600 }
601
602 void WebKitTestRunner::DisplayRepaintMask() {
603 GetCanvas()->drawARGB(167, 0, 0, 0);
604 }
605
606 } // namespace content 512 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/webkit_test_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698