| 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 "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 #include "cc/content_layer_client.h" | 6 #include "cc/content_layer_client.h" |
| 7 #include "cc/picture.h" | 7 #include "cc/picture.h" |
| 8 #include "cc/rendering_stats.h" | 8 #include "cc/rendering_stats.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkData.h" | 10 #include "third_party/skia/include/core/SkData.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 scoped_refptr<Picture> Picture::Clone() const { | 44 scoped_refptr<Picture> Picture::Clone() const { |
| 45 // SkPicture is not thread-safe to rasterize with, so return a thread-safe | 45 // SkPicture is not thread-safe to rasterize with, so return a thread-safe |
| 46 // clone of it. | 46 // clone of it. |
| 47 DCHECK(picture_); | 47 DCHECK(picture_); |
| 48 skia::RefPtr<SkPicture> clone = skia::AdoptRef(picture_->clone()); | 48 skia::RefPtr<SkPicture> clone = skia::AdoptRef(picture_->clone()); |
| 49 return make_scoped_refptr(new Picture(clone, layer_rect_, opaque_rect_)); | 49 return make_scoped_refptr(new Picture(clone, layer_rect_, opaque_rect_)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Picture::Record(ContentLayerClient* painter, | 52 void Picture::Record(ContentLayerClient* painter, |
| 53 RenderingStats& stats) { | 53 RenderingStats* stats) { |
| 54 TRACE_EVENT2("cc", "Picture::Record", | 54 TRACE_EVENT2("cc", "Picture::Record", |
| 55 "width", layer_rect_.width(), "height", layer_rect_.height()); | 55 "width", layer_rect_.width(), "height", layer_rect_.height()); |
| 56 | 56 |
| 57 // Record() should only be called once. | 57 // Record() should only be called once. |
| 58 DCHECK(!picture_); | 58 DCHECK(!picture_); |
| 59 picture_ = skia::AdoptRef(new SkTileGridPicture( | 59 picture_ = skia::AdoptRef(new SkTileGridPicture( |
| 60 tileGridSize, tileGridSize, layer_rect_.width(), layer_rect_.height())); | 60 tileGridSize, tileGridSize, layer_rect_.width(), layer_rect_.height())); |
| 61 | 61 |
| 62 SkCanvas* canvas = picture_->beginRecording( | 62 SkCanvas* canvas = picture_->beginRecording( |
| 63 layer_rect_.width(), | 63 layer_rect_.width(), |
| 64 layer_rect_.height(), | 64 layer_rect_.height(), |
| 65 SkPicture::kUsePathBoundsForClip_RecordingFlag | | 65 SkPicture::kUsePathBoundsForClip_RecordingFlag | |
| 66 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); | 66 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); |
| 67 | 67 |
| 68 canvas->save(); | 68 canvas->save(); |
| 69 canvas->translate(SkFloatToScalar(-layer_rect_.x()), | 69 canvas->translate(SkFloatToScalar(-layer_rect_.x()), |
| 70 SkFloatToScalar(-layer_rect_.y())); | 70 SkFloatToScalar(-layer_rect_.y())); |
| 71 | 71 |
| 72 SkPaint paint; | 72 SkPaint paint; |
| 73 paint.setAntiAlias(false); | 73 paint.setAntiAlias(false); |
| 74 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 74 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| 75 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(), | 75 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(), |
| 76 layer_rect_.y(), | 76 layer_rect_.y(), |
| 77 layer_rect_.width(), | 77 layer_rect_.width(), |
| 78 layer_rect_.height()); | 78 layer_rect_.height()); |
| 79 canvas->clipRect(layer_skrect); | 79 canvas->clipRect(layer_skrect); |
| 80 canvas->drawRect(layer_skrect, paint); | 80 canvas->drawRect(layer_skrect, paint); |
| 81 | 81 |
| 82 gfx::RectF opaque_layer_rect; | 82 gfx::RectF opaque_layer_rect; |
| 83 base::TimeTicks beginPaintTime = base::TimeTicks::Now(); | 83 base::TimeTicks begin_paint_time; |
| 84 if (stats) |
| 85 begin_paint_time = base::TimeTicks::Now(); |
| 84 painter->paintContents(canvas, layer_rect_, opaque_layer_rect); | 86 painter->paintContents(canvas, layer_rect_, opaque_layer_rect); |
| 85 stats.totalPaintTime += base::TimeTicks::Now() - beginPaintTime; | 87 if (stats) { |
| 86 stats.totalPixelsPainted += layer_rect_.width() * | 88 stats->totalPaintTime += base::TimeTicks::Now() - begin_paint_time; |
| 87 layer_rect_.height(); | 89 stats->totalPixelsPainted += |
| 90 layer_rect_.width() * layer_rect_.height(); |
| 91 } |
| 88 | 92 |
| 89 canvas->restore(); | 93 canvas->restore(); |
| 90 picture_->endRecording(); | 94 picture_->endRecording(); |
| 91 | 95 |
| 92 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); | 96 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void Picture::Raster( | 99 void Picture::Raster( |
| 96 SkCanvas* canvas, | 100 SkCanvas* canvas, |
| 97 gfx::Rect content_rect, | 101 gfx::Rect content_rect, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (*refs && (*refs)->getURI() && !strncmp( | 134 if (*refs && (*refs)->getURI() && !strncmp( |
| 131 (*refs)->getURI(), labelLazyDecoded, 4)) { | 135 (*refs)->getURI(), labelLazyDecoded, 4)) { |
| 132 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); | 136 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); |
| 133 } | 137 } |
| 134 refs++; | 138 refs++; |
| 135 } | 139 } |
| 136 pixel_refs->unref(); | 140 pixel_refs->unref(); |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace cc | 143 } // namespace cc |
| OLD | NEW |