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