Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: printing/metafile_skia_wrapper.cc

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop TNoRef Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "printing/metafile_skia_wrapper.h" 5 #include "printing/metafile_skia_wrapper.h"
6 #include "skia/ext/platform_device.h" 6 #include "skia/ext/platform_device.h"
7 #include "skia/ext/refptr.h"
7 #include "third_party/skia/include/core/SkCanvas.h" 8 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkDevice.h" 9 #include "third_party/skia/include/core/SkDevice.h"
9 #include "third_party/skia/include/core/SkMetaData.h" 10 #include "third_party/skia/include/core/SkMetaData.h"
10 11
11 namespace printing { 12 namespace printing {
12 13
13 namespace { 14 namespace {
14 15
15 const char* kMetafileKey = "CrMetafile"; 16 const char* kMetafileKey = "CrMetafile";
16 const char* kCustomScaleKey = "CrCustomScale"; 17 const char* kCustomScaleKey = "CrCustomScale";
17 18
18 } // namespace 19 } // namespace
19 20
20 // static 21 // static
21 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, 22 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
22 Metafile* metafile) { 23 Metafile* metafile) {
23 MetafileSkiaWrapper* wrapper = NULL; 24 skia::RefPtr<MetafileSkiaWrapper> wrapper;
24 if (metafile) 25 if (metafile)
25 wrapper = new MetafileSkiaWrapper(metafile); 26 wrapper = new MetafileSkiaWrapper(metafile);
26 27
27 SkMetaData& meta = skia::getMetaData(canvas); 28 SkMetaData& meta = skia::getMetaData(canvas);
28 meta.setRefCnt(kMetafileKey, wrapper); 29 meta.setRefCnt(kMetafileKey, wrapper.get());
29 SkSafeUnref(wrapper);
30 } 30 }
31 31
32 // static 32 // static
33 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { 33 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) {
34 SkMetaData& meta = skia::getMetaData(canvas); 34 SkMetaData& meta = skia::getMetaData(canvas);
35 SkRefCnt* value; 35 SkRefCnt* value;
36 if (!meta.findRefCnt(kMetafileKey, &value) || !value) 36 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
37 return NULL; 37 return NULL;
38 38
39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; 39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
(...skipping 16 matching lines...) Expand all
56 56
57 *scale = SkScalarToFloat(value); 57 *scale = SkScalarToFloat(value);
58 return true; 58 return true;
59 } 59 }
60 60
61 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) 61 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile)
62 : metafile_(metafile) { 62 : metafile_(metafile) {
63 } 63 }
64 64
65 } // namespace printing 65 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698