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