| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCanvasDrawable.h" | 9 #include "SkDrawable.h" |
| 10 #include "SkThread.h" | 10 #include "SkThread.h" |
| 11 | 11 |
| 12 static int32_t next_generation_id() { | 12 static int32_t next_generation_id() { |
| 13 static int32_t gCanvasDrawableGenerationID; | 13 static int32_t gCanvasDrawableGenerationID; |
| 14 | 14 |
| 15 // do a loop in case our global wraps around, as we never want to | 15 // do a loop in case our global wraps around, as we never want to |
| 16 // return a 0 | 16 // return a 0 |
| 17 int32_t genID; | 17 int32_t genID; |
| 18 do { | 18 do { |
| 19 genID = sk_atomic_inc(&gCanvasDrawableGenerationID) + 1; | 19 genID = sk_atomic_inc(&gCanvasDrawableGenerationID) + 1; |
| 20 } while (0 == genID); | 20 } while (0 == genID); |
| 21 return genID; | 21 return genID; |
| 22 } | 22 } |
| 23 | 23 |
| 24 SkCanvasDrawable::SkCanvasDrawable() : fGenerationID(0) {} | 24 SkDrawable::SkDrawable() : fGenerationID(0) {} |
| 25 | 25 |
| 26 static void draw_bbox(SkCanvas* canvas, const SkRect& r) { | 26 static void draw_bbox(SkCanvas* canvas, const SkRect& r) { |
| 27 SkPaint paint; | 27 SkPaint paint; |
| 28 paint.setStyle(SkPaint::kStroke_Style); | 28 paint.setStyle(SkPaint::kStroke_Style); |
| 29 paint.setColor(0xFFFF7088); | 29 paint.setColor(0xFFFF7088); |
| 30 canvas->drawRect(r, paint); | 30 canvas->drawRect(r, paint); |
| 31 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); | 31 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); |
| 32 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); | 32 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SkCanvasDrawable::draw(SkCanvas* canvas) { | 35 void SkDrawable::draw(SkCanvas* canvas) { |
| 36 SkAutoCanvasRestore acr(canvas, true); | 36 SkAutoCanvasRestore acr(canvas, true); |
| 37 this->onDraw(canvas); | 37 this->onDraw(canvas); |
| 38 | 38 |
| 39 if (false) { | 39 if (false) { |
| 40 draw_bbox(canvas, this->getBounds()); | 40 draw_bbox(canvas, this->getBounds()); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 SkPicture* SkCanvasDrawable::newPictureSnapshot() { | 44 SkPicture* SkDrawable::newPictureSnapshot() { |
| 45 return this->onNewPictureSnapshot(); | 45 return this->onNewPictureSnapshot(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 uint32_t SkCanvasDrawable::getGenerationID() { | 48 uint32_t SkDrawable::getGenerationID() { |
| 49 if (0 == fGenerationID) { | 49 if (0 == fGenerationID) { |
| 50 fGenerationID = next_generation_id(); | 50 fGenerationID = next_generation_id(); |
| 51 } | 51 } |
| 52 return fGenerationID; | 52 return fGenerationID; |
| 53 } | 53 } |
| 54 | 54 |
| 55 SkRect SkCanvasDrawable::getBounds() { | 55 SkRect SkDrawable::getBounds() { |
| 56 return this->onGetBounds(); | 56 return this->onGetBounds(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SkCanvasDrawable::notifyDrawingChanged() { | 59 void SkDrawable::notifyDrawingChanged() { |
| 60 fGenerationID = 0; | 60 fGenerationID = 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 ////////////////////////////////////////////////////////////////////////////////
///////// | 63 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 64 | 64 |
| 65 #include "SkPictureRecorder.h" | 65 #include "SkPictureRecorder.h" |
| 66 | 66 |
| 67 SkPicture* SkCanvasDrawable::onNewPictureSnapshot() { | 67 SkPicture* SkDrawable::onNewPictureSnapshot() { |
| 68 SkPictureRecorder recorder; | 68 SkPictureRecorder recorder; |
| 69 | 69 |
| 70 const SkRect bounds = this->getBounds(); | 70 const SkRect bounds = this->getBounds(); |
| 71 SkCanvas* canvas = recorder.beginRecording(bounds, NULL, 0); | 71 SkCanvas* canvas = recorder.beginRecording(bounds, NULL, 0); |
| 72 this->draw(canvas); | 72 this->draw(canvas); |
| 73 if (false) { | 73 if (false) { |
| 74 draw_bbox(canvas, bounds); | 74 draw_bbox(canvas, bounds); |
| 75 } | 75 } |
| 76 return recorder.endRecording(); | 76 return recorder.endRecording(); |
| 77 } | 77 } |
| OLD | NEW |