Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: src/core/SkCanvasDrawable.cpp

Issue 736583004: allow pictures to have a full bounds (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use new roundOut Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkCanvasDrawable.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 SkCanvasDrawable::SkCanvasDrawable() : fGenerationID(0) {}
25 25
26 static void draw_bbox(SkCanvas* canvas, const SkRect& r) {
27 SkPaint paint;
28 paint.setStyle(SkPaint::kStroke_Style);
29 paint.setColor(0xFFFF7088);
30 canvas->drawRect(r, 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);
33 }
34
26 void SkCanvasDrawable::draw(SkCanvas* canvas) { 35 void SkCanvasDrawable::draw(SkCanvas* canvas) {
27 SkAutoCanvasRestore acr(canvas, true); 36 SkAutoCanvasRestore acr(canvas, true);
28 this->onDraw(canvas); 37 this->onDraw(canvas);
38
39 if (false) {
40 draw_bbox(canvas, this->getBounds());
f(malita) 2014/11/19 15:02:27 This could be a debugger option. (I'm planning to
mtklein 2014/11/19 15:16:00 This SGTM. This would be pretty easy to do with a
41 }
29 } 42 }
30 43
31 SkPicture* SkCanvasDrawable::newPictureSnapshot(SkBBHFactory* bbhFactory, uint32 _t recordFlags) { 44 SkPicture* SkCanvasDrawable::newPictureSnapshot(SkBBHFactory* bbhFactory, uint32 _t recordFlags) {
32 return this->onNewPictureSnapshot(bbhFactory, recordFlags); 45 return this->onNewPictureSnapshot(bbhFactory, recordFlags);
33 } 46 }
34 47
35 uint32_t SkCanvasDrawable::getGenerationID() { 48 uint32_t SkCanvasDrawable::getGenerationID() {
36 if (0 == fGenerationID) { 49 if (0 == fGenerationID) {
37 fGenerationID = next_generation_id(); 50 fGenerationID = next_generation_id();
38 } 51 }
39 return fGenerationID; 52 return fGenerationID;
40 } 53 }
41 54
42 SkRect SkCanvasDrawable::getBounds() { 55 SkRect SkCanvasDrawable::getBounds() {
43 return this->onGetBounds(); 56 return this->onGetBounds();
44 } 57 }
45 58
46 void SkCanvasDrawable::notifyDrawingChanged() { 59 void SkCanvasDrawable::notifyDrawingChanged() {
47 fGenerationID = 0; 60 fGenerationID = 0;
48 } 61 }
49 62
50 //////////////////////////////////////////////////////////////////////////////// ///////// 63 //////////////////////////////////////////////////////////////////////////////// /////////
51 64
52 #include "SkPictureRecorder.h" 65 #include "SkPictureRecorder.h"
53 66
54 SkPicture* SkCanvasDrawable::onNewPictureSnapshot(SkBBHFactory* bbhFactory, uint 32_t recordFlags) { 67 SkPicture* SkCanvasDrawable::onNewPictureSnapshot(SkBBHFactory* bbhFactory, uint 32_t recordFlags) {
68 SkPictureRecorder recorder;
69
55 const SkRect bounds = this->getBounds(); 70 const SkRect bounds = this->getBounds();
56 SkPictureRecorder recorder; 71 SkCanvas* canvas = recorder.beginRecording(bounds, bbhFactory, recordFlags);
57 this->draw(recorder.beginRecording(bounds.width(), bounds.height(), bbhFacto ry, recordFlags)); 72 this->draw(canvas);
73 if (false) {
74 draw_bbox(canvas, bounds);
75 }
58 return recorder.endRecording(); 76 return recorder.endRecording();
59 } 77 }
OLDNEW
« samplecode/SampleArc.cpp ('K') | « src/core/SkCanvas.cpp ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698