Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | |
| 8 #include "cc/content_layer_client.h" | |
| 7 #include "cc/picture.h" | 9 #include "cc/picture.h" |
| 10 #include "cc/rendering_stats.h" | |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | |
| 12 #include "ui/gfx/rect_conversions.h" | |
| 8 | 13 |
| 9 namespace cc { | 14 namespace cc { |
| 10 | 15 |
| 11 Picture::Picture() { | 16 scoped_refptr<Picture> Picture::Create() { |
| 17 return make_scoped_refptr(new Picture()); | |
| 18 } | |
| 19 | |
| 20 Picture::Picture() : picture_(new SkPicture()) { | |
| 21 } | |
| 22 | |
| 23 Picture::Picture(SkPicture* picture, gfx::Rect layer_rect, | |
| 24 gfx::Rect opaque_rect) : | |
| 25 layer_rect_(layer_rect), | |
| 26 opaque_rect_(opaque_rect), | |
| 27 picture_(picture) { | |
| 12 } | 28 } |
| 13 | 29 |
| 14 Picture::~Picture() { | 30 Picture::~Picture() { |
| 15 } | 31 } |
| 16 | 32 |
| 33 scoped_refptr<Picture> Picture::Clone() { | |
| 34 // SkPicture is not thread-safe to rasterize with, so return a thread-safe | |
| 35 // clone of it. | |
| 36 SkPicture* clone = picture_->clone(); | |
| 37 return make_scoped_refptr(new Picture(clone, layer_rect_, opaque_rect_)); | |
| 38 } | |
| 39 | |
| 40 void Picture::Record(ContentLayerClient* painter, gfx::Rect layer_rect, | |
| 41 RenderingStats& stats) { | |
| 42 TRACE_EVENT0("cc", "Picture::Record"); | |
| 43 SkCanvas* canvas = picture_->beginRecording( | |
| 44 layer_rect.width(), | |
| 45 layer_rect.height(), | |
| 46 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); | |
| 47 | |
| 48 canvas->save(); | |
| 49 canvas->translate(SkFloatToScalar(-layer_rect.x()), | |
| 50 SkFloatToScalar(-layer_rect.y())); | |
| 51 | |
| 52 SkPaint paint; | |
| 53 paint.setAntiAlias(false); | |
| 54 paint.setXfermodeMode(SkXfermode::kClear_Mode); | |
| 55 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect.x(), | |
| 56 layer_rect.y(), | |
| 57 layer_rect.width(), | |
| 58 layer_rect.height()); | |
| 59 canvas->drawRect(layer_skrect, paint); | |
| 60 canvas->clipRect(layer_skrect); | |
| 61 | |
| 62 gfx::RectF opaque_layer_rect; | |
| 63 base::TimeTicks beginPaintTime = base::TimeTicks::Now(); | |
| 64 painter->paintContents(canvas, layer_rect, opaque_layer_rect); | |
| 65 double delta = (base::TimeTicks::Now() - beginPaintTime).InSecondsF(); | |
| 66 stats.totalPaintTimeInSeconds += delta; | |
| 67 | |
| 68 canvas->restore(); | |
| 69 picture_->endRecording(); | |
| 70 | |
| 71 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); | |
| 72 layer_rect_ = layer_rect; | |
| 73 } | |
| 74 | |
| 75 void Picture::Raster(SkCanvas* canvas) { | |
| 76 TRACE_EVENT0("cc", "Picture::Raster"); | |
| 77 canvas->translate(layer_rect_.x(), layer_rect_.y()); | |
| 78 canvas->save(); | |
|
slavi
2012/11/09 23:56:21
No need to save/resore here. See comment of SkCanv
enne (OOO)
2012/11/09 23:59:20
Oh, thanks! :)
| |
| 79 canvas->drawPicture(*picture_); | |
| 80 canvas->restore(); | |
| 81 } | |
| 82 | |
| 17 } // namespace cc | 83 } // namespace cc |
| OLD | NEW |