OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 | 11 |
12 /////////////////////////////////////////////////////////////////////////////// | 12 /////////////////////////////////////////////////////////////////////////////// |
13 | 13 |
14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height)
{ | 14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height)
{ |
15 fCachedCanvas = NULL; | 15 fCachedCanvas = NULL; |
16 fCachedImage = NULL; | 16 fCachedImage = NULL; |
17 } | 17 } |
18 | 18 |
| 19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { |
| 20 fCachedCanvas = NULL; |
| 21 fCachedImage = NULL; |
| 22 } |
| 23 |
19 SkSurface_Base::~SkSurface_Base() { | 24 SkSurface_Base::~SkSurface_Base() { |
20 // in case the canvas outsurvives us, we null the callback | 25 // in case the canvas outsurvives us, we null the callback |
21 if (fCachedCanvas) { | 26 if (fCachedCanvas) { |
22 fCachedCanvas->setSurfaceBase(NULL); | 27 fCachedCanvas->setSurfaceBase(NULL); |
23 } | 28 } |
24 | 29 |
25 SkSafeUnref(fCachedImage); | 30 SkSafeUnref(fCachedImage); |
26 SkSafeUnref(fCachedCanvas); | 31 SkSafeUnref(fCachedCanvas); |
27 } | 32 } |
28 | 33 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return sk_atomic_inc(&gID) + 1; | 71 return sk_atomic_inc(&gID) + 1; |
67 } | 72 } |
68 | 73 |
69 static SkSurface_Base* asSB(SkSurface* surface) { | 74 static SkSurface_Base* asSB(SkSurface* surface) { |
70 return static_cast<SkSurface_Base*>(surface); | 75 return static_cast<SkSurface_Base*>(surface); |
71 } | 76 } |
72 | 77 |
73 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
74 | 79 |
75 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { | 80 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { |
76 SkASSERT(width >= 0); | 81 SkASSERT(fWidth >= 0); |
77 SkASSERT(height >= 0); | 82 SkASSERT(fHeight >= 0); |
78 fGenerationID = 0; | 83 fGenerationID = 0; |
79 } | 84 } |
80 | 85 |
| 86 SkSurface::SkSurface(const SkImageInfo& info) |
| 87 : fWidth(info.fWidth) |
| 88 , fHeight(info.fHeight) |
| 89 { |
| 90 SkASSERT(fWidth >= 0); |
| 91 SkASSERT(fHeight >= 0); |
| 92 fGenerationID = 0; |
| 93 } |
| 94 |
81 uint32_t SkSurface::generationID() { | 95 uint32_t SkSurface::generationID() { |
82 if (0 == fGenerationID) { | 96 if (0 == fGenerationID) { |
83 fGenerationID = asSB(this)->newGenerationID(); | 97 fGenerationID = asSB(this)->newGenerationID(); |
84 } | 98 } |
85 return fGenerationID; | 99 return fGenerationID; |
86 } | 100 } |
87 | 101 |
88 void SkSurface::notifyContentWillChange(ContentChangeMode mode) { | 102 void SkSurface::notifyContentWillChange(ContentChangeMode mode) { |
89 asSB(this)->aboutToDraw(mode); | 103 asSB(this)->aboutToDraw(mode); |
90 } | 104 } |
91 | 105 |
92 SkCanvas* SkSurface::getCanvas() { | 106 SkCanvas* SkSurface::getCanvas() { |
93 return asSB(this)->getCachedCanvas(); | 107 return asSB(this)->getCachedCanvas(); |
94 } | 108 } |
95 | 109 |
96 SkImage* SkSurface::newImageSnapshot() { | 110 SkImage* SkSurface::newImageSnapshot() { |
97 SkImage* image = asSB(this)->getCachedImage(); | 111 SkImage* image = asSB(this)->getCachedImage(); |
98 SkSafeRef(image); // the caller will call unref() to balance this | 112 SkSafeRef(image); // the caller will call unref() to balance this |
99 return image; | 113 return image; |
100 } | 114 } |
101 | 115 |
102 SkSurface* SkSurface::newSurface(const SkImageInfo& info) { | 116 SkSurface* SkSurface::newSurface(const SkImageInfo& info) { |
103 return asSB(this)->onNewSurface(info); | 117 return asSB(this)->onNewSurface(info); |
104 } | 118 } |
105 | 119 |
106 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, | 120 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, |
107 const SkPaint* paint) { | 121 const SkPaint* paint) { |
108 return asSB(this)->onDraw(canvas, x, y, paint); | 122 return asSB(this)->onDraw(canvas, x, y, paint); |
109 } | 123 } |
OLD | NEW |