| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkView.h" | 9 #include "SkView.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkFlattenableBuffers.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" |
| 12 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
| 13 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
| 14 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
| 15 #include "SkKernel33MaskFilter.h" | 16 #include "SkKernel33MaskFilter.h" |
| 16 #include "SkPath.h" | 17 #include "SkPath.h" |
| 17 #include "SkRandom.h" | 18 #include "SkRandom.h" |
| 18 #include "SkRegion.h" | 19 #include "SkRegion.h" |
| 19 #include "SkShader.h" | 20 #include "SkShader.h" |
| 20 #include "SkUtils.h" | 21 #include "SkUtils.h" |
| 21 #include "SkColorPriv.h" | 22 #include "SkColorPriv.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 virtual void toString(SkString* str) const SK_OVERRIDE { | 53 virtual void toString(SkString* str) const SK_OVERRIDE { |
| 53 str->append("ReduceNoise: ("); | 54 str->append("ReduceNoise: ("); |
| 54 this->INHERITED::toString(str); | 55 this->INHERITED::toString(str); |
| 55 str->append(")"); | 56 str->append(")"); |
| 56 } | 57 } |
| 57 #endif | 58 #endif |
| 58 | 59 |
| 59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(ReduceNoise) | 60 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(ReduceNoise) |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 ReduceNoise(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {} | 63 ReduceNoise(SkReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {} |
| 63 | 64 |
| 64 typedef SkKernel33ProcMaskFilter INHERITED; | 65 typedef SkKernel33ProcMaskFilter INHERITED; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 class Darken : public SkKernel33ProcMaskFilter { | 68 class Darken : public SkKernel33ProcMaskFilter { |
| 68 public: | 69 public: |
| 69 Darken(int percent256) : SkKernel33ProcMaskFilter(percent256) {} | 70 Darken(int percent256) : SkKernel33ProcMaskFilter(percent256) {} |
| 70 virtual uint8_t computeValue(uint8_t* const* srcRows) const { | 71 virtual uint8_t computeValue(uint8_t* const* srcRows) const { |
| 71 int c = srcRows[1][1]; | 72 int c = srcRows[1][1]; |
| 72 float f = c / 255.f; | 73 float f = c / 255.f; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 84 virtual void toString(SkString* str) const SK_OVERRIDE { | 85 virtual void toString(SkString* str) const SK_OVERRIDE { |
| 85 str->append("Darken: ("); | 86 str->append("Darken: ("); |
| 86 this->INHERITED::toString(str); | 87 this->INHERITED::toString(str); |
| 87 str->append(")"); | 88 str->append(")"); |
| 88 } | 89 } |
| 89 #endif | 90 #endif |
| 90 | 91 |
| 91 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Darken) | 92 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Darken) |
| 92 | 93 |
| 93 private: | 94 private: |
| 94 Darken(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {} | 95 Darken(SkReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {} |
| 95 | 96 |
| 96 typedef SkKernel33ProcMaskFilter INHERITED; | 97 typedef SkKernel33ProcMaskFilter INHERITED; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 static SkMaskFilter* makemf() { return new Darken(0x30); } | 100 static SkMaskFilter* makemf() { return new Darken(0x30); } |
| 100 | 101 |
| 101 static void test_breakText() { | 102 static void test_breakText() { |
| 102 SkPaint paint; | 103 SkPaint paint; |
| 103 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; | 104 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; |
| 104 size_t length = strlen(text); | 105 size_t length = strlen(text); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 137 |
| 137 static SkRandom gRand; | 138 static SkRandom gRand; |
| 138 | 139 |
| 139 class SkPowerMode : public SkXfermode { | 140 class SkPowerMode : public SkXfermode { |
| 140 public: | 141 public: |
| 141 SkPowerMode(SkScalar exponent) { this->init(exponent); } | 142 SkPowerMode(SkScalar exponent) { this->init(exponent); } |
| 142 | 143 |
| 143 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, | 144 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
| 144 const SkAlpha aa[]) const SK_OVERRIDE; | 145 const SkAlpha aa[]) const SK_OVERRIDE; |
| 145 | 146 |
| 146 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); | 147 typedef SkFlattenable* (*Factory)(SkReadBuffer&); |
| 147 | 148 |
| 148 SK_DEVELOPER_TO_STRING() | 149 SK_DEVELOPER_TO_STRING() |
| 149 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPowerMode) | 150 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPowerMode) |
| 150 | 151 |
| 151 private: | 152 private: |
| 152 SkScalar fExp; // user's value | 153 SkScalar fExp; // user's value |
| 153 uint8_t fTable[256]; // cache | 154 uint8_t fTable[256]; // cache |
| 154 | 155 |
| 155 void init(SkScalar exponent); | 156 void init(SkScalar exponent); |
| 156 SkPowerMode(SkFlattenableReadBuffer& b) : INHERITED(b) { | 157 SkPowerMode(SkReadBuffer& b) : INHERITED(b) { |
| 157 // read the exponent | 158 // read the exponent |
| 158 this->init(SkFixedToScalar(b.readFixed())); | 159 this->init(SkFixedToScalar(b.readFixed())); |
| 159 } | 160 } |
| 160 virtual void flatten(SkFlattenableWriteBuffer& b) const SK_OVERRIDE { | 161 virtual void flatten(SkWriteBuffer& b) const SK_OVERRIDE { |
| 161 this->INHERITED::flatten(b); | 162 this->INHERITED::flatten(b); |
| 162 b.writeFixed(SkScalarToFixed(fExp)); | 163 b.writeFixed(SkScalarToFixed(fExp)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 typedef SkXfermode INHERITED; | 166 typedef SkXfermode INHERITED; |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 void SkPowerMode::init(SkScalar e) { | 169 void SkPowerMode::init(SkScalar e) { |
| 169 fExp = e; | 170 fExp = e; |
| 170 float ee = SkScalarToFloat(e); | 171 float ee = SkScalarToFloat(e); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 SkScalar fClickX; | 351 SkScalar fClickX; |
| 351 SkMaskFilter* fMF; | 352 SkMaskFilter* fMF; |
| 352 | 353 |
| 353 typedef SampleView INHERITED; | 354 typedef SampleView INHERITED; |
| 354 }; | 355 }; |
| 355 | 356 |
| 356 ////////////////////////////////////////////////////////////////////////////// | 357 ////////////////////////////////////////////////////////////////////////////// |
| 357 | 358 |
| 358 static SkView* MyFactory() { return new TextSpeedView; } | 359 static SkView* MyFactory() { return new TextSpeedView; } |
| 359 static SkViewRegister reg(MyFactory); | 360 static SkViewRegister reg(MyFactory); |
| OLD | NEW |