| 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_canvas.h" | 6 #include "skia/ext/platform_canvas.h" |
| 7 #include "third_party/skia/include/core/SkMetaData.h" | 7 #include "third_party/skia/include/core/SkMetaData.h" |
| 8 #include "third_party/skia/include/core/SkRefCnt.h" | 8 #include "third_party/skia/include/core/SkRefCnt.h" |
| 9 | 9 |
| 10 namespace printing { | 10 namespace printing { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const char kMetafileKey[] = "CrMetafile"; | 14 const char kMetafileKey[] = "CrMetafile"; |
| 15 | 15 |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, | 19 void MetafileSkiaWrapper::SetMetafileOnCanvas(const CdlCanvas& canvas, |
| 20 PdfMetafileSkia* metafile) { | 20 PdfMetafileSkia* metafile) { |
| 21 sk_sp<MetafileSkiaWrapper> wrapper; | 21 sk_sp<MetafileSkiaWrapper> wrapper; |
| 22 // Can't use sk_make_sp<>() because the constructor is private. | 22 // Can't use sk_make_sp<>() because the constructor is private. |
| 23 if (metafile) | 23 if (metafile) |
| 24 wrapper = sk_sp<MetafileSkiaWrapper>(new MetafileSkiaWrapper(metafile)); | 24 wrapper = sk_sp<MetafileSkiaWrapper>(new MetafileSkiaWrapper(metafile)); |
| 25 | 25 |
| 26 SkMetaData& meta = skia::GetMetaData(canvas); | 26 SkMetaData& meta = skia::GetMetaData(canvas); |
| 27 meta.setRefCnt(kMetafileKey, wrapper.get()); | 27 meta.setRefCnt(kMetafileKey, wrapper.get()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas( | 31 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas( |
| 32 const SkCanvas& canvas) { | 32 const CdlCanvas& canvas) { |
| 33 SkMetaData& meta = skia::GetMetaData(canvas); | 33 SkMetaData& meta = skia::GetMetaData(canvas); |
| 34 SkRefCnt* value; | 34 SkRefCnt* value; |
| 35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) | 35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) |
| 36 return nullptr; | 36 return nullptr; |
| 37 | 37 |
| 38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | 38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile) | 41 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile) |
| 42 : metafile_(metafile) { | 42 : metafile_(metafile) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace printing | 45 } // namespace printing |
| OLD | NEW |