| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "gm.h" | 8 #include "gm.h" |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkShader.h" | 13 #include "SkShader.h" |
| 14 #include "SkTextBlob.h" | 14 #include "SkTextBlob.h" |
| 15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 | 17 |
| 18 // This GM exercises drawTextBlob offset vs. shader space behavior. | 18 // This GM exercises drawTextBlob offset vs. shader space behavior. |
| 19 class TextBlobShaderGM : public skiagm::GM { | 19 class TextBlobShaderGM : public skiagm::GM { |
| 20 public: | 20 public: |
| 21 TextBlobShaderGM(const char* txt) { | 21 TextBlobShaderGM(const char* txt) { |
| 22 SkPaint p; | 22 SkPaint p; |
| 23 size_t txtLen = strlen(txt); | 23 size_t txtLen = strlen(txt); |
| 24 fGlyphs.append(p.textToGlyphs(txt, txtLen, NULL)); | 24 fGlyphs.append(p.textToGlyphs(txt, txtLen, NULL)); |
| 25 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); | 25 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 | 29 |
| 30 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 30 void onOnceBeforeDraw() SK_OVERRIDE { |
| 31 SkPaint p; | 31 SkPaint p; |
| 32 p.setAntiAlias(true); | 32 p.setAntiAlias(true); |
| 33 p.setSubpixelText(true); | 33 p.setSubpixelText(true); |
| 34 p.setTextSize(30); | 34 p.setTextSize(30); |
| 35 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 35 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 36 | 36 |
| 37 SkTextBlobBuilder builder; | 37 SkTextBlobBuilder builder; |
| 38 int glyphCount = fGlyphs.count(); | 38 int glyphCount = fGlyphs.count(); |
| 39 const SkTextBlobBuilder::RunBuffer* run; | 39 const SkTextBlobBuilder::RunBuffer* run; |
| 40 | 40 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 SkISize sz = this->onISize(); | 68 SkISize sz = this->onISize(); |
| 69 fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar
(sz.width() / 2), | 69 fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar
(sz.width() / 2), |
| 70 SkIntToScalar
(sz.height() / 2)), | 70 SkIntToScalar
(sz.height() / 2)), |
| 71 sz.width() * .66f, colors,
pos, | 71 sz.width() * .66f, colors,
pos, |
| 72 SK_ARRAY_COUNT(colors), | 72 SK_ARRAY_COUNT(colors), |
| 73 SkShader::kRepeat_TileMode)
); | 73 SkShader::kRepeat_TileMode)
); |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 76 uint32_t onGetFlags() const SK_OVERRIDE { |
| 77 return kSkip565_Flag; | 77 return kSkip565_Flag; |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual SkString onShortName() SK_OVERRIDE { | 80 SkString onShortName() SK_OVERRIDE { |
| 81 return SkString("textblobshader"); | 81 return SkString("textblobshader"); |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual SkISize onISize() SK_OVERRIDE { | 84 SkISize onISize() SK_OVERRIDE { |
| 85 return SkISize::Make(640, 480); | 85 return SkISize::Make(640, 480); |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 88 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 89 SkPaint p; | 89 SkPaint p; |
| 90 p.setStyle(SkPaint::kFill_Style); | 90 p.setStyle(SkPaint::kFill_Style); |
| 91 p.setShader(fShader); | 91 p.setShader(fShader); |
| 92 | 92 |
| 93 SkISize sz = this->onISize(); | 93 SkISize sz = this->onISize(); |
| 94 static const int kXCount = 4; | 94 static const int kXCount = 4; |
| 95 static const int kYCount = 3; | 95 static const int kYCount = 3; |
| 96 for (int i = 0; i < kXCount; ++i) { | 96 for (int i = 0; i < kXCount; ++i) { |
| 97 for (int j = 0; j < kYCount; ++j) { | 97 for (int j = 0; j < kYCount; ++j) { |
| 98 canvas->drawTextBlob(fBlob, | 98 canvas->drawTextBlob(fBlob, |
| 99 SkIntToScalar(i * sz.width() / kXCount), | 99 SkIntToScalar(i * sz.width() / kXCount), |
| 100 SkIntToScalar(j * sz.height() / kYCount), | 100 SkIntToScalar(j * sz.height() / kYCount), |
| 101 p); | 101 p); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 SkTDArray<uint16_t> fGlyphs; | 107 SkTDArray<uint16_t> fGlyphs; |
| 108 SkAutoTUnref<const SkTextBlob> fBlob; | 108 SkAutoTUnref<const SkTextBlob> fBlob; |
| 109 SkAutoTUnref<SkShader> fShader; | 109 SkAutoTUnref<SkShader> fShader; |
| 110 | 110 |
| 111 typedef skiagm::GM INHERITED; | 111 typedef skiagm::GM INHERITED; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 DEF_GM( return SkNEW_ARGS(TextBlobShaderGM, ("Blobber")); ) | 114 DEF_GM( return SkNEW_ARGS(TextBlobShaderGM, ("Blobber")); ) |
| OLD | NEW |