blob: 2fddc004e12512016e478c27d9a6d936ea0c3398 [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]a1f24b72012-12-04 03:56:217#include "skia/ext/refptr.h"
[email protected]7d7489902011-04-11 21:54:068#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"
11
12namespace printing {
13
14namespace {
15
[email protected]926ae242011-08-02 02:07:0816const char* kMetafileKey = "CrMetafile";
[email protected]f64d7a352012-05-09 17:22:2117const char* kCustomScaleKey = "CrCustomScale";
[email protected]7d7489902011-04-11 21:54:0618
[email protected]7d7489902011-04-11 21:54:0619} // namespace
20
21// static
[email protected]be44f2f52011-09-28 03:07:3422void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
[email protected]7d7489902011-04-11 21:54:0623 Metafile* metafile) {
[email protected]a1f24b72012-12-04 03:56:2124 skia::RefPtr<MetafileSkiaWrapper> wrapper;
[email protected]7d7489902011-04-11 21:54:0625 if (metafile)
[email protected]a1f24b72012-12-04 03:56:2126 wrapper = skia::AdoptRef(new MetafileSkiaWrapper(metafile));
[email protected]7d7489902011-04-11 21:54:0627
[email protected]be44f2f52011-09-28 03:07:3428 SkMetaData& meta = skia::getMetaData(canvas);
[email protected]a1f24b72012-12-04 03:56:2129 meta.setRefCnt(kMetafileKey, wrapper.get());
[email protected]7d7489902011-04-11 21:54:0630}
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