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

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

Issue 11138024: Simplify platform_canvas.h by recognizing that PlatformCanvas does not actually extend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
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 "base/md5.h" 7 #include "base/md5.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 if (recursive) { 104 if (recursive) {
105 for (WebFrame* child = frame->firstChild(); child; 105 for (WebFrame* child = frame->firstChild(); child;
106 child = child->nextSibling()) { 106 child = child->nextSibling()) {
107 result.append(DumpFrameScrollPosition(child, recursive)); 107 result.append(DumpFrameScrollPosition(child, recursive));
108 } 108 }
109 } 109 }
110 return result; 110 return result;
111 } 111 }
112 112
113 bool PaintViewIntoCanvas(WebView* view, skia::PlatformCanvas& canvas) { 113 SkCanvas* PaintViewIntoCanvas(WebView* view) {
114 view->layout(); 114 view->layout();
115 const WebSize& size = view->size(); 115 const WebSize& size = view->size();
116 116
117 if (!canvas.initialize(size.width, size.height, true)) 117 SkCanvas* canvas = skia::CreatePlatformCanvas(size.width, size.height, true,
118 return false; 118 0, skia::RETURN_NULL_ON_FAILURE);
119 119 if (canvas) {
120 view->paint(webkit_glue::ToWebCanvas(&canvas), 120 view->paint(webkit_glue::ToWebCanvas(canvas),
121 WebRect(0, 0, size.width, size.height)); 121 WebRect(0, 0, size.width, size.height));
122 return true; 122 }
123 return canvas;
123 } 124 }
124 125
125 #if !defined(OS_MACOSX) 126 #if !defined(OS_MACOSX)
126 void MakeBitmapOpaque(SkBitmap* bitmap) { 127 void MakeBitmapOpaque(SkBitmap* bitmap) {
127 SkAutoLockPixels lock(*bitmap); 128 SkAutoLockPixels lock(*bitmap);
128 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); 129 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config);
129 for (int y = 0; y < bitmap->height(); ++y) { 130 for (int y = 0; y < bitmap->height(); ++y) {
130 uint32_t* row = bitmap->getAddr32(0, y); 131 uint32_t* row = bitmap->getAddr32(0, y);
131 for (int x = 0; x < bitmap->width(); ++x) 132 for (int x = 0; x < bitmap->width(); ++x)
132 row[x] |= 0xFF000000; // Set alpha bits to 1. 133 row[x] |= 0xFF000000; // Set alpha bits to 1.
133 } 134 }
134 } 135 }
135 #endif 136 #endif
136 137
137 void CaptureSnapshot(WebView* view, SkBitmap* snapshot) { 138 void CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
138 skia::PlatformCanvas canvas; 139 SkCanvas* canvas = PaintViewIntoCanvas(view);
139 if (!PaintViewIntoCanvas(view, canvas)) 140 if (!canvas)
140 return; 141 return;
141 142
142 SkDevice* device = skia::GetTopDevice(canvas); 143 SkDevice* device = skia::GetTopDevice(*canvas);
143 144
144 const SkBitmap& bitmap = device->accessBitmap(false); 145 const SkBitmap& bitmap = device->accessBitmap(false);
145 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config); 146 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config);
146 147
147 #if !defined(OS_MACOSX) 148 #if !defined(OS_MACOSX)
148 // Only the expected PNGs for Mac have a valid alpha channel. 149 // Only the expected PNGs for Mac have a valid alpha channel.
149 MakeBitmapOpaque(snapshot); 150 MakeBitmapOpaque(snapshot);
150 #endif 151 #endif
151 152
152 } 153 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 Send(new ShellViewHostMsg_ImageDump( 316 Send(new ShellViewHostMsg_ImageDump(
316 routing_id(), actual_pixel_hash, snapshot)); 317 routing_id(), actual_pixel_hash, snapshot));
317 } 318 }
318 319
319 void WebKitTestRunner::OnSetIsMainWindow() { 320 void WebKitTestRunner::OnSetIsMainWindow() {
320 is_main_window_ = true; 321 is_main_window_ = true;
321 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view(), this); 322 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view(), this);
322 } 323 }
323 324
324 } // namespace content 325 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698