Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 } | 55 } |
| 56 | 56 |
| 57 static const SkColorType gColorTypes[] = { | 57 static const SkColorType gColorTypes[] = { |
| 58 kN32_SkColorType, | 58 kN32_SkColorType, |
| 59 kRGB_565_SkColorType, | 59 kRGB_565_SkColorType, |
| 60 }; | 60 }; |
| 61 static const int gWidth = 32; | 61 static const int gWidth = 32; |
| 62 static const int gHeight = 32; | 62 static const int gHeight = 32; |
| 63 | 63 |
| 64 class TilingView : public SampleView { | 64 class TilingView : public SampleView { |
| 65 SkPicture* fTextPicture; | 65 SkAutoTUnref<SkPicture> fTextPicture; |
| 66 SkBlurDrawLooper fLooper; | 66 SkBlurDrawLooper fLooper; |
| 67 public: | 67 public: |
| 68 TilingView() | 68 TilingView() |
| 69 : fLooper(0x88000000, | 69 : fLooper(0x88000000, |
| 70 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), | 70 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), |
| 71 SkIntToScalar(2), SkIntToScalar(2)) { | 71 SkIntToScalar(2), SkIntToScalar(2)) { |
| 72 fTextPicture = new SkPicture(); | |
| 73 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { | 72 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { |
| 74 makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight); | 73 makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 ~TilingView() { | 77 virtual ~TilingView() { |
| 79 fTextPicture->unref(); | |
| 80 } | 78 } |
| 81 | 79 |
| 82 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; | 80 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; |
| 83 | 81 |
| 84 protected: | 82 protected: |
| 85 // overrides from SkEventSink | 83 // overrides from SkEventSink |
| 86 virtual bool onQuery(SkEvent* evt) { | 84 virtual bool onQuery(SkEvent* evt) { |
| 87 if (SampleCode::TitleQ(*evt)) { | 85 if (SampleCode::TitleQ(*evt)) { |
| 88 SampleCode::TitleR(evt, "Tiling"); | 86 SampleCode::TitleR(evt, "Tiling"); |
| 89 return true; | 87 return true; |
| 90 } | 88 } |
| 91 return this->INHERITED::onQuery(evt); | 89 return this->INHERITED::onQuery(evt); |
| 92 } | 90 } |
| 93 | 91 |
| 94 virtual void onDrawContent(SkCanvas* canvas) { | 92 virtual void onDrawContent(SkCanvas* canvas) { |
| 95 SkRect r = { 0, 0, SkIntToScalar(gWidth*2), SkIntToScalar(gHeight*2) }; | 93 SkRect r = { 0, 0, SkIntToScalar(gWidth*2), SkIntToScalar(gHeight*2) }; |
| 96 | 94 |
| 97 static const char* gConfigNames[] = { "8888", "565", "4444" }; | 95 static const char* gConfigNames[] = { "8888", "565", "4444" }; |
| 98 | 96 |
| 99 static const bool gFilters[] = { false, true }; | 97 static const bool gFilters[] = { false, true }; |
| 100 static const char* gFilterNames[] = { "point", "bilinear" }; | 98 static const char* gFilterNames[] = { "point", "bilinear" }; |
| 101 | 99 |
| 102 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; | 100 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; |
| 103 static const char* gModeNames[] = { "C", "R", "M" }; | 101 static const char* gModeNames[] = { "C", "R", "M" }; |
| 104 | 102 |
| 105 SkScalar y = SkIntToScalar(24); | 103 SkScalar y = SkIntToScalar(24); |
| 106 SkScalar x = SkIntToScalar(10); | 104 SkScalar x = SkIntToScalar(10); |
| 107 | 105 |
| 106 SkPictureRecorder recorder; | |
| 108 SkCanvas* textCanvas = NULL; | 107 SkCanvas* textCanvas = NULL; |
| 109 if (fTextPicture->width() == 0) { | 108 if (fTextPicture->width() == 0) { |
|
bungeman-chromium
2014/04/15 21:07:08
fTextPicture is still uninitialized here!
| |
| 110 textCanvas = fTextPicture->beginRecording(1000, 1000); | 109 textCanvas = recorder.beginRecording(1000, 1000); |
| 111 } | 110 } |
| 112 | 111 |
| 113 if (textCanvas) { | 112 if (NULL != textCanvas) { |
| 114 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 113 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 115 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 114 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
| 116 SkPaint p; | 115 SkPaint p; |
| 117 SkString str; | 116 SkString str; |
| 118 p.setAntiAlias(true); | 117 p.setAntiAlias(true); |
| 119 p.setDither(true); | 118 p.setDither(true); |
| 120 p.setLooper(&fLooper); | 119 p.setLooper(&fLooper); |
| 121 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); | 120 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); |
| 122 | 121 |
| 123 p.setTextAlign(SkPaint::kCenter_Align); | 122 p.setTextAlign(SkPaint::kCenter_Align); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 153 p.setAntiAlias(true); | 152 p.setAntiAlias(true); |
| 154 p.setLooper(&fLooper); | 153 p.setLooper(&fLooper); |
| 155 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); | 154 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); |
| 156 textCanvas->drawText(str.c_str(), str.size(), x, y + r.heigh t() * 2 / 3, p); | 155 textCanvas->drawText(str.c_str(), str.size(), x, y + r.heigh t() * 2 / 3, p); |
| 157 } | 156 } |
| 158 | 157 |
| 159 y += r.height() * 4 / 3; | 158 y += r.height() * 4 / 3; |
| 160 } | 159 } |
| 161 } | 160 } |
| 162 | 161 |
| 162 fTextPicture.reset(recorder.endRecording()); | |
| 163 | |
| 163 canvas->drawPicture(*fTextPicture); | 164 canvas->drawPicture(*fTextPicture); |
| 164 } | 165 } |
| 165 | 166 |
| 166 private: | 167 private: |
| 167 typedef SampleView INHERITED; | 168 typedef SampleView INHERITED; |
| 168 }; | 169 }; |
| 169 | 170 |
| 170 ////////////////////////////////////////////////////////////////////////////// | 171 ////////////////////////////////////////////////////////////////////////////// |
| 171 | 172 |
| 172 static SkView* MyFactory() { return new TilingView; } | 173 static SkView* MyFactory() { return new TilingView; } |
| 173 static SkViewRegister reg(MyFactory); | 174 static SkViewRegister reg(MyFactory); |
| OLD | NEW |