| 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/shell/renderer/webkit_test_runner.h" | 5 #include "content/shell/renderer/webkit_test_runner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <clocale> | 8 #include <clocale> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 namespace content { | 91 namespace content { |
| 92 | 92 |
| 93 namespace { | 93 namespace { |
| 94 | 94 |
| 95 void InvokeTaskHelper(void* context) { | 95 void InvokeTaskHelper(void* context) { |
| 96 WebTask* task = reinterpret_cast<WebTask*>(context); | 96 WebTask* task = reinterpret_cast<WebTask*>(context); |
| 97 task->run(); | 97 task->run(); |
| 98 delete task; | 98 delete task; |
| 99 } | 99 } |
| 100 | 100 |
| 101 #if !defined(OS_MACOSX) | |
| 102 void MakeBitmapOpaque(SkBitmap* bitmap) { | |
| 103 SkAutoLockPixels lock(*bitmap); | |
| 104 DCHECK_EQ(bitmap->config(), SkBitmap::kARGB_8888_Config); | |
| 105 for (int y = 0; y < bitmap->height(); ++y) { | |
| 106 uint32_t* row = bitmap->getAddr32(0, y); | |
| 107 for (int x = 0; x < bitmap->width(); ++x) | |
| 108 row[x] |= 0xFF000000; // Set alpha bits to 1. | |
| 109 } | |
| 110 } | |
| 111 #endif | |
| 112 | |
| 113 void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) { | |
| 114 SkBaseDevice* device = skia::GetTopDevice(*canvas); | |
| 115 const SkBitmap& bitmap = device->accessBitmap(false); | |
| 116 const bool success = bitmap.copyTo(snapshot, kPMColor_SkColorType); | |
| 117 DCHECK(success); | |
| 118 | |
| 119 #if !defined(OS_MACOSX) | |
| 120 // Only the expected PNGs for Mac have a valid alpha channel. | |
| 121 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 122 switches::kEnableOverlayFullscreenVideo)) | |
| 123 MakeBitmapOpaque(snapshot); | |
| 124 #endif | |
| 125 } | |
| 126 | |
| 127 class SyncNavigationStateVisitor : public RenderViewVisitor { | 101 class SyncNavigationStateVisitor : public RenderViewVisitor { |
| 128 public: | 102 public: |
| 129 SyncNavigationStateVisitor() {} | 103 SyncNavigationStateVisitor() {} |
| 130 virtual ~SyncNavigationStateVisitor() {} | 104 virtual ~SyncNavigationStateVisitor() {} |
| 131 | 105 |
| 132 virtual bool Visit(RenderView* render_view) OVERRIDE { | 106 virtual bool Visit(RenderView* render_view) OVERRIDE { |
| 133 SyncNavigationState(render_view); | 107 SyncNavigationState(render_view); |
| 134 return true; | 108 return true; |
| 135 } | 109 } |
| 136 private: | 110 private: |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 if (interfaces->testRunner()->shouldDumpAsAudio()) { | 616 if (interfaces->testRunner()->shouldDumpAsAudio()) { |
| 643 std::vector<unsigned char> vector_data; | 617 std::vector<unsigned char> vector_data; |
| 644 interfaces->testRunner()->getAudioData(&vector_data); | 618 interfaces->testRunner()->getAudioData(&vector_data); |
| 645 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data)); | 619 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data)); |
| 646 } else { | 620 } else { |
| 647 Send(new ShellViewHostMsg_TextDump(routing_id(), | 621 Send(new ShellViewHostMsg_TextDump(routing_id(), |
| 648 proxy()->CaptureTree(false))); | 622 proxy()->CaptureTree(false))); |
| 649 | 623 |
| 650 if (test_config_.enable_pixel_dumping && | 624 if (test_config_.enable_pixel_dumping && |
| 651 interfaces->testRunner()->shouldGeneratePixelResults()) { | 625 interfaces->testRunner()->shouldGeneratePixelResults()) { |
| 652 // TODO(danakj): Remove when kForceCompositingMode is everywhere. | 626 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive()); |
| 653 if (!render_view()->GetWebView()->isAcceleratedCompositingActive()) { | 627 proxy()->CapturePixelsAsync(base::Bind( |
| 654 SkBitmap snapshot; | 628 &WebKitTestRunner::CaptureDumpPixels, base::Unretained(this))); |
| 655 CopyCanvasToBitmap(proxy()->CapturePixels(), &snapshot); | |
| 656 CaptureDumpPixels(snapshot); | |
| 657 } else { | |
| 658 proxy()->CapturePixelsAsync(base::Bind( | |
| 659 &WebKitTestRunner::CaptureDumpPixels, base::Unretained(this))); | |
| 660 } | |
| 661 return; | 629 return; |
| 662 } | 630 } |
| 663 } | 631 } |
| 664 | 632 |
| 665 CaptureDumpComplete(); | 633 CaptureDumpComplete(); |
| 666 } | 634 } |
| 667 | 635 |
| 668 void WebKitTestRunner::CaptureDumpPixels(const SkBitmap& snapshot) { | 636 void WebKitTestRunner::CaptureDumpPixels(const SkBitmap& snapshot) { |
| 669 DCHECK_NE(0, snapshot.info().fWidth); | 637 DCHECK_NE(0, snapshot.info().fWidth); |
| 670 DCHECK_NE(0, snapshot.info().fHeight); | 638 DCHECK_NE(0, snapshot.info().fHeight); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 714 |
| 747 leak_detector_->TryLeakDetection(main_frame); | 715 leak_detector_->TryLeakDetection(main_frame); |
| 748 } | 716 } |
| 749 | 717 |
| 750 void WebKitTestRunner::ReportLeakDetectionResult( | 718 void WebKitTestRunner::ReportLeakDetectionResult( |
| 751 const LeakDetectionResult& report) { | 719 const LeakDetectionResult& report) { |
| 752 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); | 720 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); |
| 753 } | 721 } |
| 754 | 722 |
| 755 } // namespace content | 723 } // namespace content |
| OLD | NEW |