| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 7 |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| 11 #include "SkView.h" | 11 #include "SkView.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkUtils.h" | 13 #include "SkUtils.h" |
| 14 | 14 |
| 15 static SkBitmap make_bitmap() { | 15 static SkBitmap make_bitmap() { |
| 16 const int N = 1; | 16 const int N = 1; |
| 17 | 17 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 class TinyBitmapView : public SampleView { | 41 class TinyBitmapView : public SampleView { |
| 42 SkBitmap fBM; | 42 SkBitmap fBM; |
| 43 public: | 43 public: |
| 44 TinyBitmapView() { | 44 TinyBitmapView() { |
| 45 fBM = make_bitmap(); | 45 fBM = make_bitmap(); |
| 46 this->setBGColor(0xFFDDDDDD); | 46 this->setBGColor(0xFFDDDDDD); |
| 47 } | 47 } |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 // overrides from SkEventSink | 50 bool onQuery(SkEvent* evt) override { |
| 51 virtual bool onQuery(SkEvent* evt) { | |
| 52 if (SampleCode::TitleQ(*evt)) { | 51 if (SampleCode::TitleQ(*evt)) { |
| 53 SampleCode::TitleR(evt, "TinyBitmap"); | 52 SampleCode::TitleR(evt, "TinyBitmap"); |
| 54 return true; | 53 return true; |
| 55 } | 54 } |
| 56 return this->INHERITED::onQuery(evt); | 55 return this->INHERITED::onQuery(evt); |
| 57 } | 56 } |
| 58 | 57 |
| 59 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { | 58 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { |
| 60 SkAutoLockPixels alp(*bm); // needed for ctable | 59 SkAutoLockPixels alp(*bm); // needed for ctable |
| 61 bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 60 bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 62 } | 61 } |
| 63 | 62 |
| 64 virtual void onDrawContent(SkCanvas* canvas) { | 63 void onDrawContent(SkCanvas* canvas) override { |
| 65 SkShader* s = SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMo
de, | |
| 66 SkShader::kMirror_TileMode); | |
| 67 SkPaint paint; | 64 SkPaint paint; |
| 68 paint.setShader(s)->unref(); | 65 paint.setShader(SkShader::MakeBitmapShader(fBM, SkShader::kRepeat_TileMo
de, |
| 66 SkShader::kMirror_TileMode)); |
| 69 canvas->drawPaint(paint); | 67 canvas->drawPaint(paint); |
| 70 } | 68 } |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 typedef SkView INHERITED; | 71 typedef SkView INHERITED; |
| 74 }; | 72 }; |
| 75 | 73 |
| 76 ////////////////////////////////////////////////////////////////////////////// | 74 ////////////////////////////////////////////////////////////////////////////// |
| 77 | 75 |
| 78 static SkView* MyFactory() { return new TinyBitmapView; } | 76 static SkView* MyFactory() { return new TinyBitmapView; } |
| 79 static SkViewRegister reg(MyFactory); | 77 static SkViewRegister reg(MyFactory); |
| OLD | NEW |