OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "printing/native_metafile_skia_wrapper.h" |
| 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/SkRefDict.h" |
| 10 |
| 11 namespace printing { |
| 12 |
| 13 namespace { |
| 14 |
| 15 static const char* kNativeMetafileKey = "CrNativeMetafile"; |
| 16 |
| 17 SkRefDict& getRefDict(SkCanvas* canvas) { |
| 18 DCHECK(canvas != NULL); |
| 19 |
| 20 SkDevice* device = canvas->getDevice(); |
| 21 DCHECK(device != NULL); |
| 22 return device->getRefDict(); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 |
| 28 // static |
| 29 void NativeMetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas, |
| 30 NativeMetafile* metafile) { |
| 31 NativeMetafileSkiaWrapper* wrapper = NULL; |
| 32 if (metafile) |
| 33 wrapper = new NativeMetafileSkiaWrapper(metafile); |
| 34 |
| 35 SkRefDict& dict = getRefDict(canvas); |
| 36 dict.set(kNativeMetafileKey, wrapper); |
| 37 SkSafeUnref(wrapper); |
| 38 } |
| 39 |
| 40 // static |
| 41 NativeMetafile* NativeMetafileSkiaWrapper::GetMetafileFromCanvas( |
| 42 SkCanvas* canvas) { |
| 43 SkRefDict& dict = getRefDict(canvas); |
| 44 SkRefCnt* value = dict.find(kNativeMetafileKey); |
| 45 if (!value) |
| 46 return NULL; |
| 47 |
| 48 return static_cast<NativeMetafileSkiaWrapper*>(value)->metafile_; |
| 49 } |
| 50 |
| 51 NativeMetafileSkiaWrapper::NativeMetafileSkiaWrapper(NativeMetafile* metafile) |
| 52 : metafile_(metafile) { |
| 53 } |
| 54 |
| 55 } // namespace printing |
OLD | NEW |