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..07c02f4dd3bad644e638d73eec29afe9fa0f7deb |
--- /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); |
+ SkSafeUnred(wrapper); |
Lei Zhang
2011/03/24 21:54:12
typo :)
vandebo (ex-Chrome)
2011/03/24 21:58:09
Done.
|
+} |
+ |
+// 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 |