| OLD | NEW |
| 1 #include "SampleCode.h" | 1 #include "SampleCode.h" |
| 2 #include "SkCanvas.h" | 2 #include "SkCanvas.h" |
| 3 #include "SkView.h" | 3 #include "SkView.h" |
| 4 #include "Sk1DPathEffect.h" | 4 #include "Sk1DPathEffect.h" |
| 5 #include "Sk2DPathEffect.h" | 5 #include "Sk2DPathEffect.h" |
| 6 #include "SkAvoidXfermode.h" | 6 #include "SkAvoidXfermode.h" |
| 7 #include "SkBlurMaskFilter.h" | 7 #include "SkBlurMaskFilter.h" |
| 8 #include "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkCornerPathEffect.h" | 10 #include "SkCornerPathEffect.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "SkPathMeasure.h" | 23 #include "SkPathMeasure.h" |
| 24 #include "SkPicture.h" | 24 #include "SkPicture.h" |
| 25 #include "SkRandom.h" | 25 #include "SkRandom.h" |
| 26 #include "SkTransparentShader.h" | 26 #include "SkTransparentShader.h" |
| 27 #include "SkTypeface.h" | 27 #include "SkTypeface.h" |
| 28 #include "SkUnitMappers.h" | 28 #include "SkUnitMappers.h" |
| 29 #include "SkUtils.h" | 29 #include "SkUtils.h" |
| 30 #include "SkXfermode.h" | 30 #include "SkXfermode.h" |
| 31 | 31 |
| 32 #include <math.h> | 32 #include <math.h> |
| 33 | 33 |
| 34 static inline SkPMColor rgb2gray(SkPMColor c) | 34 static inline SkPMColor rgb2gray(SkPMColor c) |
| 35 { | 35 { |
| 36 unsigned r = SkGetPackedR32(c); | 36 unsigned r = SkGetPackedR32(c); |
| 37 unsigned g = SkGetPackedG32(c); | 37 unsigned g = SkGetPackedG32(c); |
| 38 unsigned b = SkGetPackedB32(c); | 38 unsigned b = SkGetPackedB32(c); |
| 39 | 39 |
| 40 unsigned x = r * 5 + g * 7 + b * 4 >> 4; | 40 unsigned x = r * 5 + g * 7 + b * 4 >> 4; |
| 41 | 41 |
| 42 return SkPackARGB32(0, x, x, x) | (c & (SK_A32_MASK << SK_A32_SHIFT)); | 42 return SkPackARGB32(0, x, x, x) | (c & (SK_A32_MASK << SK_A32_SHIFT)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 class SkGrayScaleColorFilter : public SkColorFilter { | 45 class SkGrayScaleColorFilter : public SkColorFilter { |
| 46 public: | 46 public: |
| 47 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]
) | 47 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]
) |
| 48 { | 48 { |
| 49 for (int i = 0; i < count; i++) | 49 for (int i = 0; i < count; i++) |
| 50 result[i] = rgb2gray(src[i]); | 50 result[i] = rgb2gray(src[i]); |
| 51 } | 51 } |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class SkChannelMaskColorFilter : public SkColorFilter { | 54 class SkChannelMaskColorFilter : public SkColorFilter { |
| 55 public: | 55 public: |
| 56 SkChannelMaskColorFilter(U8CPU redMask, U8CPU greenMask, U8CPU blueMask) | 56 SkChannelMaskColorFilter(U8CPU redMask, U8CPU greenMask, U8CPU blueMask) |
| 57 { | 57 { |
| 58 fMask = SkPackARGB32(0xFF, redMask, greenMask, blueMask); | 58 fMask = SkPackARGB32(0xFF, redMask, greenMask, blueMask); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]
) | 61 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]
) |
| 62 { | 62 { |
| 63 SkPMColor mask = fMask; | 63 SkPMColor mask = fMask; |
| 64 for (int i = 0; i < count; i++) | 64 for (int i = 0; i < count; i++) |
| 65 result[i] = src[i] & mask; | 65 result[i] = src[i] & mask; |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 SkPMColor fMask; | 69 SkPMColor fMask; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 /////////////////////////////////////////////////////////// | 72 /////////////////////////////////////////////////////////// |
| 73 | 73 |
| 74 static void r0(SkLayerRasterizer* rast, SkPaint& p) | 74 static void r0(SkLayerRasterizer* rast, SkPaint& p) |
| 75 { | 75 { |
| 76 p.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3), | 76 p.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3), |
| 77 SkBlurMaskFilter::kNormal_BlurStyle
))->unref(); | 77 SkBlurMaskFilter::kNormal_BlurStyle
))->unref(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 91 static void r1(SkLayerRasterizer* rast, SkPaint& p) | 91 static void r1(SkLayerRasterizer* rast, SkPaint& p) |
| 92 { | 92 { |
| 93 rast->addLayer(p); | 93 rast->addLayer(p); |
| 94 | 94 |
| 95 p.setAlpha(0x40); | 95 p.setAlpha(0x40); |
| 96 p.setXfermodeMode(SkXfermode::kSrc_Mode); | 96 p.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 97 p.setStyle(SkPaint::kStroke_Style); | 97 p.setStyle(SkPaint::kStroke_Style); |
| 98 p.setStrokeWidth(SK_Scalar1*2); | 98 p.setStrokeWidth(SK_Scalar1*2); |
| 99 rast->addLayer(p); | 99 rast->addLayer(p); |
| 100 } | 100 } |
| 101 | 101 |
| 102 static void r2(SkLayerRasterizer* rast, SkPaint& p) | 102 static void r2(SkLayerRasterizer* rast, SkPaint& p) |
| 103 { | 103 { |
| 104 p.setStyle(SkPaint::kStrokeAndFill_Style); | 104 p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 105 p.setStrokeWidth(SK_Scalar1*4); | 105 p.setStrokeWidth(SK_Scalar1*4); |
| 106 rast->addLayer(p); | 106 rast->addLayer(p); |
| 107 | 107 |
| 108 p.setStyle(SkPaint::kStroke_Style); | 108 p.setStyle(SkPaint::kStroke_Style); |
| 109 p.setStrokeWidth(SK_Scalar1*3/2); | 109 p.setStrokeWidth(SK_Scalar1*3/2); |
| 110 p.setXfermodeMode(SkXfermode::kClear_Mode); | 110 p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 111 rast->addLayer(p); | 111 rast->addLayer(p); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 141 rast->addLayer(p); | 141 rast->addLayer(p); |
| 142 | 142 |
| 143 p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref
(); | 143 p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref
(); |
| 144 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); | 144 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
| 145 rast->addLayer(p); | 145 rast->addLayer(p); |
| 146 } | 146 } |
| 147 | 147 |
| 148 static void r6(SkLayerRasterizer* rast, SkPaint& p) | 148 static void r6(SkLayerRasterizer* rast, SkPaint& p) |
| 149 { | 149 { |
| 150 rast->addLayer(p); | 150 rast->addLayer(p); |
| 151 | 151 |
| 152 p.setAntiAlias(false); | 152 p.setAntiAlias(false); |
| 153 SkLayerRasterizer* rast2 = new SkLayerRasterizer; | 153 SkLayerRasterizer* rast2 = new SkLayerRasterizer; |
| 154 r5(rast2, p); | 154 r5(rast2, p); |
| 155 p.setRasterizer(rast2)->unref(); | 155 p.setRasterizer(rast2)->unref(); |
| 156 p.setXfermodeMode(SkXfermode::kClear_Mode); | 156 p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 157 rast->addLayer(p); | 157 rast->addLayer(p); |
| 158 } | 158 } |
| 159 | 159 |
| 160 class Dot2DPathEffect : public Sk2DPathEffect { | 160 class Dot2DPathEffect : public Sk2DPathEffect { |
| 161 public: | 161 public: |
| 162 Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix) | 162 Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix) |
| 163 : Sk2DPathEffect(matrix), fRadius(radius) {} | 163 : Sk2DPathEffect(matrix), fRadius(radius) {} |
| 164 | 164 |
| 165 virtual void flatten(SkFlattenableWriteBuffer& buffer) | 165 virtual void flatten(SkFlattenableWriteBuffer& buffer) |
| 166 { | 166 { |
| 167 this->INHERITED::flatten(buffer); | 167 this->INHERITED::flatten(buffer); |
| 168 | 168 |
| 169 buffer.writeScalar(fRadius); | 169 buffer.writeScalar(fRadius); |
| 170 } | 170 } |
| 171 virtual Factory getFactory() { return CreateProc; } | 171 virtual Factory getFactory() { return CreateProc; } |
| 172 | 172 |
| 173 protected: | 173 protected: |
| 174 virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) | 174 virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) |
| 175 { | 175 { |
| 176 dst->addCircle(loc.fX, loc.fY, fRadius); | 176 dst->addCircle(loc.fX, loc.fY, fRadius); |
| 177 } | 177 } |
| 178 | 178 |
| 179 Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) | 179 Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) |
| 180 { | 180 { |
| 181 fRadius = buffer.readScalar(); | 181 fRadius = buffer.readScalar(); |
| 182 } | 182 } |
| 183 private: | 183 private: |
| 184 SkScalar fRadius; | 184 SkScalar fRadius; |
| 185 | 185 |
| 186 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) | 186 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) |
| 187 { | 187 { |
| 188 return new Dot2DPathEffect(buffer); | 188 return new Dot2DPathEffect(buffer); |
| 189 } | 189 } |
| 190 | 190 |
| 191 typedef Sk2DPathEffect INHERITED; | 191 typedef Sk2DPathEffect INHERITED; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 static void r7(SkLayerRasterizer* rast, SkPaint& p) | 194 static void r7(SkLayerRasterizer* rast, SkPaint& p) |
| 195 { | 195 { |
| 196 SkMatrix lattice; | 196 SkMatrix lattice; |
| 197 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); | 197 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 198 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); | 198 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
| 199 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref(); | 199 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref(); |
| 200 rast->addLayer(p); | 200 rast->addLayer(p); |
| 201 } | 201 } |
| 202 | 202 |
| 203 static void r8(SkLayerRasterizer* rast, SkPaint& p) | 203 static void r8(SkLayerRasterizer* rast, SkPaint& p) |
| 204 { | 204 { |
| 205 rast->addLayer(p); | 205 rast->addLayer(p); |
| 206 | 206 |
| 207 SkMatrix lattice; | 207 SkMatrix lattice; |
| 208 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); | 208 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 209 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); | 209 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
| 210 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref(); | 210 p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref(); |
| 211 p.setXfermodeMode(SkXfermode::kClear_Mode); | 211 p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 212 rast->addLayer(p); | 212 rast->addLayer(p); |
| 213 | 213 |
| 214 p.setPathEffect(NULL); | 214 p.setPathEffect(NULL); |
| 215 p.setXfermode(NULL); | 215 p.setXfermode(NULL); |
| 216 p.setStyle(SkPaint::kStroke_Style); | 216 p.setStyle(SkPaint::kStroke_Style); |
| 217 p.setStrokeWidth(SK_Scalar1); | 217 p.setStrokeWidth(SK_Scalar1); |
| 218 rast->addLayer(p); | 218 rast->addLayer(p); |
| 219 } | 219 } |
| 220 | 220 |
| 221 class Line2DPathEffect : public Sk2DPathEffect { | 221 class Line2DPathEffect : public Sk2DPathEffect { |
| 222 public: | 222 public: |
| 223 Line2DPathEffect(SkScalar width, const SkMatrix& matrix) | 223 Line2DPathEffect(SkScalar width, const SkMatrix& matrix) |
| 224 : Sk2DPathEffect(matrix), fWidth(width) {} | 224 : Sk2DPathEffect(matrix), fWidth(width) {} |
| 225 | 225 |
| 226 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) | 226 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) |
| 227 { | 227 { |
| 228 if (this->INHERITED::filterPath(dst, src, width)) | 228 if (this->INHERITED::filterPath(dst, src, width)) |
| 229 { | 229 { |
| 230 *width = fWidth; | 230 *width = fWidth; |
| 231 return true; | 231 return true; |
| 232 } | 232 } |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 | 235 |
| 236 virtual Factory getFactory() { return CreateProc; } | 236 virtual Factory getFactory() { return CreateProc; } |
| 237 virtual void flatten(SkFlattenableWriteBuffer& buffer) | 237 virtual void flatten(SkFlattenableWriteBuffer& buffer) |
| 238 { | 238 { |
| 239 this->INHERITED::flatten(buffer); | 239 this->INHERITED::flatten(buffer); |
| 240 buffer.writeScalar(fWidth); | 240 buffer.writeScalar(fWidth); |
| 241 } | 241 } |
| 242 protected: | 242 protected: |
| 243 virtual void nextSpan(int u, int v, int ucount, SkPath* dst) | 243 virtual void nextSpan(int u, int v, int ucount, SkPath* dst) |
| 244 { | 244 { |
| 245 if (ucount > 1) | 245 if (ucount > 1) |
| 246 { | 246 { |
| 247 SkPoint src[2], dstP[2]; | 247 SkPoint src[2], dstP[2]; |
| 248 | 248 |
| 249 src[0].set(SkIntToScalar(u) + SK_ScalarHalf, | 249 src[0].set(SkIntToScalar(u) + SK_ScalarHalf, |
| 250 SkIntToScalar(v) + SK_ScalarHalf); | 250 SkIntToScalar(v) + SK_ScalarHalf); |
| 251 src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf, | 251 src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf, |
| 252 SkIntToScalar(v) + SK_ScalarHalf); | 252 SkIntToScalar(v) + SK_ScalarHalf); |
| 253 this->getMatrix().mapPoints(dstP, src, 2); | 253 this->getMatrix().mapPoints(dstP, src, 2); |
| 254 | 254 |
| 255 dst->moveTo(dstP[0]); | 255 dst->moveTo(dstP[0]); |
| 256 dst->lineTo(dstP[1]); | 256 dst->lineTo(dstP[1]); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 Line2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) | 260 Line2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) |
| 261 { | 261 { |
| 262 fWidth = buffer.readScalar(); | 262 fWidth = buffer.readScalar(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 private: | 265 private: |
| 266 SkScalar fWidth; | 266 SkScalar fWidth; |
| 267 | 267 |
| 268 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { return n
ew Line2DPathEffect(buffer); } | 268 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { return n
ew Line2DPathEffect(buffer); } |
| 269 | 269 |
| 270 typedef Sk2DPathEffect INHERITED; | 270 typedef Sk2DPathEffect INHERITED; |
| 271 }; | 271 }; |
| 272 | 272 |
| 273 static void r9(SkLayerRasterizer* rast, SkPaint& p) | 273 static void r9(SkLayerRasterizer* rast, SkPaint& p) |
| 274 { | 274 { |
| 275 rast->addLayer(p); | 275 rast->addLayer(p); |
| 276 | 276 |
| 277 SkMatrix lattice; | 277 SkMatrix lattice; |
| 278 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); | 278 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
| 279 lattice.postRotate(SkIntToScalar(30), 0, 0); | 279 lattice.postRotate(SkIntToScalar(30), 0, 0); |
| 280 p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref(); | 280 p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref(); |
| 281 p.setXfermodeMode(SkXfermode::kClear_Mode); | 281 p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 282 rast->addLayer(p); | 282 rast->addLayer(p); |
| 283 | 283 |
| 284 p.setPathEffect(NULL); | 284 p.setPathEffect(NULL); |
| 285 p.setXfermode(NULL); | 285 p.setXfermode(NULL); |
| 286 p.setStyle(SkPaint::kStroke_Style); | 286 p.setStyle(SkPaint::kStroke_Style); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 302 { 0xFFFFFF, 0x800000 }, // just-add case | 302 { 0xFFFFFF, 0x800000 }, // just-add case |
| 303 { 0x808080, 0x000000 }, // just-mul case | 303 { 0x808080, 0x000000 }, // just-mul case |
| 304 { 0xFFFFFF, 0x000000 } // identity case | 304 { 0xFFFFFF, 0x000000 } // identity case |
| 305 }; | 305 }; |
| 306 | 306 |
| 307 static unsigned color_dist16(uint16_t a, uint16_t b) | 307 static unsigned color_dist16(uint16_t a, uint16_t b) |
| 308 { | 308 { |
| 309 unsigned dr = SkAbs32(SkPacked16ToR32(a) - SkPacked16ToR32(b)); | 309 unsigned dr = SkAbs32(SkPacked16ToR32(a) - SkPacked16ToR32(b)); |
| 310 unsigned dg = SkAbs32(SkPacked16ToG32(a) - SkPacked16ToG32(b)); | 310 unsigned dg = SkAbs32(SkPacked16ToG32(a) - SkPacked16ToG32(b)); |
| 311 unsigned db = SkAbs32(SkPacked16ToB32(a) - SkPacked16ToB32(b)); | 311 unsigned db = SkAbs32(SkPacked16ToB32(a) - SkPacked16ToB32(b)); |
| 312 | 312 |
| 313 return SkMax32(dr, SkMax32(dg, db)); | 313 return SkMax32(dr, SkMax32(dg, db)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 static unsigned scale_dist(unsigned dist, unsigned scale) | 316 static unsigned scale_dist(unsigned dist, unsigned scale) |
| 317 { | 317 { |
| 318 dist >>= 6; | 318 dist >>= 6; |
| 319 dist = (dist << 2) | dist; | 319 dist = (dist << 2) | dist; |
| 320 dist = (dist << 4) | dist; | 320 dist = (dist << 4) | dist; |
| 321 return dist; | 321 return dist; |
| 322 | 322 |
| 323 // return SkAlphaMul(dist, scale); | 323 // return SkAlphaMul(dist, scale); |
| 324 } | 324 } |
| 325 | 325 |
| 326 static void apply_shader(SkPaint* paint, int index) | 326 static void apply_shader(SkPaint* paint, int index) |
| 327 { | 327 { |
| 328 raster_proc proc = gRastProcs[index]; | 328 raster_proc proc = gRastProcs[index]; |
| 329 if (proc) | 329 if (proc) |
| 330 { | 330 { |
| 331 SkPaint p; | 331 SkPaint p; |
| 332 SkLayerRasterizer* rast = new SkLayerRasterizer; | 332 SkLayerRasterizer* rast = new SkLayerRasterizer; |
| 333 | 333 |
| 334 p.setAntiAlias(true); | 334 p.setAntiAlias(true); |
| 335 proc(rast, p); | 335 proc(rast, p); |
| 336 paint->setRasterizer(rast)->unref(); | 336 paint->setRasterizer(rast)->unref(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 #if 1 | 339 #if 1 |
| 340 SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; | 340 SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; |
| 341 paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss(dir, SK_Scalar1/4, SkInt
ToScalar(4), SkIntToScalar(3)))->unref(); | 341 paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss(dir, SK_Scalar1/4, SkInt
ToScalar(4), SkIntToScalar(3)))->unref(); |
| 342 paint->setColor(SK_ColorBLUE); | 342 paint->setColor(SK_ColorBLUE); |
| 343 #endif | 343 #endif |
| 344 } | 344 } |
| 345 | 345 |
| 346 static void test_math() | 346 static void test_math() |
| 347 { | 347 { |
| 348 float x; | 348 float x; |
| 349 const float PI = 3.141593; | 349 const float PI = 3.141593; |
| 350 | 350 |
| 351 for (x = 0; x < 1; x += 0.05f) | 351 for (x = 0; x < 1; x += 0.05f) |
| 352 printf("atan(%g) = %g\n", x, atanf(x) * 180/PI); | 352 printf("atan(%g) = %g\n", x, atanf(x) * 180/PI); |
| 353 for (x = 1; x < 10000000; x *= 2) | 353 for (x = 1; x < 10000000; x *= 2) |
| 354 printf("atan(%g) = %g\n", x, atanf(x) * 180/PI); | 354 printf("atan(%g) = %g\n", x, atanf(x) * 180/PI); |
| 355 } | 355 } |
| 356 | 356 |
| 357 class DemoView : public SkView { | 357 class DemoView : public SkView { |
| 358 public: | 358 public: |
| 359 DemoView() | 359 DemoView() |
| 360 { | 360 { |
| 361 test_math(); | 361 test_math(); |
| 362 } | 362 } |
| 363 » | 363 |
| 364 protected: | 364 protected: |
| 365 // overrides from SkEventSink | 365 // overrides from SkEventSink |
| 366 virtual bool onQuery(SkEvent* evt) | 366 virtual bool onQuery(SkEvent* evt) |
| 367 { | 367 { |
| 368 if (SampleCode::TitleQ(*evt)) | 368 if (SampleCode::TitleQ(*evt)) |
| 369 { | 369 { |
| 370 SampleCode::TitleR(evt, "Demo"); | 370 SampleCode::TitleR(evt, "Demo"); |
| 371 return true; | 371 return true; |
| 372 } | 372 } |
| 373 return this->INHERITED::onQuery(evt); | 373 return this->INHERITED::onQuery(evt); |
| 374 } | 374 } |
| 375 | 375 |
| 376 virtual bool onClick(Click* click) | 376 virtual bool onClick(Click* click) |
| 377 { | 377 { |
| 378 return this->INHERITED::onClick(click); | 378 return this->INHERITED::onClick(click); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void makePath(SkPath& path) | 381 void makePath(SkPath& path) |
| 382 { | 382 { |
| 383 path.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(20), | 383 path.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(20), |
| 384 SkPath::kCCW_Direction); | 384 SkPath::kCCW_Direction); |
| 385 for (int index = 0; index < 10; index++) { | 385 for (int index = 0; index < 10; index++) { |
| 386 SkScalar x = SkFloatToScalar(cos(index / 10.0f * 2 * 3.1415925358f))
; | 386 SkScalar x = SkFloatToScalar(cos(index / 10.0f * 2 * 3.1415925358f))
; |
| 387 SkScalar y = SkFloatToScalar(sin(index / 10.0f * 2 * 3.1415925358f))
; | 387 SkScalar y = SkFloatToScalar(sin(index / 10.0f * 2 * 3.1415925358f))
; |
| 388 x *= index & 1 ? 7 : 14; | 388 x *= index & 1 ? 7 : 14; |
| 389 y *= index & 1 ? 7 : 14; | 389 y *= index & 1 ? 7 : 14; |
| 390 x += SkIntToScalar(20); | 390 x += SkIntToScalar(20); |
| 391 y += SkIntToScalar(20); | 391 y += SkIntToScalar(20); |
| 392 if (index == 0) | 392 if (index == 0) |
| 393 path.moveTo(x, y); | 393 path.moveTo(x, y); |
| 394 else | 394 else |
| 395 path.lineTo(x, y); | 395 path.lineTo(x, y); |
| 396 } | 396 } |
| 397 path.close(); | 397 path.close(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 virtual void onDraw(SkCanvas* canvas) | 400 virtual void onDraw(SkCanvas* canvas) |
| 401 { | 401 { |
| 402 canvas->drawColor(SK_ColorWHITE); | 402 canvas->drawColor(SK_ColorWHITE); |
| 403 canvas->save(); | 403 canvas->save(); |
| 404 drawPicture(canvas, 0); | 404 drawPicture(canvas, 0); |
| 405 canvas->restore(); | 405 canvas->restore(); |
| 406 | 406 |
| 407 { | 407 { |
| 408 SkPicture picture; | 408 SkPicture picture; |
| 409 SkCanvas* record = picture.beginRecording(320, 480); | 409 SkCanvas* record = picture.beginRecording(320, 480); |
| 410 drawPicture(record, 120); | 410 drawPicture(record, 120); |
| 411 canvas->translate(0, SkIntToScalar(120)); | 411 canvas->translate(0, SkIntToScalar(120)); |
| 412 | 412 |
| 413 SkRect clip; | 413 SkRect clip; |
| 414 clip.set(0, 0, SkIntToScalar(160), SkIntToScalar(160)); | 414 clip.set(0, 0, SkIntToScalar(160), SkIntToScalar(160)); |
| 415 do { | 415 do { |
| 416 canvas->save(); | 416 canvas->save(); |
| 417 canvas->clipRect(clip); | 417 canvas->clipRect(clip); |
| 418 picture.draw(canvas); | 418 picture.draw(canvas); |
| 419 canvas->restore(); | 419 canvas->restore(); |
| 420 if (clip.fRight < SkIntToScalar(320)) | 420 if (clip.fRight < SkIntToScalar(320)) |
| 421 clip.offset(SkIntToScalar(160), 0); | 421 clip.offset(SkIntToScalar(160), 0); |
| 422 else if (clip.fBottom < SkIntToScalar(480)) | 422 else if (clip.fBottom < SkIntToScalar(480)) |
| 423 clip.offset(-SkIntToScalar(320), SkIntToScalar(160)); | 423 clip.offset(-SkIntToScalar(320), SkIntToScalar(160)); |
| 424 else | 424 else |
| 425 break; | 425 break; |
| 426 } while (true); | 426 } while (true); |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 | 429 |
| 430 void drawPicture(SkCanvas* canvas, int spriteOffset) | 430 void drawPicture(SkCanvas* canvas, int spriteOffset) |
| 431 { | 431 { |
| 432 SkMatrix matrix; matrix.reset(); | 432 SkMatrix matrix; matrix.reset(); |
| 433 SkPaint paint; | 433 SkPaint paint; |
| 434 SkPath path; | 434 SkPath path; |
| 435 SkPoint start = {0, 0}; | 435 SkPoint start = {0, 0}; |
| 436 SkPoint stop = { SkIntToScalar(40), SkIntToScalar(40) }; | 436 SkPoint stop = { SkIntToScalar(40), SkIntToScalar(40) }; |
| 437 SkRect rect = {0, 0, SkIntToScalar(40), SkIntToScalar(40) }; | 437 SkRect rect = {0, 0, SkIntToScalar(40), SkIntToScalar(40) }; |
| 438 SkRect rect2 = {0, 0, SkIntToScalar(65), SkIntToScalar(20) }; | 438 SkRect rect2 = {0, 0, SkIntToScalar(65), SkIntToScalar(20) }; |
| 439 SkScalar left = 0, top = 0, x = 0, y = 0; | 439 SkScalar left = 0, top = 0, x = 0, y = 0; |
| 440 int index; | 440 int index; |
| 441 » » | 441 |
| 442 char ascii[] = "ascii..."; | 442 char ascii[] = "ascii..."; |
| 443 size_t asciiLength = sizeof(ascii) - 1; | 443 size_t asciiLength = sizeof(ascii) - 1; |
| 444 char utf8[] = "utf8" "\xe2\x80\xa6"; | 444 char utf8[] = "utf8" "\xe2\x80\xa6"; |
| 445 short utf16[] = {'u', 't', 'f', '1', '6', 0x2026 }; | 445 short utf16[] = {'u', 't', 'f', '1', '6', 0x2026 }; |
| 446 short utf16simple[] = {'u', 't', 'f', '1', '6', '!' }; | 446 short utf16simple[] = {'u', 't', 'f', '1', '6', '!' }; |
| 447 » » | 447 |
| 448 makePath(path); | 448 makePath(path); |
| 449 SkTDArray<SkPoint>(pos); | 449 SkTDArray<SkPoint>(pos); |
| 450 pos.setCount(asciiLength); | 450 pos.setCount(asciiLength); |
| 451 for (index = 0; index < asciiLength; index++) | 451 for (index = 0; index < asciiLength; index++) |
| 452 pos[index].set(SkIntToScalar(index * 10), SkIntToScalar(
index * 2)); | 452 pos[index].set(SkIntToScalar(index * 10), SkIntToScalar(
index * 2)); |
| 453 SkTDArray<SkPoint>(pos2); | 453 SkTDArray<SkPoint>(pos2); |
| 454 pos2.setCount(asciiLength); | 454 pos2.setCount(asciiLength); |
| 455 for (index = 0; index < asciiLength; index++) | 455 for (index = 0; index < asciiLength; index++) |
| 456 pos2[index].set(SkIntToScalar(index * 10), SkIntToScalar
(20)); | 456 pos2[index].set(SkIntToScalar(index * 10), SkIntToScalar
(20)); |
| 457 » » | 457 |
| 458 // shaders | 458 // shaders |
| 459 SkPoint linearPoints[] = { 0, 0, SkIntToScalar(40), SkIntToScalar(40) }; | 459 SkPoint linearPoints[] = { 0, 0, SkIntToScalar(40), SkIntToScalar(40) }; |
| 460 SkColor linearColors[] = { SK_ColorRED, SK_ColorBLUE }; | 460 SkColor linearColors[] = { SK_ColorRED, SK_ColorBLUE }; |
| 461 SkScalar* linearPos = NULL; | 461 SkScalar* linearPos = NULL; |
| 462 int linearCount = 2; | 462 int linearCount = 2; |
| 463 SkShader::TileMode linearMode = SkShader::kMirror_TileMode; | 463 SkShader::TileMode linearMode = SkShader::kMirror_TileMode; |
| 464 SkUnitMapper* linearMapper = new SkDiscreteMapper(3); | 464 SkUnitMapper* linearMapper = new SkDiscreteMapper(3); |
| 465 SkAutoUnref unmapLinearMapper(linearMapper); | 465 SkAutoUnref unmapLinearMapper(linearMapper); |
| 466 SkShader* linear = SkGradientShader::CreateLinear(linearPoints, | 466 SkShader* linear = SkGradientShader::CreateLinear(linearPoints, |
| 467 linearColors, linearPos, linearCount, linearMode, linearMapper); | 467 linearColors, linearPos, linearCount, linearMode, linearMapper); |
| 468 | 468 |
| 469 SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) }; | 469 SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) }; |
| 470 SkScalar radialRadius = SkIntToScalar(25); | 470 SkScalar radialRadius = SkIntToScalar(25); |
| 471 SkColor radialColors[] = { SK_ColorGREEN, SK_ColorGRAY, SK_ColorRED }; | 471 SkColor radialColors[] = { SK_ColorGREEN, SK_ColorGRAY, SK_ColorRED }; |
| 472 SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)}; | 472 SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)}; |
| 473 int radialCount = 3; | 473 int radialCount = 3; |
| 474 SkShader::TileMode radialMode = SkShader::kRepeat_TileMode; | 474 SkShader::TileMode radialMode = SkShader::kRepeat_TileMode; |
| 475 SkUnitMapper* radialMapper = new SkCosineMapper(); | 475 SkUnitMapper* radialMapper = new SkCosineMapper(); |
| 476 SkAutoUnref unmapRadialMapper(radialMapper); | 476 SkAutoUnref unmapRadialMapper(radialMapper); |
| 477 SkShader* radial = SkGradientShader::CreateRadial(radialCenter, | 477 SkShader* radial = SkGradientShader::CreateRadial(radialCenter, |
| 478 radialRadius, radialColors, radialPos, radialCount, | 478 radialRadius, radialColors, radialPos, radialCount, |
| 479 radialMode, radialMapper); | 479 radialMode, radialMapper); |
| 480 | 480 |
| 481 SkTransparentShader* transparentShader = new SkTransparentShader(); | 481 SkTransparentShader* transparentShader = new SkTransparentShader(); |
| 482 SkEmbossMaskFilter::Light light; | 482 SkEmbossMaskFilter::Light light; |
| 483 light.fDirection[0] = SK_Scalar1/2; | 483 light.fDirection[0] = SK_Scalar1/2; |
| 484 light.fDirection[1] = SK_Scalar1/2; | 484 light.fDirection[1] = SK_Scalar1/2; |
| 485 light.fDirection[2] = SK_Scalar1/3; | 485 light.fDirection[2] = SK_Scalar1/3; |
| 486 light.fAmbient = 0x48; | 486 light.fAmbient = 0x48; |
| 487 light.fSpecular = 0x80; | 487 light.fSpecular = 0x80; |
| 488 SkScalar radius = SkIntToScalar(12)/5; | 488 SkScalar radius = SkIntToScalar(12)/5; |
| 489 SkEmbossMaskFilter* embossFilter = new SkEmbossMaskFilter(light, | 489 SkEmbossMaskFilter* embossFilter = new SkEmbossMaskFilter(light, |
| 490 radius); | 490 radius); |
| 491 | 491 |
| 492 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); | 492 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode); |
| 493 SkColorFilter* lightingFilter = SkColorFilter::CreateLightingFilter( | 493 SkColorFilter* lightingFilter = SkColorFilter::CreateLightingFilter( |
| 494 0xff89bc45, 0xff112233); | 494 0xff89bc45, 0xff112233); |
| 495 | 495 |
| 496 canvas->save(); | 496 canvas->save(); |
| 497 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); | 497 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); |
| 498 paint.setFlags(SkPaint::kAntiAlias_Flag | SkPaint::kFilterBitmap
_Flag); | 498 paint.setFlags(SkPaint::kAntiAlias_Flag | SkPaint::kFilterBitmap
_Flag); |
| 499 // !!! draw through a clip | 499 // !!! draw through a clip |
| 500 paint.setColor(SK_ColorLTGRAY); | 500 paint.setColor(SK_ColorLTGRAY); |
| 501 paint.setStyle(SkPaint::kFill_Style); | 501 paint.setStyle(SkPaint::kFill_Style); |
| 502 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; | 502 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; |
| 503 canvas->clipRect(clip); | 503 canvas->clipRect(clip); |
| 504 paint.setShader(SkShader::CreateBitmapShader(fTx, | 504 paint.setShader(SkShader::CreateBitmapShader(fTx, |
| 505 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode))->unref(); | 505 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode))->unref(); |
| 506 canvas->drawPaint(paint); | 506 canvas->drawPaint(paint); |
| 507 canvas->save(); | 507 canvas->save(); |
| 508 | 508 |
| 509 // line (exercises xfermode, colorShader, colorFilter, filterShader) | 509 // line (exercises xfermode, colorShader, colorFilter, filterShader) |
| 510 paint.setColor(SK_ColorGREEN); | 510 paint.setColor(SK_ColorGREEN); |
| 511 paint.setStrokeWidth(SkIntToScalar(10)); | 511 paint.setStrokeWidth(SkIntToScalar(10)); |
| 512 paint.setStyle(SkPaint::kStroke_Style); | 512 paint.setStyle(SkPaint::kStroke_Style); |
| 513 paint.setXfermode(xfermode)->unref(); | 513 paint.setXfermode(xfermode)->unref(); |
| 514 paint.setColorFilter(lightingFilter)->unref(); | 514 paint.setColorFilter(lightingFilter)->unref(); |
| 515 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); /
/ should not be green | 515 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); /
/ should not be green |
| 516 paint.setXfermode(NULL); | 516 paint.setXfermode(NULL); |
| 517 paint.setColorFilter(NULL); | 517 paint.setColorFilter(NULL); |
| 518 | 518 |
| 519 // rectangle | 519 // rectangle |
| 520 paint.setStyle(SkPaint::kFill_Style); | 520 paint.setStyle(SkPaint::kFill_Style); |
| 521 canvas->translate(SkIntToScalar(50), 0); | 521 canvas->translate(SkIntToScalar(50), 0); |
| 522 paint.setColor(SK_ColorYELLOW); | 522 paint.setColor(SK_ColorYELLOW); |
| 523 paint.setShader(linear)->unref(); | 523 paint.setShader(linear)->unref(); |
| 524 paint.setPathEffect(pathEffectTest())->unref(); | 524 paint.setPathEffect(pathEffectTest())->unref(); |
| 525 » » canvas->drawRect(rect, paint); | 525 » » canvas->drawRect(rect, paint); |
| 526 paint.setPathEffect(NULL); | 526 paint.setPathEffect(NULL); |
| 527 | 527 |
| 528 // circle w/ emboss & transparent (exercises 3dshader) | 528 // circle w/ emboss & transparent (exercises 3dshader) |
| 529 canvas->translate(SkIntToScalar(50), 0); | 529 canvas->translate(SkIntToScalar(50), 0); |
| 530 paint.setMaskFilter(embossFilter)->unref(); | 530 paint.setMaskFilter(embossFilter)->unref(); |
| 531 canvas->drawOval(rect, paint); | 531 canvas->drawOval(rect, paint); |
| 532 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); | 532 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
| 533 paint.setShader(transparentShader)->unref(); | 533 paint.setShader(transparentShader)->unref(); |
| 534 canvas->drawOval(rect, paint); | 534 canvas->drawOval(rect, paint); |
| 535 canvas->translate(0, SkIntToScalar(-10)); | 535 canvas->translate(0, SkIntToScalar(-10)); |
| 536 | 536 |
| 537 // path | 537 // path |
| 538 canvas->translate(SkIntToScalar(50), 0); | 538 canvas->translate(SkIntToScalar(50), 0); |
| 539 paint.setColor(SK_ColorRED); | 539 paint.setColor(SK_ColorRED); |
| 540 paint.setStyle(SkPaint::kStroke_Style); | 540 paint.setStyle(SkPaint::kStroke_Style); |
| 541 paint.setStrokeWidth(SkIntToScalar(5)); | 541 paint.setStrokeWidth(SkIntToScalar(5)); |
| 542 paint.setShader(radial)->unref(); | 542 paint.setShader(radial)->unref(); |
| 543 paint.setMaskFilter(NULL); | 543 paint.setMaskFilter(NULL); |
| 544 canvas->drawPath(path, paint); | 544 canvas->drawPath(path, paint); |
| 545 » » | 545 |
| 546 paint.setShader(NULL); | 546 paint.setShader(NULL); |
| 547 // bitmap, sprite | 547 // bitmap, sprite |
| 548 canvas->translate(SkIntToScalar(50), 0); | 548 canvas->translate(SkIntToScalar(50), 0); |
| 549 paint.setStyle(SkPaint::kFill_Style); | 549 paint.setStyle(SkPaint::kFill_Style); |
| 550 canvas->drawBitmap(fBug, left, top, &paint); | 550 canvas->drawBitmap(fBug, left, top, &paint); |
| 551 canvas->translate(SkIntToScalar(30), 0); | 551 canvas->translate(SkIntToScalar(30), 0); |
| 552 » » canvas->drawSprite(fTb, | 552 » » canvas->drawSprite(fTb, |
| 553 » » » SkScalarRound(canvas->getTotalMatrix().getTranslateX()),
| 553 » » » SkScalarRound(canvas->getTotalMatrix().getTranslateX()), |
| 554 spriteOffset + 10, &paint); | 554 spriteOffset + 10, &paint); |
| 555 | 555 |
| 556 canvas->translate(-SkIntToScalar(30), SkIntToScalar(30)); | 556 canvas->translate(-SkIntToScalar(30), SkIntToScalar(30)); |
| 557 paint.setShader(shaderTest())->unref(); // test compose shader | 557 paint.setShader(shaderTest())->unref(); // test compose shader |
| 558 » » canvas->drawRect(rect2, paint); | 558 » » canvas->drawRect(rect2, paint); |
| 559 paint.setShader(NULL); | 559 paint.setShader(NULL); |
| 560 » » | 560 |
| 561 canvas->restore(); | 561 canvas->restore(); |
| 562 // text | 562 // text |
| 563 canvas->translate(0, SkIntToScalar(60)); | 563 canvas->translate(0, SkIntToScalar(60)); |
| 564 canvas->save(); | 564 canvas->save(); |
| 565 paint.setColor(SK_ColorGRAY); | 565 paint.setColor(SK_ColorGRAY); |
| 566 canvas->drawPosText(ascii, asciiLength, pos.begin(), paint); | 566 canvas->drawPosText(ascii, asciiLength, pos.begin(), paint); |
| 567 canvas->drawPosText(ascii, asciiLength, pos2.begin(), paint); | 567 canvas->drawPosText(ascii, asciiLength, pos2.begin(), paint); |
| 568 | 568 |
| 569 canvas->translate(SkIntToScalar(50), 0); | 569 canvas->translate(SkIntToScalar(50), 0); |
| 570 paint.setColor(SK_ColorCYAN); | 570 paint.setColor(SK_ColorCYAN); |
| 571 canvas->drawText(utf8, sizeof(utf8) - 1, x, y, paint); | 571 canvas->drawText(utf8, sizeof(utf8) - 1, x, y, paint); |
| 572 | 572 |
| 573 canvas->translate(SkIntToScalar(30), 0); | 573 canvas->translate(SkIntToScalar(30), 0); |
| 574 paint.setColor(SK_ColorMAGENTA); | 574 paint.setColor(SK_ColorMAGENTA); |
| 575 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | 575 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 576 matrix.setTranslate(SkIntToScalar(10), SkIntToScalar(10)); | 576 matrix.setTranslate(SkIntToScalar(10), SkIntToScalar(10)); |
| 577 canvas->drawTextOnPath((void*) utf16, sizeof(utf16), path, &matr
ix, paint); | 577 canvas->drawTextOnPath((void*) utf16, sizeof(utf16), path, &matr
ix, paint); |
| 578 canvas->translate(0, SkIntToScalar(20)); | 578 canvas->translate(0, SkIntToScalar(20)); |
| 579 canvas->drawTextOnPath((void*) utf16simple, sizeof(utf16simple),
path, &matrix, paint); | 579 canvas->drawTextOnPath((void*) utf16simple, sizeof(utf16simple),
path, &matrix, paint); |
| 580 canvas->restore(); | 580 canvas->restore(); |
| 581 | 581 |
| 582 canvas->translate(0, SkIntToScalar(60)); | 582 canvas->translate(0, SkIntToScalar(60)); |
| 583 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); | 583 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 584 canvas->restore(); | 584 canvas->restore(); |
| 585 } | 585 } |
| 586 | 586 |
| 587 /* | 587 /* |
| 588 ./SkColorFilter.h:25:class SkColorFilter : public SkFlattenable { -- abstract | 588 ./SkColorFilter.h:25:class SkColorFilter : public SkFlattenable { -- abstract |
| 589 static SkColorFilter* CreatXfermodeFilter() *** untested *** | 589 static SkColorFilter* CreatXfermodeFilter() *** untested *** |
| 590 static SkColorFilter* CreatePorterDuffFilter() *** untested *** | 590 static SkColorFilter* CreatePorterDuffFilter() *** untested *** |
| 591 static SkColorFilter* CreateLightingFilter() -- tested | 591 static SkColorFilter* CreateLightingFilter() -- tested |
| 592 ./SkDrawLooper.h:9:class SkDrawLooper : public SkFlattenable { -- virtually abst
ract | 592 ./SkDrawLooper.h:9:class SkDrawLooper : public SkFlattenable { -- virtually abst
ract |
| 593 ./SkBlurDrawLooper.h:9:class SkBlurDrawLooper : public SkDrawLooper { *** un
tested *** | 593 ./SkBlurDrawLooper.h:9:class SkBlurDrawLooper : public SkDrawLooper { *** un
tested *** |
| 594 ./SkMaskFilter.h:41:class SkMaskFilter : public SkFlattenable { -- abstract chmo
d +w .h | 594 ./SkMaskFilter.h:41:class SkMaskFilter : public SkFlattenable { -- abstract chmo
d +w .h |
| 595 ./SkEmbossMaskFilter.h:27:class SkEmbossMaskFilter : public SkMaskFilter { -
- tested | 595 ./SkEmbossMaskFilter.h:27:class SkEmbossMaskFilter : public SkMaskFilter { -
- tested |
| 596 ./SkPathEffect.h:33:class SkPathEffect : public SkFlattenable { -- abstract | 596 ./SkPathEffect.h:33:class SkPathEffect : public SkFlattenable { -- abstract |
| (...skipping 14 matching lines...) Expand all Loading... |
| 611 ./SkColorShader.h:26:class SkColorShader : public SkShader { | 611 ./SkColorShader.h:26:class SkColorShader : public SkShader { |
| 612 ./SkShaderExtras.h:31:class SkComposeShader : public SkShader { | 612 ./SkShaderExtras.h:31:class SkComposeShader : public SkShader { |
| 613 ./SkTransparentShader.h:23:class SkTransparentShader : public SkShader { | 613 ./SkTransparentShader.h:23:class SkTransparentShader : public SkShader { |
| 614 ./SkUnitMapper.h:24:class SkUnitMapper : public SkFlattenable { | 614 ./SkUnitMapper.h:24:class SkUnitMapper : public SkFlattenable { |
| 615 ./SkUnitMapper.h:33:class SkDiscreteMapper : public SkUnitMapper { | 615 ./SkUnitMapper.h:33:class SkDiscreteMapper : public SkUnitMapper { |
| 616 ./SkUnitMapper.h:51:class SkFlipCosineMapper : public SkUnitMapper { | 616 ./SkUnitMapper.h:51:class SkFlipCosineMapper : public SkUnitMapper { |
| 617 ./SkXfermode.h:32:class SkXfermode : public SkFlattenable { | 617 ./SkXfermode.h:32:class SkXfermode : public SkFlattenable { |
| 618 ./SkAvoidXfermode.h:28:class SkAvoidXfermode : public SkXfermode { *** not d
one *** chmod +w .h .cpp | 618 ./SkAvoidXfermode.h:28:class SkAvoidXfermode : public SkXfermode { *** not d
one *** chmod +w .h .cpp |
| 619 ./SkXfermode.h:54:class SkProcXfermode : public SkXfermode { | 619 ./SkXfermode.h:54:class SkProcXfermode : public SkXfermode { |
| 620 */ | 620 */ |
| 621 | 621 |
| 622 /* | 622 /* |
| 623 ./SkBlurMaskFilter.h:25:class SkBlurMaskFilter { | 623 ./SkBlurMaskFilter.h:25:class SkBlurMaskFilter { |
| 624 chmod +w SkBlurMaskFilter.cpp | 624 chmod +w SkBlurMaskFilter.cpp |
| 625 ./SkGradientShader.h:30:class SkGradientShader { | 625 ./SkGradientShader.h:30:class SkGradientShader { |
| 626 */ | 626 */ |
| 627 // save layer, bounder, looper | 627 // save layer, bounder, looper |
| 628 // matrix | 628 // matrix |
| 629 // clip /path/region | 629 // clip /path/region |
| 630 // bitmap proc shader ? | 630 // bitmap proc shader ? |
| 631 | 631 |
| 632 /* untested: | 632 /* untested: |
| 633 SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { | 633 SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { |
| 634 */ | 634 */ |
| 635 | 635 |
| 636 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) | 636 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) |
| 637 { | 637 { |
| 638 fClickPt.set(x, y); | 638 fClickPt.set(x, y); |
| 639 this->inval(NULL); | 639 this->inval(NULL); |
| 640 return this->INHERITED::onFindClickHandler(x, y); | 640 return this->INHERITED::onFindClickHandler(x, y); |
| 641 } | 641 } |
| 642 | 642 |
| 643 SkPathEffect* pathEffectTest() | 643 SkPathEffect* pathEffectTest() |
| 644 { | 644 { |
| 645 static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; | 645 static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; |
| 646 SkScalar gPhase = 0; | 646 SkScalar gPhase = 0; |
| 647 SkPath path; | 647 SkPath path; |
| 648 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 648 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 649 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 649 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
| 650 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 650 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 651 path.close(); | 651 path.close(); |
| 652 path.offset(SkIntToScalar(-6), 0); | 652 path.offset(SkIntToScalar(-6), 0); |
| 653 SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), | 653 SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), |
| 654 gPhase, SkPath1DPathEffect::kRotate_Style); | 654 gPhase, SkPath1DPathEffect::kRotate_Style); |
| 655 SkPathEffect* inner = new SkDiscretePathEffect(SkIntToScalar(2), | 655 SkPathEffect* inner = new SkDiscretePathEffect(SkIntToScalar(2), |
| 656 SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); | 656 SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); |
| 657 SkPathEffect* result = new SkComposePathEffect(outer, inner); | 657 SkPathEffect* result = new SkComposePathEffect(outer, inner); |
| 658 outer->unref(); | 658 outer->unref(); |
| 659 inner->unref(); | 659 inner->unref(); |
| 660 return result; | 660 return result; |
| 661 } | 661 } |
| 662 | 662 |
| 663 SkPathEffect* pathEffectTest2() // unsure this works (has no visible effect) | 663 SkPathEffect* pathEffectTest2() // unsure this works (has no visible effect) |
| 664 { | 664 { |
| 665 SkPathEffect* outer = new SkStrokePathEffect(SkIntToScalar(4), | 665 SkPathEffect* outer = new SkStrokePathEffect(SkIntToScalar(4), |
| 666 SkPaint::kStroke_Style, SkPaint::kMiter_Join, SkPaint::kButt_Cap); | 666 SkPaint::kStroke_Style, SkPaint::kMiter_Join, SkPaint::kButt_Cap); |
| 667 static const SkScalar intervals[] = {SkIntToScalar(1), SkIntToScalar(2), | 667 static const SkScalar intervals[] = {SkIntToScalar(1), SkIntToScalar(2), |
| 668 SkIntToScalar(2), SkIntToScalar(1)}; | 668 SkIntToScalar(2), SkIntToScalar(1)}; |
| 669 SkPathEffect* inner = new SkDashPathEffect(intervals, | 669 SkPathEffect* inner = new SkDashPathEffect(intervals, |
| 670 sizeof(intervals) / sizeof(intervals[0]), 0); | 670 sizeof(intervals) / sizeof(intervals[0]), 0); |
| 671 SkPathEffect* result = new SkSumPathEffect(outer, inner); | 671 SkPathEffect* result = new SkSumPathEffect(outer, inner); |
| 672 outer->unref(); | 672 outer->unref(); |
| 673 inner->unref(); | 673 inner->unref(); |
| 674 return result; | 674 return result; |
| 675 } | 675 } |
| 676 | 676 |
| 677 SkShader* shaderTest() | 677 SkShader* shaderTest() |
| 678 { | 678 { |
| 679 SkPoint pts[] = {0, 0, SkIntToScalar(100), 0 }; | 679 SkPoint pts[] = {0, 0, SkIntToScalar(100), 0 }; |
| 680 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; | 680 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
| 681 SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, | 681 SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, |
| 682 2, SkShader::kClamp_TileMode); | 682 2, SkShader::kClamp_TileMode); |
| 683 pts[1].set(0, SkIntToScalar(100)); | 683 pts[1].set(0, SkIntToScalar(100)); |
| 684 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; | 684 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; |
| 685 SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors2, NULL, | 685 SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors2, NULL, |
| 686 2, SkShader::kClamp_TileMode); | 686 2, SkShader::kClamp_TileMode); |
| 687 SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode); | 687 SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode); |
| 688 SkShader* result = new SkComposeShader(shaderA, shaderB, mode); | 688 SkShader* result = new SkComposeShader(shaderA, shaderB, mode); |
| 689 shaderA->unref(); | 689 shaderA->unref(); |
| 690 shaderB->unref(); | 690 shaderB->unref(); |
| 691 mode->unref(); | 691 mode->unref(); |
| 692 return result; | 692 return result; |
| 693 } | 693 } |
| 694 | 694 |
| 695 virtual void startTest() { | 695 virtual void startTest() { |
| 696 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/bugcirc.gif
", &fBug); | 696 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/bugcirc.gif
", &fBug); |
| 697 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/tbcirc.gif"
, &fTb); | 697 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/tbcirc.gif"
, &fTb); |
| 698 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/05psp04.gif
", &fTx); | 698 SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/05psp04.gif
", &fTx); |
| 699 } | 699 } |
| 700 | 700 |
| 701 void drawRaster(SkCanvas* canvas) | 701 void drawRaster(SkCanvas* canvas) |
| 702 { | 702 { |
| 703 for (int index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++) | 703 for (int index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++) |
| 704 drawOneRaster(canvas); | 704 drawOneRaster(canvas); |
| 705 } | 705 } |
| 706 | 706 |
| 707 void drawOneRaster(SkCanvas* canvas) | 707 void drawOneRaster(SkCanvas* canvas) |
| 708 { | 708 { |
| 709 canvas->save(); | 709 canvas->save(); |
| 710 | 710 |
| 711 SkScalar x = SkIntToScalar(20); | 711 SkScalar x = SkIntToScalar(20); |
| 712 SkScalar y = SkIntToScalar(40); | 712 SkScalar y = SkIntToScalar(40); |
| 713 SkPaint paint; | 713 SkPaint paint; |
| 714 | 714 |
| 715 paint.setAntiAlias(true); | 715 paint.setAntiAlias(true); |
| 716 paint.setTextSize(SkIntToScalar(48)); | 716 paint.setTextSize(SkIntToScalar(48)); |
| 717 paint.setTypeface(SkTypeface::CreateFromName("sans-serif", | 717 paint.setTypeface(SkTypeface::CreateFromName("sans-serif", |
| 718 SkTypeface::kBold)); | 718 SkTypeface::kBold)); |
| 719 | 719 |
| 720 SkString str("GOOGLE"); | 720 SkString str("GOOGLE"); |
| 721 | 721 |
| 722 for (int i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) | 722 for (int i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) |
| 723 { | 723 { |
| 724 apply_shader(&paint, i); | 724 apply_shader(&paint, i); |
| 725 | 725 |
| 726 // paint.setMaskFilter(NULL); | 726 // paint.setMaskFilter(NULL); |
| 727 // paint.setColor(SK_ColorBLACK); | 727 // paint.setColor(SK_ColorBLACK); |
| 728 | 728 |
| 729 #if 01 | 729 #if 01 |
| 730 int index = i % SK_ARRAY_COUNT(gLightingColors); | 730 int index = i % SK_ARRAY_COUNT(gLightingColors); |
| 731 paint.setColorFilter(SkColorFilter::CreateLightingFilter( | 731 paint.setColorFilter(SkColorFilter::CreateLightingFilter( |
| 732 gLightingColors[index].fMul, | 732 gLightingColors[index].fMul, |
| 733 gLightingColors[index].fAdd))->unref(); | 733 gLightingColors[index].fAdd))->unref(); |
| 734 #endif | 734 #endif |
| 735 | 735 |
| 736 canvas->drawText(str.c_str(), str.size(), x, y, paint); | 736 canvas->drawText(str.c_str(), str.size(), x, y, paint); |
| 737 SkRect oval = { x, y - SkIntToScalar(40), x + SkIntToScalar(40), y
}; | 737 SkRect oval = { x, y - SkIntToScalar(40), x + SkIntToScalar(40), y
}; |
| 738 paint.setStyle(SkPaint::kStroke_Style); | 738 paint.setStyle(SkPaint::kStroke_Style); |
| 739 canvas->drawOval(oval, paint); | 739 canvas->drawOval(oval, paint); |
| 740 paint.setStyle(SkPaint::kFill_Style); | 740 paint.setStyle(SkPaint::kFill_Style); |
| 741 | 741 |
| 742 y += paint.getFontSpacing(); | 742 y += paint.getFontSpacing(); |
| 743 } | 743 } |
| 744 | 744 |
| 745 canvas->restore(); | 745 canvas->restore(); |
| 746 | 746 |
| 747 if (1) { | 747 if (1) { |
| 748 SkAvoidXfermode mode(SK_ColorWHITE, 0xFF, | 748 SkAvoidXfermode mode(SK_ColorWHITE, 0xFF, |
| 749 SkAvoidXfermode::kTargetColor_Mode); | 749 SkAvoidXfermode::kTargetColor_Mode); |
| 750 SkPaint paint; | 750 SkPaint paint; |
| 751 x += SkIntToScalar(20); | 751 x += SkIntToScalar(20); |
| 752 SkRect r = { x, 0, x + SkIntToScalar(360), SkIntToScalar(700) }; | 752 SkRect r = { x, 0, x + SkIntToScalar(360), SkIntToScalar(700) }; |
| 753 paint.setXfermode(&mode); | 753 paint.setXfermode(&mode); |
| 754 paint.setColor(SK_ColorGREEN); | 754 paint.setColor(SK_ColorGREEN); |
| 755 paint.setAntiAlias(true); | 755 paint.setAntiAlias(true); |
| 756 canvas->drawOval(r, paint); | 756 canvas->drawOval(r, paint); |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 | 759 |
| 760 private: | 760 private: |
| 761 SkPoint fClickPt; | 761 SkPoint fClickPt; |
| 762 SkBitmap fBug, fTb, fTx; | 762 SkBitmap fBug, fTb, fTx; |
| 763 typedef SkView INHERITED; | 763 typedef SkView INHERITED; |
| 764 }; | 764 }; |
| 765 | 765 |
| 766 ////////////////////////////////////////////////////////////////////////////// | 766 ////////////////////////////////////////////////////////////////////////////// |
| 767 | 767 |
| 768 static SkView* MyFactory() { return new DemoView; } | 768 static SkView* MyFactory() { return new DemoView; } |
| 769 static SkViewRegister reg(MyFactory); | 769 static SkViewRegister reg(MyFactory); |
| 770 | 770 |
| OLD | NEW |