OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | |
6 #include "printing/metafile_skia_wrapper.h" | 5 #include "printing/metafile_skia_wrapper.h" |
| 6 #include "skia/ext/platform_device.h" |
7 #include "third_party/skia/include/core/SkCanvas.h" | 7 #include "third_party/skia/include/core/SkCanvas.h" |
8 #include "third_party/skia/include/core/SkDevice.h" | 8 #include "third_party/skia/include/core/SkDevice.h" |
9 #include "third_party/skia/include/core/SkMetaData.h" | 9 #include "third_party/skia/include/core/SkMetaData.h" |
10 | 10 |
11 namespace printing { | 11 namespace printing { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const char* kDraftModeKey = "CrDraftMode"; | |
16 const char* kMetafileKey = "CrMetafile"; | 15 const char* kMetafileKey = "CrMetafile"; |
17 | 16 |
18 SkMetaData& getMetaData(SkCanvas* canvas) { | |
19 DCHECK(canvas != NULL); | |
20 | |
21 SkDevice* device = canvas->getDevice(); | |
22 DCHECK(device != NULL); | |
23 return device->getMetaData(); | |
24 } | |
25 | |
26 } // namespace | 17 } // namespace |
27 | 18 |
28 // static | 19 // static |
29 void MetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas, | 20 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, |
30 Metafile* metafile) { | 21 Metafile* metafile) { |
31 MetafileSkiaWrapper* wrapper = NULL; | 22 MetafileSkiaWrapper* wrapper = NULL; |
32 if (metafile) | 23 if (metafile) |
33 wrapper = new MetafileSkiaWrapper(metafile); | 24 wrapper = new MetafileSkiaWrapper(metafile); |
34 | 25 |
35 SkMetaData& meta = getMetaData(canvas); | 26 SkMetaData& meta = skia::getMetaData(canvas); |
36 meta.setRefCnt(kMetafileKey, wrapper); | 27 meta.setRefCnt(kMetafileKey, wrapper); |
37 SkSafeUnref(wrapper); | 28 SkSafeUnref(wrapper); |
38 } | 29 } |
39 | 30 |
40 // static | 31 // static |
41 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(SkCanvas* canvas) { | 32 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { |
42 SkMetaData& meta = getMetaData(canvas); | 33 SkMetaData& meta = skia::getMetaData(canvas); |
43 SkRefCnt* value; | 34 SkRefCnt* value; |
44 if (!meta.findRefCnt(kMetafileKey, &value) || !value) | 35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) |
45 return NULL; | 36 return NULL; |
46 | 37 |
47 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | 38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; |
48 } | 39 } |
49 | 40 |
50 // static | |
51 void MetafileSkiaWrapper::SetDraftMode(SkCanvas* canvas, bool draft_mode) { | |
52 SkMetaData& meta = getMetaData(canvas); | |
53 meta.setBool(kDraftModeKey, draft_mode); | |
54 } | |
55 | |
56 // static | |
57 bool MetafileSkiaWrapper::GetDraftMode(SkCanvas* canvas) { | |
58 SkMetaData& meta = getMetaData(canvas); | |
59 bool draft_mode; | |
60 if (!meta.findBool(kDraftModeKey, &draft_mode)) | |
61 draft_mode = false; | |
62 return draft_mode; | |
63 } | |
64 | |
65 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) | 41 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) |
66 : metafile_(metafile) { | 42 : metafile_(metafile) { |
67 } | 43 } |
68 | 44 |
69 } // namespace printing | 45 } // namespace printing |
OLD | NEW |