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 #include "SkFontLCDConfig.h" | |
13 static SkPixelGeometry compute_default_geometry() { | |
14 SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder(); | |
15 if (SkFontLCDConfig::kNONE_LCDOrder == order) { | |
16 return kUnknown_SkPixelGeometry; | |
17 } else { | |
18 // Bit0 is RGB(0), BGR(1) | |
19 // Bit1 is H(0), V(1) | |
20 const SkPixelGeometry gGeo[] = { | |
21 kRGB_H_SkPixelGeometry, | |
22 kBGR_H_SkPixelGeometry, | |
23 kRGB_V_SkPixelGeometry, | |
24 kBGR_V_SkPixelGeometry, | |
25 }; | |
26 int index = 0; | |
27 if (SkFontLCDConfig::kBGR_LCDOrder == order) { | |
28 index |= 1; | |
29 } | |
30 if (SkFontLCDConfig::kVertical_LCDOrientation == SkFontLCDConfig::GetSub
pixelOrientation()){ | |
31 index |= 2; | |
32 } | |
33 return gGeo[index]; | |
34 } | |
35 } | |
36 | |
37 SkSurfaceProps::SkSurfaceProps() : fFlags(0), fPixelGeometry(kUnknown_SkPixelGeo
metry) {} | |
38 | |
39 SkSurfaceProps::SkSurfaceProps(InitType) : fFlags(0), fPixelGeometry(compute_def
ault_geometry()) {} | |
40 | |
41 SkSurfaceProps::SkSurfaceProps(uint32_t flags, InitType) | |
42 : fFlags(flags) | |
43 , fPixelGeometry(compute_default_geometry()) | |
44 {} | |
45 | |
46 SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg) | |
47 : fFlags(flags), fPixelGeometry(pg) | |
48 {} | |
49 | |
50 /////////////////////////////////////////////////////////////////////////////// | 12 /////////////////////////////////////////////////////////////////////////////// |
51 | 13 |
52 SkSurface_Base::SkSurface_Base(int width, int height, const SkSurfaceProps* prop
s) | 14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height)
{ |
53 : INHERITED(width, height, props) | |
54 { | |
55 fCachedCanvas = NULL; | 15 fCachedCanvas = NULL; |
56 fCachedImage = NULL; | 16 fCachedImage = NULL; |
57 } | 17 } |
58 | 18 |
59 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* pr
ops) | 19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { |
60 : INHERITED(info, props) | |
61 { | |
62 fCachedCanvas = NULL; | 20 fCachedCanvas = NULL; |
63 fCachedImage = NULL; | 21 fCachedImage = NULL; |
64 } | 22 } |
65 | 23 |
66 SkSurface_Base::~SkSurface_Base() { | 24 SkSurface_Base::~SkSurface_Base() { |
67 // in case the canvas outsurvives us, we null the callback | 25 // in case the canvas outsurvives us, we null the callback |
68 if (fCachedCanvas) { | 26 if (fCachedCanvas) { |
69 fCachedCanvas->setSurfaceBase(NULL); | 27 fCachedCanvas->setSurfaceBase(NULL); |
70 } | 28 } |
71 | 29 |
72 SkSafeUnref(fCachedImage); | 30 SkSafeUnref(fCachedImage); |
73 SkSafeUnref(fCachedCanvas); | 31 SkSafeUnref(fCachedCanvas); |
74 } | 32 } |
75 | 33 |
76 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) { | 34 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 35 const SkPaint* paint) { |
77 SkImage* image = this->newImageSnapshot(); | 36 SkImage* image = this->newImageSnapshot(); |
78 if (image) { | 37 if (image) { |
79 image->draw(canvas, x, y, paint); | 38 image->draw(canvas, x, y, paint); |
80 image->unref(); | 39 image->unref(); |
81 } | 40 } |
82 } | 41 } |
83 | 42 |
84 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { | 43 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { |
85 this->dirtyGenerationID(); | 44 this->dirtyGenerationID(); |
86 | 45 |
(...skipping 21 matching lines...) Expand all Loading... |
108 static int32_t gID; | 67 static int32_t gID; |
109 return sk_atomic_inc(&gID) + 1; | 68 return sk_atomic_inc(&gID) + 1; |
110 } | 69 } |
111 | 70 |
112 static SkSurface_Base* asSB(SkSurface* surface) { | 71 static SkSurface_Base* asSB(SkSurface* surface) { |
113 return static_cast<SkSurface_Base*>(surface); | 72 return static_cast<SkSurface_Base*>(surface); |
114 } | 73 } |
115 | 74 |
116 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
117 | 76 |
118 SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props) | 77 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { |
119 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(width), fHeight(height) | |
120 { | |
121 SkASSERT(fWidth >= 0); | 78 SkASSERT(fWidth >= 0); |
122 SkASSERT(fHeight >= 0); | 79 SkASSERT(fHeight >= 0); |
123 fGenerationID = 0; | 80 fGenerationID = 0; |
124 } | 81 } |
125 | 82 |
126 SkSurface::SkSurface(const SkImageInfo& info, const SkSurfaceProps* props) | 83 SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(in
fo.height()) { |
127 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(info.width()), fHeight(
info.height()) | |
128 { | |
129 SkASSERT(fWidth >= 0); | 84 SkASSERT(fWidth >= 0); |
130 SkASSERT(fHeight >= 0); | 85 SkASSERT(fHeight >= 0); |
131 fGenerationID = 0; | 86 fGenerationID = 0; |
132 } | 87 } |
133 | 88 |
134 uint32_t SkSurface::generationID() { | 89 uint32_t SkSurface::generationID() { |
135 if (0 == fGenerationID) { | 90 if (0 == fGenerationID) { |
136 fGenerationID = asSB(this)->newGenerationID(); | 91 fGenerationID = asSB(this)->newGenerationID(); |
137 } | 92 } |
138 return fGenerationID; | 93 return fGenerationID; |
(...skipping 18 matching lines...) Expand all Loading... |
157 } | 112 } |
158 | 113 |
159 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, | 114 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, |
160 const SkPaint* paint) { | 115 const SkPaint* paint) { |
161 return asSB(this)->onDraw(canvas, x, y, paint); | 116 return asSB(this)->onDraw(canvas, x, y, paint); |
162 } | 117 } |
163 | 118 |
164 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { | 119 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { |
165 return this->getCanvas()->peekPixels(info, rowBytes); | 120 return this->getCanvas()->peekPixels(info, rowBytes); |
166 } | 121 } |
167 | |
168 ////////////////////////////////////////////////////////////////////////////////
////// | |
169 #ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE | |
170 | |
171 static SkSurfaceProps make_props(SkSurface::TextRenderMode trm) { | |
172 uint32_t propsFlags = 0; | |
173 if (SkSurface::kDistanceField_TextRenderMode == trm) { | |
174 propsFlags |= SkSurfaceProps::kUseDistanceFieldFonts_Flag; | |
175 } | |
176 return SkSurfaceProps(propsFlags, SkSurfaceProps::kLegacyFontHost_InitType); | |
177 } | |
178 | |
179 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm, | |
180 RenderTargetFlags flags) { | |
181 SkSurfaceProps props = make_props(trm); | |
182 return NewRenderTargetDirect(target, &props, flags); | |
183 } | |
184 | |
185 SkSurface* SkSurface::NewRenderTarget(GrContext* gr, const SkImageInfo& info, in
t sampleCount, | |
186 TextRenderMode trm, RenderTargetFlags flag
s) { | |
187 SkSurfaceProps props = make_props(trm); | |
188 return NewRenderTarget(gr, info, sampleCount, &props, flags); | |
189 } | |
190 | |
191 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* gr, const SkImageInfo& i
nfo, int sampleCount, | |
192 TextRenderMode trm, RenderTargetFla
gs flags) { | |
193 SkSurfaceProps props = make_props(trm); | |
194 return NewScratchRenderTarget(gr, info, sampleCount, &props, flags); | |
195 } | |
196 | |
197 #endif | |
198 | |
199 #if !SK_SUPPORT_GPU | |
200 | |
201 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*) { | |
202 return NULL; | |
203 } | |
204 | |
205 SkSurface* SkSurface::NewRenderTarget(GrContext*, const SkImageInfo&, int, const
SkSurfaceProps*) { | |
206 return NULL; | |
207 } | |
208 | |
209 SkSurface* SkSurface::NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, | |
210 const SkSurfaceProps*) { | |
211 return NULL; | |
212 } | |
213 | |
214 #endif | |
OLD | NEW |