[email protected] | f64d7a35 | 2012-05-09 17:22:21 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 5 | #include "printing/metafile_skia_wrapper.h" |
[email protected] | be44f2f5 | 2011-09-28 03:07:34 | [diff] [blame] | 6 | #include "skia/ext/platform_device.h" |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 7 | #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 | |||||
11 | namespace printing { | ||||
12 | |||||
13 | namespace { | ||||
14 | |||||
[email protected] | 926ae24 | 2011-08-02 02:07:08 | [diff] [blame] | 15 | const char* kMetafileKey = "CrMetafile"; |
[email protected] | f64d7a35 | 2012-05-09 17:22:21 | [diff] [blame^] | 16 | const char* kCustomScaleKey = "CrCustomScale"; |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 17 | |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 18 | } // namespace |
19 | |||||
20 | // static | ||||
[email protected] | be44f2f5 | 2011-09-28 03:07:34 | [diff] [blame] | 21 | void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 22 | Metafile* metafile) { |
23 | MetafileSkiaWrapper* wrapper = NULL; | ||||
24 | if (metafile) | ||||
25 | wrapper = new MetafileSkiaWrapper(metafile); | ||||
26 | |||||
[email protected] | be44f2f5 | 2011-09-28 03:07:34 | [diff] [blame] | 27 | SkMetaData& meta = skia::getMetaData(canvas); |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 28 | meta.setRefCnt(kMetafileKey, wrapper); |
29 | SkSafeUnref(wrapper); | ||||
30 | } | ||||
31 | |||||
32 | // static | ||||
[email protected] | be44f2f5 | 2011-09-28 03:07:34 | [diff] [blame] | 33 | Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { |
34 | SkMetaData& meta = skia::getMetaData(canvas); | ||||
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 35 | SkRefCnt* value; |
36 | if (!meta.findRefCnt(kMetafileKey, &value) || !value) | ||||
37 | return NULL; | ||||
38 | |||||
39 | return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | ||||
40 | } | ||||
41 | |||||
[email protected] | f64d7a35 | 2012-05-09 17:22:21 | [diff] [blame^] | 42 | // static |
43 | void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas, | ||||
44 | double scale) { | ||||
45 | SkMetaData& meta = skia::getMetaData(canvas); | ||||
46 | meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale)); | ||||
47 | } | ||||
48 | |||||
49 | // static | ||||
50 | bool 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] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 61 | MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) |
62 | : metafile_(metafile) { | ||||
63 | } | ||||
64 | |||||
65 | } // namespace printing |