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" |
5 #include "printing/metafile_skia_wrapper.h" | 6 #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"; |
15 const char* kMetafileKey = "CrMetafile"; | 16 const char* kMetafileKey = "CrMetafile"; |
16 | 17 |
| 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 |
17 } // namespace | 26 } // namespace |
18 | 27 |
19 // static | 28 // static |
20 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, | 29 void MetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas, |
21 Metafile* metafile) { | 30 Metafile* metafile) { |
22 MetafileSkiaWrapper* wrapper = NULL; | 31 MetafileSkiaWrapper* wrapper = NULL; |
23 if (metafile) | 32 if (metafile) |
24 wrapper = new MetafileSkiaWrapper(metafile); | 33 wrapper = new MetafileSkiaWrapper(metafile); |
25 | 34 |
26 SkMetaData& meta = skia::getMetaData(canvas); | 35 SkMetaData& meta = getMetaData(canvas); |
27 meta.setRefCnt(kMetafileKey, wrapper); | 36 meta.setRefCnt(kMetafileKey, wrapper); |
28 SkSafeUnref(wrapper); | 37 SkSafeUnref(wrapper); |
29 } | 38 } |
30 | 39 |
31 // static | 40 // static |
32 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { | 41 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(SkCanvas* canvas) { |
33 SkMetaData& meta = skia::getMetaData(canvas); | 42 SkMetaData& meta = getMetaData(canvas); |
34 SkRefCnt* value; | 43 SkRefCnt* value; |
35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) | 44 if (!meta.findRefCnt(kMetafileKey, &value) || !value) |
36 return NULL; | 45 return NULL; |
37 | 46 |
38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; | 47 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; |
39 } | 48 } |
40 | 49 |
| 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 |
41 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) | 65 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) |
42 : metafile_(metafile) { | 66 : metafile_(metafile) { |
43 } | 67 } |
44 | 68 |
45 } // namespace printing | 69 } // namespace printing |
OLD | NEW |