diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 17:51:02 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 17:51:02 +0000 |
commit | 8649fb3771f7d6227e5fea231050c7da63fb0e08 (patch) | |
tree | 740947d3576a2227c4420d313435dbd5c1e40a51 | |
parent | c3546c5dd8cfba47dac4026e024d59ed9bbcdd0c (diff) | |
download | chromium_src-8649fb3771f7d6227e5fea231050c7da63fb0e08.zip chromium_src-8649fb3771f7d6227e5fea231050c7da63fb0e08.tar.gz chromium_src-8649fb3771f7d6227e5fea231050c7da63fb0e08.tar.bz2 |
Remove WebFrame::CaptureImage in favor of having consumers call Layout
and Paint manually on the WebView.
BUG=10034
TEST=none
R=brettw
Review URL: http://codereview.chromium.org/147212
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19379 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/render_view.cc | 22 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 15 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 35 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 36 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 2 |
7 files changed, 40 insertions, 74 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index a164d10..051b8d6 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -107,6 +107,7 @@ using WebKit::WebHistoryItem; using WebKit::WebNavigationType; using WebKit::WebRect; using WebKit::WebScriptSource; +using WebKit::WebSize; using WebKit::WebString; using WebKit::WebURL; using WebKit::WebURLError; @@ -432,7 +433,7 @@ void RenderView::SendThumbnail() { ThumbnailScore score; SkBitmap thumbnail; - if (!CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight, + if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, &thumbnail, &score)) return; @@ -538,7 +539,7 @@ void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { } } -bool RenderView::CaptureThumbnail(WebFrame* frame, +bool RenderView::CaptureThumbnail(WebView* view, int w, int h, SkBitmap* thumbnail, @@ -547,11 +548,18 @@ bool RenderView::CaptureThumbnail(WebFrame* frame, double begin = time_util::GetHighResolutionTimeNow(); #endif - scoped_ptr<skia::BitmapPlatformDevice> device; - if (!frame->CaptureImage(&device, true)) + view->Layout(); + const WebSize& size = view->GetSize(); + + skia::PlatformCanvas canvas; + if (!canvas.initialize(size.width, size.height, true)) return false; + view->Paint(&canvas, WebRect(0, 0, size.width, size.height)); + + skia::BitmapPlatformDevice& device = + static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); - const SkBitmap& src_bmp = device->accessBitmap(false); + const SkBitmap& src_bmp = device.accessBitmap(false); SkRect dest_rect; dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); @@ -584,10 +592,10 @@ bool RenderView::CaptureThumbnail(WebFrame* frame, } } - score->at_top = (frame->ScrollOffset().height == 0); + score->at_top = (view->GetMainFrame()->ScrollOffset().height == 0); SkBitmap subset; - device->accessBitmap(false).extractSubset(&subset, src_rect); + device.accessBitmap(false).extractSubset(&subset, src_rect); // Resample the subset that we want to get it the right size. *thumbnail = skia::ImageOperations::Resize( diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 8a65ebb..07cbc02 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -430,7 +430,7 @@ class RenderView : public RenderWidget, // Creates a thumbnail of |frame|'s contents resized to (|w|, |h|) // and puts that in |thumbnail|. Thumbnail metadata goes in |score|. - bool CaptureThumbnail(WebFrame* frame, int w, int h, + bool CaptureThumbnail(WebView* view, int w, int h, SkBitmap* thumbnail, ThumbnailScore* score); diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 48d64fe..2a7f524 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -331,21 +331,6 @@ class WebFrame { // Returns the full HTML of the page. virtual std::string GetFullPageHtml() = 0; - // Paints the contents of this web view in a bitmapped image. This image - // will not have plugins drawn. Devices are cheap to copy because the data is - // internally refcounted so we allocate and return a new copy - // - // Set scroll_to_zero to force all frames to be scrolled to 0,0 before - // being painted into the image. This will not send DOM events because it - // just draws the contents at a different place, but it does mean the - // scrollbars in the resulting image will appear to be wrong (they'll be - // painted as if the content was scrolled). - // - // Returns false on failure. CaptureImage can fail if 'image' argument - // is not valid or due to failure to allocate a canvas. - virtual bool CaptureImage(scoped_ptr<skia::BitmapPlatformDevice>* image, - bool scroll_to_zero) = 0; - // This function sets a flag within WebKit to instruct it to render the page // as View-Source (showing the HTML source for the page). virtual void SetInViewSourceMode(bool enable) = 0; diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 2763334..7a8f190 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -1538,41 +1538,6 @@ void WebFrameImpl::Paint(skia::PlatformCanvas* canvas, const WebRect& rect) { } } -bool WebFrameImpl::CaptureImage(scoped_ptr<skia::BitmapPlatformDevice>* image, - bool scroll_to_zero) { - if (!image) { - NOTREACHED(); - return false; - } - - // Must layout before painting. - Layout(); - - skia::PlatformCanvas canvas; - if (!canvas.initialize(frameview()->width(), frameview()->height(), true)) - return false; - -#if defined(OS_WIN) || defined(OS_LINUX) - PlatformContextSkia context(&canvas); - GraphicsContext gc(reinterpret_cast<PlatformGraphicsContext*>(&context)); -#elif defined(OS_MACOSX) - CGContextRef context = canvas.beginPlatformPaint(); - GraphicsContext gc(context); - WebCore::LocalCurrentGraphicsContext localContext(&gc); -#endif - frameview()->paint(&gc, IntRect(0, 0, frameview()->width(), - frameview()->height())); -#if defined(OS_MACOSX) - canvas.endPlatformPaint(); -#endif - - skia::BitmapPlatformDevice& device = - static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); - - image->reset(new skia::BitmapPlatformDevice(device)); - return true; -} - bool WebFrameImpl::IsLoading() { // I'm assuming this does what we want. return frame_->loader()->isLoading(); diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 56c578c..9a344c0c 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -109,8 +109,6 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual WebView* GetView() const; virtual void GetForms(std::vector<WebKit::WebForm>* forms) const; virtual std::string GetSecurityOrigin() const; - virtual bool CaptureImage(scoped_ptr<skia::BitmapPlatformDevice>* image, - bool scroll_to_zero); // This method calls createRuntimeObject (in KJS::Bindings::Instance), which // increments the refcount of the NPObject passed in. diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index e18c2b6..caa450d 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -32,6 +32,8 @@ #include "skia/ext/bitmap_platform_device.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/api/public/WebRect.h" +#include "webkit/api/public/WebSize.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLRequest.h" @@ -46,6 +48,8 @@ #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell_switches.h" +using WebKit::WebRect; +using WebKit::WebSize; using WebKit::WebURLRequest; namespace { @@ -184,8 +188,8 @@ void TestShell::Dump(TestShell* shell) { printf("#URL:%s\n", params->test_url.c_str()); // Dump the requested representation. - WebFrame* webFrame = shell->webView()->GetMainFrame(); - if (webFrame) { + WebFrame* frame = shell->webView()->GetMainFrame(); + if (frame) { bool should_dump_as_text = shell->layout_test_controller_->ShouldDumpAsText(); bool dumped_anything = false; @@ -196,26 +200,26 @@ void TestShell::Dump(TestShell* shell) { if (!should_dump_as_text) { // Plain text pages should be dumped as text const string16& mime_type = - webFrame->GetDataSource()->response().mimeType(); + frame->GetDataSource()->response().mimeType(); should_dump_as_text = EqualsASCII(mime_type, "text/plain"); } if (should_dump_as_text) { bool recursive = shell->layout_test_controller_-> ShouldDumpChildFramesAsText(); std::string data_utf8 = WideToUTF8( - webkit_glue::DumpFramesAsText(webFrame, recursive)); + webkit_glue::DumpFramesAsText(frame, recursive)); if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) != data_utf8.size()) { LOG(FATAL) << "Short write to stdout, disk full?"; } } else { printf("%s", WideToUTF8( - webkit_glue::DumpRenderer(webFrame)).c_str()); + webkit_glue::DumpRenderer(frame)).c_str()); bool recursive = shell->layout_test_controller_-> ShouldDumpChildFrameScrollPositions(); printf("%s", WideToUTF8( - webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).c_str()); + webkit_glue::DumpFrameScrollPosition(frame, recursive)).c_str()); } if (shell->layout_test_controller_->ShouldDumpBackForwardList()) { @@ -230,7 +234,7 @@ void TestShell::Dump(TestShell* shell) { // command line (for the dump pixels argument), and the MD5 sum to // stdout. dumped_anything = true; - std::string md5sum = DumpImage(webFrame, params->pixel_file_name, + std::string md5sum = DumpImage(shell->webView(), params->pixel_file_name, params->pixel_hash); printf("#MD5:%s\n", md5sum.c_str()); } @@ -241,13 +245,19 @@ void TestShell::Dump(TestShell* shell) { } // static -std::string TestShell::DumpImage(WebFrame* web_frame, +std::string TestShell::DumpImage(WebView* view, const std::wstring& file_name, const std::string& pixel_hash) { - scoped_ptr<skia::BitmapPlatformDevice> device; - if (!web_frame->CaptureImage(&device, true)) + view->Layout(); + const WebSize& size = view->GetSize(); + + skia::PlatformCanvas canvas; + if (!canvas.initialize(size.width, size.height, true)) return std::string(); + view->Paint(&canvas, WebRect(0, 0, size.width, size.height)); - const SkBitmap& src_bmp = device->accessBitmap(false); + skia::BitmapPlatformDevice& device = + static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); + const SkBitmap& src_bmp = device.accessBitmap(false); // Encode image. std::vector<unsigned char> png; @@ -261,7 +271,7 @@ std::string TestShell::DumpImage(WebFrame* web_frame, // doesn't have the wrong alpha like Windows, but we ignore it anyway. #if defined(OS_WIN) bool discard_transparency = true; - device->makeOpaque(0, 0, src_bmp.width(), src_bmp.height()); + device.makeOpaque(0, 0, src_bmp.width(), src_bmp.height()); #elif defined(OS_LINUX) bool discard_transparency = true; #elif defined(OS_MACOSX) @@ -269,7 +279,7 @@ std::string TestShell::DumpImage(WebFrame* web_frame, #endif // Compute MD5 sum. We should have done this before calling - // device->makeOpaque on Windows. Because we do it after the call, there are + // device.makeOpaque on Windows. Because we do it after the call, there are // some images that are the pixel identical on windows and other platforms // but have different MD5 sums. At this point, rebaselining all the windows // tests is too much of a pain, so we just check in different baselines. diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 1de2a9f..5b20e9d 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -209,7 +209,7 @@ public: // Writes the image captured from the given web frame to the given file. // The returned string is the ASCII-ized MD5 sum of the image. - static std::string DumpImage(WebFrame* web_frame, + static std::string DumpImage(WebView* view, const std::wstring& file_name, const std::string& pixel_hash); |