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 |
12 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
13 | 51 |
14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height)
{ | 52 SkSurface_Base::SkSurface_Base(int width, int height, const Props* props) |
| 53 : INHERITED(width, height, props) |
| 54 { |
15 fCachedCanvas = NULL; | 55 fCachedCanvas = NULL; |
16 fCachedImage = NULL; | 56 fCachedImage = NULL; |
17 } | 57 } |
18 | 58 |
19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { | 59 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const Props* props) |
| 60 : INHERITED(info, props) |
| 61 { |
20 fCachedCanvas = NULL; | 62 fCachedCanvas = NULL; |
21 fCachedImage = NULL; | 63 fCachedImage = NULL; |
22 } | 64 } |
23 | 65 |
24 SkSurface_Base::~SkSurface_Base() { | 66 SkSurface_Base::~SkSurface_Base() { |
25 // in case the canvas outsurvives us, we null the callback | 67 // in case the canvas outsurvives us, we null the callback |
26 if (fCachedCanvas) { | 68 if (fCachedCanvas) { |
27 fCachedCanvas->setSurfaceBase(NULL); | 69 fCachedCanvas->setSurfaceBase(NULL); |
28 } | 70 } |
29 | 71 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 static int32_t gID; | 109 static int32_t gID; |
68 return sk_atomic_inc(&gID) + 1; | 110 return sk_atomic_inc(&gID) + 1; |
69 } | 111 } |
70 | 112 |
71 static SkSurface_Base* asSB(SkSurface* surface) { | 113 static SkSurface_Base* asSB(SkSurface* surface) { |
72 return static_cast<SkSurface_Base*>(surface); | 114 return static_cast<SkSurface_Base*>(surface); |
73 } | 115 } |
74 | 116 |
75 /////////////////////////////////////////////////////////////////////////////// | 117 /////////////////////////////////////////////////////////////////////////////// |
76 | 118 |
77 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { | 119 static SkSurfaceProps props_or_default(const SkSurfaceProps* props) { |
| 120 if (props) { |
| 121 return *props; |
| 122 } else { |
| 123 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
| 124 } |
| 125 } |
| 126 |
| 127 SkSurface::SkSurface(int width, int height, const Props* props) |
| 128 : fProps(props_or_default(props)), fWidth(width), fHeight(height) |
| 129 { |
78 SkASSERT(fWidth >= 0); | 130 SkASSERT(fWidth >= 0); |
79 SkASSERT(fHeight >= 0); | 131 SkASSERT(fHeight >= 0); |
80 fGenerationID = 0; | 132 fGenerationID = 0; |
81 } | 133 } |
82 | 134 |
83 SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(in
fo.height()) { | 135 SkSurface::SkSurface(const SkImageInfo& info, const Props* props) |
| 136 : fProps(props_or_default(props)), fWidth(info.width()), fHeight(info.height
()) |
| 137 { |
84 SkASSERT(fWidth >= 0); | 138 SkASSERT(fWidth >= 0); |
85 SkASSERT(fHeight >= 0); | 139 SkASSERT(fHeight >= 0); |
86 fGenerationID = 0; | 140 fGenerationID = 0; |
87 } | 141 } |
88 | 142 |
89 uint32_t SkSurface::generationID() { | 143 uint32_t SkSurface::generationID() { |
90 if (0 == fGenerationID) { | 144 if (0 == fGenerationID) { |
91 fGenerationID = asSB(this)->newGenerationID(); | 145 fGenerationID = asSB(this)->newGenerationID(); |
92 } | 146 } |
93 return fGenerationID; | 147 return fGenerationID; |
(...skipping 18 matching lines...) Expand all Loading... |
112 } | 166 } |
113 | 167 |
114 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, | 168 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, |
115 const SkPaint* paint) { | 169 const SkPaint* paint) { |
116 return asSB(this)->onDraw(canvas, x, y, paint); | 170 return asSB(this)->onDraw(canvas, x, y, paint); |
117 } | 171 } |
118 | 172 |
119 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { | 173 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { |
120 return this->getCanvas()->peekPixels(info, rowBytes); | 174 return this->getCanvas()->peekPixels(info, rowBytes); |
121 } | 175 } |
OLD | NEW |