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

Unified Diff: printing/native_metafile_skia_wrapper.cc

Issue 6733036: Make PluginInstance::PrintPDFOutput-metafile implementation agnostic on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: printing/native_metafile_skia_wrapper.cc
diff --git a/printing/native_metafile_skia_wrapper.cc b/printing/native_metafile_skia_wrapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..03d6e132821269fc65bed23141258840440dd501
--- /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 {
+
+SkRefDict& getRefDict(SkCanvas* canvas) {
+ DCHECK(canvas != NULL);
+
+ SkDevice* device = canvas->getDevice();
+ DCHECK(device != NULL);
+ return device->getRefDict();
+}
+
+} // namespace
+
+// static
+const char* NativeMetafileSkiaWrapper::kNativeMetafileKey = "CrNativeMetafile";
+
+// static
+void NativeMetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas,
+ NativeMetafile* metafile) {
+ NativeMetafileSkiaWrapper* wrapper = NULL;
+ if (metafile)
Lei Zhang 2011/03/24 21:28:27 What happens if |metafile| is NULL? Do we need thi
vandebo (ex-Chrome) 2011/03/24 21:44:45 There's no reason to store an entry in the SkRefDi
+ wrapper = new NativeMetafileSkiaWrapper(metafile);
+
+ SkRefDict& dict = getRefDict(canvas);
+ dict.set(kNativeMetafileKey, wrapper);
+ wrapper->unref();
+}
+
+// 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

Powered by Google App Engine
This is Rietveld 408576698