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 "skia/ext/refptr.h" | |
8 #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" |
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 SkCanvas& canvas, |
20 PdfMetafileSkia* metafile) { | 20 PdfMetafileSkia* metafile) { |
21 skia::RefPtr<MetafileSkiaWrapper> wrapper; | 21 sk_sp<MetafileSkiaWrapper> wrapper; |
| 22 // Can't use sk_make_sp<>() because the constructor is private. |
22 if (metafile) | 23 if (metafile) |
23 wrapper = skia::AdoptRef(new MetafileSkiaWrapper(metafile)); | 24 wrapper = sk_sp<MetafileSkiaWrapper>(new MetafileSkiaWrapper(metafile)); |
24 | 25 |
25 SkMetaData& meta = skia::GetMetaData(canvas); | 26 SkMetaData& meta = skia::GetMetaData(canvas); |
26 meta.setRefCnt(kMetafileKey, wrapper.get()); | 27 meta.setRefCnt(kMetafileKey, wrapper.get()); |
27 } | 28 } |
28 | 29 |
29 // static | 30 // static |
30 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas( | 31 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas( |
31 const SkCanvas& canvas) { | 32 const SkCanvas& canvas) { |
32 SkMetaData& meta = skia::GetMetaData(canvas); | 33 SkMetaData& meta = skia::GetMetaData(canvas); |
33 SkRefCnt* value; | 34 SkRefCnt* value; |
34 if (!meta.findRefCnt(kMetafileKey, &value) || !value) | 35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) |
35 return nullptr; | 36 return nullptr; |
36 | 37 |
37 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | 38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; |
38 } | 39 } |
39 | 40 |
40 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile) | 41 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile) |
41 : metafile_(metafile) { | 42 : metafile_(metafile) { |
42 } | 43 } |
43 | 44 |
44 } // namespace printing | 45 } // namespace printing |
OLD | NEW |