Enable V3 fetcher mode for privet v3 session.
[chromium-blink-merge.git] / printing / metafile_skia_wrapper.cc
blob3657bc12414b6972e07d571f6e699345510fce64
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 "skia/ext/platform_device.h"
7 #include "skia/ext/refptr.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "third_party/skia/include/core/SkMetaData.h"
12 namespace printing {
14 namespace {
16 const char* kMetafileKey = "CrMetafile";
17 const char* kCustomScaleKey = "CrCustomScale";
19 } // namespace
21 // static
22 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
23 PdfMetafileSkia* metafile) {
24 skia::RefPtr<MetafileSkiaWrapper> wrapper;
25 if (metafile)
26 wrapper = skia::AdoptRef(new MetafileSkiaWrapper(metafile));
28 SkMetaData& meta = skia::getMetaData(canvas);
29 meta.setRefCnt(kMetafileKey, wrapper.get());
32 // static
33 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
34 const SkCanvas& canvas) {
35 SkMetaData& meta = skia::getMetaData(canvas);
36 SkRefCnt* value;
37 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
38 return NULL;
40 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
43 // static
44 void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas,
45 double scale) {
46 SkMetaData& meta = skia::getMetaData(canvas);
47 meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale));
50 // static
51 bool MetafileSkiaWrapper::GetCustomScaleOnCanvas(const SkCanvas& canvas,
52 double* scale) {
53 SkMetaData& meta = skia::getMetaData(canvas);
54 SkScalar value;
55 if (!meta.findScalar(kCustomScaleKey, &value))
56 return false;
58 *scale = SkScalarToFloat(value);
59 return true;
62 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile)
63 : metafile_(metafile) {
66 } // namespace printing