| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "printing/metafile_skia_wrapper.h" | 5 #include "printing/metafile_skia_wrapper.h" |
| 6 #include "skia/ext/platform_device.h" | 6 #include "skia/ext/platform_device.h" |
| 7 #include "skia/ext/refptr.h" |
| 7 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 8 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
| 9 #include "third_party/skia/include/core/SkMetaData.h" | 10 #include "third_party/skia/include/core/SkMetaData.h" |
| 10 | 11 |
| 11 namespace printing { | 12 namespace printing { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 const char* kMetafileKey = "CrMetafile"; | 16 const char* kMetafileKey = "CrMetafile"; |
| 16 const char* kCustomScaleKey = "CrCustomScale"; | 17 const char* kCustomScaleKey = "CrCustomScale"; |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, | 22 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, |
| 22 Metafile* metafile) { | 23 Metafile* metafile) { |
| 23 MetafileSkiaWrapper* wrapper = NULL; | 24 skia::RefPtr<MetafileSkiaWrapper> wrapper; |
| 24 if (metafile) | 25 if (metafile) |
| 25 wrapper = new MetafileSkiaWrapper(metafile); | 26 wrapper = new MetafileSkiaWrapper(metafile); |
| 26 | 27 |
| 27 SkMetaData& meta = skia::getMetaData(canvas); | 28 SkMetaData& meta = skia::getMetaData(canvas); |
| 28 meta.setRefCnt(kMetafileKey, wrapper); | 29 meta.setRefCnt(kMetafileKey, wrapper.get()); |
| 29 SkSafeUnref(wrapper); | |
| 30 } | 30 } |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { | 33 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { |
| 34 SkMetaData& meta = skia::getMetaData(canvas); | 34 SkMetaData& meta = skia::getMetaData(canvas); |
| 35 SkRefCnt* value; | 35 SkRefCnt* value; |
| 36 if (!meta.findRefCnt(kMetafileKey, &value) || !value) | 36 if (!meta.findRefCnt(kMetafileKey, &value) || !value) |
| 37 return NULL; | 37 return NULL; |
| 38 | 38 |
| 39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | 39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 *scale = SkScalarToFloat(value); | 57 *scale = SkScalarToFloat(value); |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) | 61 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) |
| 62 : metafile_(metafile) { | 62 : metafile_(metafile) { |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace printing | 65 } // namespace printing |
| OLD | NEW |