Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SampleCode.h" | |
| 9 #include "SkPaint.h" | |
| 10 #include "SkCanvas.h" | |
| 11 #include "SkStream.h" | |
| 12 #include "SkImageDecoder.h" | |
| 13 #include "Resources.h" | |
| 14 | |
| 15 class ImageView : public SampleView { | |
| 16 public: | |
| 17 ImageView(const char imageFilename[]) { | |
|
scroggo
2015/05/18 14:03:59
nit: Skia uses a four space indent.
Not sure if y
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
| |
| 18 SkString resourcePath = GetResourcePath(imageFilename); | |
|
scroggo
2015/05/18 14:03:59
It threw me off for a second that this is lined up
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
| |
| 19 SkImageDecoder* codec = NULL; | |
| 20 SkFILEStream stream(resourcePath.c_str()); | |
| 21 if (stream.isValid()) { | |
| 22 codec = SkImageDecoder::Factory(&stream); | |
| 23 } | |
| 24 if (codec) { | |
| 25 stream.rewind(); | |
| 26 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDeco dePixels_Mode); | |
| 27 SkDELETE(codec); | |
| 28 } else { | |
|
scroggo
2015/05/18 14:03:59
This should line up with the if statement.
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
| |
| 29 fBM.allocN32Pixels(1, 1); | |
| 30 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | |
|
scroggo
2015/05/18 14:03:59
This is just an example, so it doesn't matter too
emmaleeroach
2015/05/18 20:04:28
On 2015/05/18 14:03:59, scroggo wrote:
> This is j
scroggo
2015/05/18 20:43:18
Yes :)
| |
| 31 } | |
| 32 } | |
| 33 | |
| 34 protected: | |
| 35 SkBitmap fBM; | |
|
scroggo
2015/05/18 14:03:59
Generally, this should be private unless you want
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> Generally
| |
| 36 | |
| 37 virtual bool onQuery(SkEvent* evt) { | |
|
scroggo
2015/05/18 14:03:59
The spacing is wrong for much of this file. Genera
emmaleeroach
2015/05/18 20:04:28
On 2015/05/18 14:03:59, scroggo wrote:
> The spaci
| |
| 38 if (SampleCode::TitleQ(*evt)) { | |
| 39 SampleCode::TitleR(evt, "ImageView"); | |
| 40 return true; | |
| 41 } | |
| 42 return this->INHERITED::onQuery(evt); | |
| 43 } | |
| 44 | |
| 45 virtual void onDrawContent(SkCanvas* canvas) { | |
| 46 | |
| 47 canvas->drawColor(SK_ColorWHITE); | |
| 48 | |
| 49 SkPaint paint; | |
| 50 | |
| 51 paint.setAntiAlias(true); | |
| 52 paint.setTextSize(48); | |
| 53 paint.setFilterQuality(kHigh_SkFilterQuality); | |
| 54 canvas->save(); | |
| 55 canvas->drawBitmap( fBM, 50, 50, &paint ); | |
| 56 canvas->restore(); | |
| 57 | |
| 58 paint.setColor(SK_ColorRED); | |
| 59 paint.setAntiAlias(true); | |
| 60 paint.setStyle(SkPaint::kStroke_Style); | |
| 61 paint.setStrokeWidth(10); | |
| 62 canvas->drawLine(20, 20, 100, 100, paint); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 typedef SampleView INHERITED; | |
| 67 | |
| 68 }; | |
| 69 | |
| 70 static SkView* MyFactory() { return new ImageView("yellow_rose.png"); } | |
| 71 static SkViewRegister reg(MyFactory); | |
| OLD | NEW |