summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
Diffstat (limited to 'printing')
-rw-r--r--printing/native_metafile_skia_wrapper.cc55
-rw-r--r--printing/native_metafile_skia_wrapper.h34
-rw-r--r--printing/pdf_ps_metafile_cairo.cc12
-rw-r--r--printing/pdf_ps_metafile_cairo.h4
-rw-r--r--printing/pdf_ps_metafile_cairo_unittest.cc1
-rw-r--r--printing/printing.gyp4
6 files changed, 93 insertions, 17 deletions
diff --git a/printing/native_metafile_skia_wrapper.cc b/printing/native_metafile_skia_wrapper.cc
new file mode 100644
index 0000000..af6f446
--- /dev/null
+++ b/printing/native_metafile_skia_wrapper.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 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 "base/logging.h"
+#include "printing/native_metafile_skia_wrapper.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkDevice.h"
+#include "third_party/skia/include/core/SkRefDict.h"
+
+namespace printing {
+
+namespace {
+
+static const char* kNativeMetafileKey = "CrNativeMetafile";
+
+SkRefDict& getRefDict(SkCanvas* canvas) {
+ DCHECK(canvas != NULL);
+
+ SkDevice* device = canvas->getDevice();
+ DCHECK(device != NULL);
+ return device->getRefDict();
+}
+
+} // namespace
+
+
+// static
+void NativeMetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas,
+ NativeMetafile* metafile) {
+ NativeMetafileSkiaWrapper* wrapper = NULL;
+ if (metafile)
+ wrapper = new NativeMetafileSkiaWrapper(metafile);
+
+ SkRefDict& dict = getRefDict(canvas);
+ dict.set(kNativeMetafileKey, wrapper);
+ SkSafeUnref(wrapper);
+}
+
+// static
+NativeMetafile* NativeMetafileSkiaWrapper::GetMetafileFromCanvas(
+ SkCanvas* canvas) {
+ SkRefDict& dict = getRefDict(canvas);
+ SkRefCnt* value = dict.find(kNativeMetafileKey);
+ if (!value)
+ return NULL;
+
+ return static_cast<NativeMetafileSkiaWrapper*>(value)->metafile_;
+}
+
+NativeMetafileSkiaWrapper::NativeMetafileSkiaWrapper(NativeMetafile* metafile)
+ : metafile_(metafile) {
+}
+
+} // namespace printing
diff --git a/printing/native_metafile_skia_wrapper.h b/printing/native_metafile_skia_wrapper.h
new file mode 100644
index 0000000..7eb2887
--- /dev/null
+++ b/printing/native_metafile_skia_wrapper.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 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.
+
+#ifndef PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_
+#define PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_
+
+#include "third_party/skia/include/core/SkRefCnt.h"
+
+class SkCanvas;
+
+namespace printing {
+
+class NativeMetafile;
+
+// A wrapper class with static methods to set and retrieve a NativeMetafile
+// on an SkCanvas. The ownership of the metafile is not affected and it
+// is the caller's responsibility to ensure that the metafile remains valid
+// as long as the canvas.
+class NativeMetafileSkiaWrapper : public SkRefCnt {
+ public:
+ static void SetMetafileOnCanvas(SkCanvas* canvas, NativeMetafile* metafile);
+
+ static NativeMetafile* GetMetafileFromCanvas(SkCanvas* canvas);
+
+ private:
+ explicit NativeMetafileSkiaWrapper(NativeMetafile* metafile);
+
+ NativeMetafile* metafile_;
+};
+
+} // namespace printing
+
+#endif // PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_
diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc
index fdbb335..a10b125 100644
--- a/printing/pdf_ps_metafile_cairo.cc
+++ b/printing/pdf_ps_metafile_cairo.cc
@@ -20,8 +20,6 @@
namespace {
-const cairo_user_data_key_t kPdfMetafileKey = {0};
-
// Tests if |surface| is valid.
bool IsSurfaceValid(cairo_surface_t* surface) {
return cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS;
@@ -63,10 +61,6 @@ cairo_status_t WriteCairoStream(void* dst_buffer,
return CAIRO_STATUS_SUCCESS;
}
-void DestroyContextData(void* data) {
- // Nothing to be done here.
-}
-
} // namespace
namespace printing {
@@ -110,7 +104,6 @@ bool PdfPsMetafile::Init() {
return false;
}
- cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData);
return true;
}
@@ -257,11 +250,6 @@ bool PdfPsMetafile::SaveToFD(const base::FileDescriptor& fd) const {
}
#endif // if defined(OS_CHROMEOS)
-PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) {
- return reinterpret_cast<PdfPsMetafile*>(
- cairo_get_user_data(context, &kPdfMetafileKey));
-}
-
void PdfPsMetafile::CleanUpAll() {
CleanUpContext(&context_);
CleanUpSurface(&surface_);
diff --git a/printing/pdf_ps_metafile_cairo.h b/printing/pdf_ps_metafile_cairo.h
index 2ae1f34..6d5cf5c 100644
--- a/printing/pdf_ps_metafile_cairo.h
+++ b/printing/pdf_ps_metafile_cairo.h
@@ -58,10 +58,6 @@ class PdfPsMetafile : public NativeMetafile {
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS)
- // Returns the PdfPsMetafile object that owns the given context. Returns NULL
- // if the context was not created by a PdfPsMetafile object.
- static PdfPsMetafile* FromCairoContext(cairo_t* context);
-
protected:
PdfPsMetafile();
diff --git a/printing/pdf_ps_metafile_cairo_unittest.cc b/printing/pdf_ps_metafile_cairo_unittest.cc
index d76d801..5b2bf2a 100644
--- a/printing/pdf_ps_metafile_cairo_unittest.cc
+++ b/printing/pdf_ps_metafile_cairo_unittest.cc
@@ -33,7 +33,6 @@ TEST_F(PdfPsTest, Pdf) {
// Renders page 1.
EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Point(4, 5), 1));
- EXPECT_EQ(printing::PdfPsMetafile::FromCairoContext(pdf.context()), &pdf);
// In theory, we should use Cairo to draw something on |context|.
EXPECT_TRUE(pdf.FinishPage());
diff --git a/printing/printing.gyp b/printing/printing.gyp
index 049e752..0e504c4 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -94,6 +94,10 @@
'sources/': [['exclude', '_posix\\.cc$']]
}],
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
+ 'sources': [
+ 'native_metafile_skia_wrapper.cc',
+ 'native_metafile_skia_wrapper.h',
+ ],
'dependencies': [
# For FT_Init_FreeType and friends.
'../build/linux/system.gyp:freetype2',