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.
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"
13 const char kMetafileKey[] = "CrMetafile";
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.
23 wrapper = sk_sp<MetafileSkiaWrapper>(new MetafileSkiaWrapper(metafile));
25 SkMetaData& meta = canvas->getMetaData();
26 meta.setRefCnt(kMetafileKey, wrapper.get());
30 MetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
31 cc::PaintCanvas* canvas) {
32 SkMetaData& meta = canvas->getMetaData();
34 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
37 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
40 MetafileSkiaWrapper::MetafileSkiaWrapper(MetafileSkia* metafile)
41 : metafile_(metafile) {}
43 } // namespace printing