blob: d4634ef421c42f21b8f7574d6de2a172cc796953 [file] [log] [blame]
[email protected]f64d7a352012-05-09 17:22:211// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7d7489902011-04-11 21:54:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]7d7489902011-04-11 21:54:065#include "printing/metafile_skia_wrapper.h"
[email protected]be44f2f52011-09-28 03:07:346#include "skia/ext/platform_device.h"
[email protected]7d7489902011-04-11 21:54:067#include "third_party/skia/include/core/SkCanvas.h"
8#include "third_party/skia/include/core/SkDevice.h"
9#include "third_party/skia/include/core/SkMetaData.h"
10
11namespace printing {
12
13namespace {
14
[email protected]926ae242011-08-02 02:07:0815const char* kMetafileKey = "CrMetafile";
[email protected]f64d7a352012-05-09 17:22:2116const char* kCustomScaleKey = "CrCustomScale";
[email protected]7d7489902011-04-11 21:54:0617
[email protected]7d7489902011-04-11 21:54:0618} // namespace
19
20// static
[email protected]be44f2f52011-09-28 03:07:3421void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
[email protected]7d7489902011-04-11 21:54:0622 Metafile* metafile) {
23 MetafileSkiaWrapper* wrapper = NULL;
24 if (metafile)
25 wrapper = new MetafileSkiaWrapper(metafile);
26
[email protected]be44f2f52011-09-28 03:07:3427 SkMetaData& meta = skia::getMetaData(canvas);
[email protected]7d7489902011-04-11 21:54:0628 meta.setRefCnt(kMetafileKey, wrapper);
29 SkSafeUnref(wrapper);
30}
31
32// static
[email protected]be44f2f52011-09-28 03:07:3433Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) {
34 SkMetaData& meta = skia::getMetaData(canvas);
[email protected]7d7489902011-04-11 21:54:0635 SkRefCnt* value;
36 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
37 return NULL;
38
39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
40}
41
[email protected]f64d7a352012-05-09 17:22:2142// static
43void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas,
44 double scale) {
45 SkMetaData& meta = skia::getMetaData(canvas);
46 meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale));
47}
48
49// static
50bool MetafileSkiaWrapper::GetCustomScaleOnCanvas(const SkCanvas& canvas,
51 double* scale) {
52 SkMetaData& meta = skia::getMetaData(canvas);
53 SkScalar value;
54 if (!meta.findScalar(kCustomScaleKey, &value))
55 return false;
56
57 *scale = SkScalarToFloat(value);
58 return true;
59}
60
[email protected]7d7489902011-04-11 21:54:0661MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile)
62 : metafile_(metafile) {
63}
64
65} // namespace printing