diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 06:21:43 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 06:21:43 +0000 |
commit | 5209d8e2e3fc95777a988503018781bd0c6f9ec2 (patch) | |
tree | 995ea052b0f6dfda09266b6a022d909b3404cb38 | |
parent | d03154499968cd317de9fc722ed2b39563bf3265 (diff) | |
download | chromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.zip chromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.tar.gz chromium_src-5209d8e2e3fc95777a988503018781bd0c6f9ec2.tar.bz2 |
Revert 78859 - Unfork VectorPlatformCanvas.
Unfork VectorPlatformCanvas by making NativeMetafile know how to create an appropriate VectorPlatformDevice. This will also be useful when we have multiple NativeMetafile implemenations (each requiring a different VectorPlatformDevices).
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78662
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78663
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78812
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78815
Review URL: http://codereview.chromium.org/6665046
TBR=vandebo@chromium.org
Review URL: http://codereview.chromium.org/6711067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78860 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 11 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 57 | ||||
-rw-r--r-- | printing/emf_win.cc | 14 | ||||
-rw-r--r-- | printing/emf_win.h | 3 | ||||
-rw-r--r-- | printing/native_metafile.h | 11 | ||||
-rw-r--r-- | printing/pdf_metafile_mac.cc | 7 | ||||
-rw-r--r-- | printing/pdf_metafile_mac.h | 4 | ||||
-rw-r--r-- | printing/pdf_ps_metafile_cairo.cc | 12 | ||||
-rw-r--r-- | printing/pdf_ps_metafile_cairo.h | 3 | ||||
-rw-r--r-- | skia/ext/vector_canvas.cc | 10 | ||||
-rw-r--r-- | skia/ext/vector_canvas.h | 25 | ||||
-rw-r--r-- | skia/ext/vector_canvas_linux.cc | 28 | ||||
-rw-r--r-- | skia/ext/vector_canvas_unittest.cc | 7 | ||||
-rw-r--r-- | skia/ext/vector_canvas_win.cc | 30 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_linux.cc | 6 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_linux.h | 4 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_win.cc | 5 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_win.h | 6 | ||||
-rw-r--r-- | skia/skia.gyp | 2 |
19 files changed, 153 insertions, 92 deletions
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index 555f419..970b47c 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -220,14 +220,15 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, margin_left_in_points, content_height_in_points + margin_top_in_points + margin_bottom_in_points); - gfx::Point content_origin(margin_left_in_points, margin_top_in_points); - skia::PlatformDevice* device = metafile->StartPageForVectorCanvas( - page_size, content_origin, 1.0f); - if (!device) + gfx::Point content_origin(margin_top_in_points, margin_left_in_points); + + if (!metafile->StartPage(page_size, content_origin, 1)) return; - canvas->reset(new skia::VectorCanvas(device)); + canvas->reset(new skia::VectorCanvas(metafile->context(), + canvas_size.width(), + canvas_size.height())); frame->printPage(params.page_number, canvas->get()); // TODO(myhuang): We should handle transformation for paper margins. diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 2e87939..d4b37db 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -197,7 +197,8 @@ void PrintWebViewHelper::CreatePreviewDocument( void PrintWebViewHelper::RenderPage( const ViewMsg_Print_Params& params, float* scale_factor, int page_number, WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) { - DCHECK(metafile->get()->context()); + HDC hdc = (*metafile)->context(); + DCHECK(hdc); double content_width_in_points; double content_height_in_points; @@ -215,14 +216,49 @@ void PrintWebViewHelper::RenderPage( int width = static_cast<int>(content_width_in_points * params.max_shrink); int height = static_cast<int>(content_height_in_points * params.max_shrink); - gfx::Size page_size(width, height); - gfx::Point content_origin(static_cast<int>(margin_left_in_points), - static_cast<int>(margin_top_in_points)); - skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( - page_size, content_origin, 1.0f); - DCHECK(device); - skia::VectorCanvas canvas(device); + bool result = (*metafile)->StartPage( + gfx::Size(width, height), + gfx::Point(static_cast<int>(margin_top_in_points), + static_cast<int>(margin_left_in_points)), + *scale_factor); + DCHECK(result); + +#if 0 + // TODO(maruel): This code is kept for testing until the 100% GDI drawing + // code is stable. maruels use this code's output as a reference when the + // GDI drawing code fails. + + // Mix of Skia and GDI based. + skia::PlatformCanvas canvas(width, height, true); + canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); + float webkit_scale_factor = frame->printPage(page_number, &canvas); + if (*scale_factor <= 0 || webkit_scale_factor <= 0) { + NOTREACHED() << "Printing page " << page_number << " failed."; + } else { + // Update the dpi adjustment with the "page |scale_factor|" calculated in + // webkit. + *scale_factor /= webkit_scale_factor; + } + // Create a BMP v4 header that we can serialize. + BITMAPV4HEADER bitmap_header; + gfx::CreateBitmapV4Header(width, height, &bitmap_header); + const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true); + SkAutoLockPixels src_lock(src_bmp); + int retval = StretchDIBits(hdc, + 0, + 0, + width, height, + 0, 0, + width, height, + src_bmp.getPixels(), + reinterpret_cast<BITMAPINFO*>(&bitmap_header), + DIB_RGB_COLORS, + SRCCOPY); + DCHECK(retval != GDI_ERROR); +#else + // 100% GDI based. + skia::VectorCanvas canvas(hdc, width, height); float webkit_scale_factor = frame->printPage(page_number, &canvas); if (*scale_factor <= 0 || webkit_scale_factor <= 0) { NOTREACHED() << "Printing page " << page_number << " failed."; @@ -231,12 +267,13 @@ void PrintWebViewHelper::RenderPage( // webkit. *scale_factor /= webkit_scale_factor; } +#endif - bool result = (*metafile)->FinishPage(); + result = (*metafile)->FinishPage(); DCHECK(result); skia::VectorPlatformDevice* platform_device = - static_cast<skia::VectorPlatformDevice*>(device); + static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { // Close the device context to retrieve the compiled metafile. if (!(*metafile)->FinishDocument()) diff --git a/printing/emf_win.cc b/printing/emf_win.cc index 8609c34..de652f1 100644 --- a/printing/emf_win.cc +++ b/printing/emf_win.cc @@ -9,7 +9,6 @@ #include "base/metrics/histogram.h" #include "base/scoped_ptr.h" #include "base/time.h" -#include "skia/ext/vector_platform_device_win.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/codec/png_codec.h" @@ -413,21 +412,10 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const { return res; } -skia::PlatformDevice* Emf::StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor) { - if (!StartPage(page_size, content_origin, scale_factor)) - return NULL; - - return skia::VectorPlatformDeviceFactory::CreateDevice(page_size.width(), - page_size.height(), - true, hdc_); -} - bool Emf::StartPage(const gfx::Size& /*page_size*/, const gfx::Point& /*content_origin*/, const float& scale_factor) { - DCHECK_EQ(1.0f, scale_factor); // We don't support scaling here. + DCHECK_EQ(scale_factor, 1); DCHECK(hdc_); if (!hdc_) return false; diff --git a/printing/emf_win.h b/printing/emf_win.h index f2ccffd..e3a0a8e 100644 --- a/printing/emf_win.h +++ b/printing/emf_win.h @@ -35,9 +35,6 @@ class Emf : public NativeMetafile { virtual bool Init() { return true; } virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - virtual skia::PlatformDevice* StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor); // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls // (since StartPage and EndPage do not work in a metafile DC). Only valid // when hdc_ is non-NULL. |page_size| and |content_origin| are ignored. diff --git a/printing/native_metafile.h b/printing/native_metafile.h index 742ee27..ef1e546 100644 --- a/printing/native_metafile.h +++ b/printing/native_metafile.h @@ -26,10 +26,6 @@ class Rect; class Size; } -namespace skia { -class PlatformDevice; -} - #if defined(OS_CHROMEOS) namespace base { class FileDescriptor; @@ -54,13 +50,6 @@ class NativeMetafile { // Note: It should only be called from within the browser process. virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size) = 0; - // This method calls StartPage and then returns an appropriate - // VectorPlatformDevice implementation bound to the context created by - // StartPage or NULL on error. - virtual skia::PlatformDevice* StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor) = 0; - // Prepares a context for rendering a new page at the specified // |content_origin| with the given |page_size| and a |scale_factor| to use for // the drawing. The units are in points (=1/72 in). Returns true on success. diff --git a/printing/pdf_metafile_mac.cc b/printing/pdf_metafile_mac.cc index 913f6aa..f5a36f8 100644 --- a/printing/pdf_metafile_mac.cc +++ b/printing/pdf_metafile_mac.cc @@ -62,13 +62,6 @@ bool PdfMetafile::InitFromData(const void* src_buffer, uint32 src_buffer_size) { return true; } -skia::PlatformDevice* PdfMetafile::StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor) { - NOTIMPLEMENTED(); - return NULL; -} - bool PdfMetafile::StartPage(const gfx::Size& page_size, const gfx::Point& content_origin, const float& scale_factor) { diff --git a/printing/pdf_metafile_mac.h b/printing/pdf_metafile_mac.h index 496b275..c5a2a4a 100644 --- a/printing/pdf_metafile_mac.h +++ b/printing/pdf_metafile_mac.h @@ -33,10 +33,6 @@ class PdfMetafile : public NativeMetafile { virtual bool Init(); virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - // Not implemented on mac. - virtual skia::PlatformDevice* StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor); virtual bool StartPage(const gfx::Size& page_size, const gfx::Point& content_origin, const float& scale_factor); diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc index 4a8a1ff..6c42bd4 100644 --- a/printing/pdf_ps_metafile_cairo.cc +++ b/printing/pdf_ps_metafile_cairo.cc @@ -145,18 +145,6 @@ bool PdfPsMetafile::SetRawData(const void* src_buffer, return true; } -skia::PlatformDevice* PdfPsMetafile::StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor) { - if (!StartPage(page_size, content_origin, scale_factor)) - return NULL; - - return skia::VectorPlatformDeviceFactory::CreateDevice(context_, - page_size.width(), - page_size.height(), - true); -} - bool PdfPsMetafile::StartPage(const gfx::Size& page_size, const gfx::Point& content_origin, const float& scale_factor) { diff --git a/printing/pdf_ps_metafile_cairo.h b/printing/pdf_ps_metafile_cairo.h index 3e1e811..5ff59db 100644 --- a/printing/pdf_ps_metafile_cairo.h +++ b/printing/pdf_ps_metafile_cairo.h @@ -31,9 +31,6 @@ class PdfPsMetafile : public NativeMetafile { virtual bool Init(); virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - virtual skia::PlatformDevice* StartPageForVectorCanvas( - const gfx::Size& page_size, const gfx::Point& content_origin, - const float& scale_factor); virtual bool StartPage(const gfx::Size& page_size, const gfx::Point& content_origin, const float& scale_factor); diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc index 216a2ee..851da79 100644 --- a/skia/ext/vector_canvas.cc +++ b/skia/ext/vector_canvas.cc @@ -4,13 +4,13 @@ #include "skia/ext/vector_canvas.h" -#include "skia/ext/vector_platform_device.h" - namespace skia { -VectorCanvas::VectorCanvas(PlatformDevice* device) - : PlatformCanvas(device->getDeviceFactory()) { - setDevice(device)->unref(); // Created with refcount 1, and setDevice refs. +VectorCanvas::VectorCanvas() + : PlatformCanvas(SkNEW(VectorPlatformDeviceFactory)) { +} + +VectorCanvas::VectorCanvas(SkDeviceFactory* factory) : PlatformCanvas(factory) { } VectorCanvas::~VectorCanvas() { diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h index 4b4419d..4f8bc7a 100644 --- a/skia/ext/vector_canvas.h +++ b/skia/ext/vector_canvas.h @@ -7,10 +7,13 @@ #pragma once #include "skia/ext/platform_canvas.h" +#include "skia/ext/vector_platform_device.h" -namespace skia { +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) +typedef struct _cairo cairo_t; +#endif -class PlatformDevice; +namespace skia { // This class is a specialization of the regular PlatformCanvas. It is designed // to work with a VectorDevice to manage platform-specific drawing. It allows @@ -18,10 +21,24 @@ class PlatformDevice; // support reading back from the bitmap backstore since it is not used. class SK_API VectorCanvas : public PlatformCanvas { public: - // Ownership of |device| is transfered to VectorCanvas. - explicit VectorCanvas(PlatformDevice* device); + VectorCanvas(); + explicit VectorCanvas(SkDeviceFactory* factory); +#if defined(WIN32) + VectorCanvas(HDC dc, int width, int height); +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) + // Caller owns |context|. Ownership is not transferred. + VectorCanvas(cairo_t* context, int width, int height); +#endif virtual ~VectorCanvas(); + // For two-part init, call if you use the no-argument constructor above +#if defined(WIN32) + bool initialize(HDC context, int width, int height); +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) + // Ownership of |context| is not transferred. + bool initialize(cairo_t* context, int width, int height); +#endif + virtual SkBounder* setBounder(SkBounder* bounder); virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); diff --git a/skia/ext/vector_canvas_linux.cc b/skia/ext/vector_canvas_linux.cc new file mode 100644 index 0000000..aff4fbe --- /dev/null +++ b/skia/ext/vector_canvas_linux.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/vector_canvas.h" + +#include "skia/ext/vector_platform_device.h" + +namespace skia { + +VectorCanvas::VectorCanvas(cairo_t* context, int width, int height) { + bool initialized = initialize(context, width, height); + + SkASSERT(initialized); +} + +bool VectorCanvas::initialize(cairo_t* context, int width, int height) { + SkDevice* device = VectorPlatformDeviceFactory::CreateDevice(context, width, + height, true); + if (!device) + return false; + + setDevice(device); + device->unref(); // was created with refcount 1, and setDevice also refs + return true; +} + +} // namespace skia diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc index 1066c0c..0266c81 100644 --- a/skia/ext/vector_canvas_unittest.cc +++ b/skia/ext/vector_canvas_unittest.cc @@ -14,7 +14,6 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "skia/ext/vector_canvas.h" -#include "skia/ext/vector_platform_device.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/effects/SkDashPathEffect.h" #include "ui/gfx/codec/png_codec.h" @@ -387,8 +386,7 @@ class VectorCanvasTest : public ImageTest { size_ = size; context_ = new Context(); bitmap_ = new Bitmap(*context_, size_, size_); - vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice( - size_, size_, true, context_->context())); + vcanvas_ = new VectorCanvas(context_->context(), size_, size_); pcanvas_ = new PlatformCanvas(size_, size_, false); // Clear white. @@ -454,8 +452,7 @@ TEST_F(VectorCanvasTest, Uninitialized) { context_ = new Context(); bitmap_ = new Bitmap(*context_, size_, size_); - vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice( - size_, size_, true, context_->context())); + vcanvas_ = new VectorCanvas(context_->context(), size_, size_); pcanvas_ = new PlatformCanvas(size_, size_, false); // VectorCanvas default initialization is black. diff --git a/skia/ext/vector_canvas_win.cc b/skia/ext/vector_canvas_win.cc new file mode 100644 index 0000000..400b2a4 --- /dev/null +++ b/skia/ext/vector_canvas_win.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/vector_canvas.h" + +#include "skia/ext/bitmap_platform_device.h" +#include "skia/ext/vector_platform_device.h" + +namespace skia { + +VectorCanvas::VectorCanvas(HDC dc, int width, int height) { + bool initialized = initialize(dc, width, height); + if (!initialized) + __debugbreak(); +} + +bool VectorCanvas::initialize(HDC context, int width, int height) { + SkDevice* device = VectorPlatformDeviceFactory::CreateDevice(width, height, + true, context); + if (!device) + return false; + + setDevice(device); + device->unref(); // was created with refcount 1, and setDevice also refs + return true; +} + +} // namespace skia + diff --git a/skia/ext/vector_platform_device_linux.cc b/skia/ext/vector_platform_device_linux.cc index bc6a41e..068ae89 100644 --- a/skia/ext/vector_platform_device_linux.cc +++ b/skia/ext/vector_platform_device_linux.cc @@ -78,9 +78,9 @@ SkDevice* VectorPlatformDeviceFactory::newDevice(SkCanvas* ignored, } // static -PlatformDevice* VectorPlatformDeviceFactory::CreateDevice(cairo_t* context, - int width, int height, - bool isOpaque) { +SkDevice* VectorPlatformDeviceFactory::CreateDevice(cairo_t* context, + int width, int height, + bool isOpaque) { // TODO(myhuang): Here we might also have similar issues as those on Windows // (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383). // Please note that is_opaque is true when we use this class for printing. diff --git a/skia/ext/vector_platform_device_linux.h b/skia/ext/vector_platform_device_linux.h index ae2bafb..222f68f 100644 --- a/skia/ext/vector_platform_device_linux.h +++ b/skia/ext/vector_platform_device_linux.h @@ -15,8 +15,8 @@ namespace skia { class VectorPlatformDeviceFactory : public SkDeviceFactory { public: - static PlatformDevice* CreateDevice(cairo_t* context, int width, int height, - bool isOpaque); + static SkDevice* CreateDevice(cairo_t* context, int width, int height, + bool isOpaque); // Overridden from SkDeviceFactory: virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config, diff --git a/skia/ext/vector_platform_device_win.cc b/skia/ext/vector_platform_device_win.cc index 90f824e..2476152 100644 --- a/skia/ext/vector_platform_device_win.cc +++ b/skia/ext/vector_platform_device_win.cc @@ -22,8 +22,9 @@ SkDevice* VectorPlatformDeviceFactory::newDevice(SkCanvas* unused, } //static -PlatformDevice* VectorPlatformDeviceFactory::CreateDevice( - int width, int height, bool is_opaque, HANDLE shared_section) { +SkDevice* VectorPlatformDeviceFactory::CreateDevice(int width, int height, + bool is_opaque, + HANDLE shared_section) { if (!is_opaque) { // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent // layer, i.e. merging it, we need to rasterize it because GDI doesn't diff --git a/skia/ext/vector_platform_device_win.h b/skia/ext/vector_platform_device_win.h index 83d51f7..6045f24 100644 --- a/skia/ext/vector_platform_device_win.h +++ b/skia/ext/vector_platform_device_win.h @@ -13,13 +13,13 @@ namespace skia { -class SK_API VectorPlatformDeviceFactory : public SkDeviceFactory { +class VectorPlatformDeviceFactory : public SkDeviceFactory { public: virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config, int width, int height, bool isOpaque, bool isForLayer) OVERRIDE; - static PlatformDevice* CreateDevice(int width, int height, bool isOpaque, - HANDLE shared_section); + static SkDevice* CreateDevice(int width, int height, bool isOpaque, + HANDLE shared_section); }; // A device is basically a wrapper around SkBitmap that provides a surface for diff --git a/skia/skia.gyp b/skia/skia.gyp index 628bf9b..f28ffd2 100644 --- a/skia/skia.gyp +++ b/skia/skia.gyp @@ -642,6 +642,8 @@ 'ext/skia_utils_win.h', 'ext/vector_canvas.cc', 'ext/vector_canvas.h', + 'ext/vector_canvas_linux.cc', + 'ext/vector_canvas_win.cc', 'ext/vector_platform_device.h', 'ext/vector_platform_device_linux.cc', 'ext/vector_platform_device_linux.h', |