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

Side by Side Diff: cc/picture.cc

Issue 11299324: Make PicturePile pile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix signed/unsigned mismatch warning Created 8 years 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
« no previous file with comments | « cc/picture.h ('k') | cc/picture_pile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gfx/rect_conversions.h" 10 #include "ui/gfx/rect_conversions.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 scoped_refptr<Picture> Picture::Create() { 14 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) {
15 return make_scoped_refptr(new Picture()); 15 return make_scoped_refptr(new Picture(layer_rect));
16 } 16 }
17 17
18 Picture::Picture() { 18 Picture::Picture(gfx::Rect layer_rect)
19 : layer_rect_(layer_rect) {
19 } 20 }
20 21
21 Picture::Picture(SkPicture* picture, gfx::Rect layer_rect, 22 Picture::Picture(SkPicture* picture, gfx::Rect layer_rect,
22 gfx::Rect opaque_rect) : 23 gfx::Rect opaque_rect) :
23 layer_rect_(layer_rect), 24 layer_rect_(layer_rect),
24 opaque_rect_(opaque_rect), 25 opaque_rect_(opaque_rect),
25 picture_(picture) { 26 picture_(picture) {
26 } 27 }
27 28
28 Picture::~Picture() { 29 Picture::~Picture() {
29 } 30 }
30 31
31 scoped_refptr<Picture> Picture::Clone() { 32 scoped_refptr<Picture> Picture::Clone() const {
32 // SkPicture is not thread-safe to rasterize with, so return a thread-safe 33 // SkPicture is not thread-safe to rasterize with, so return a thread-safe
33 // clone of it. 34 // clone of it.
34 DCHECK(picture_.get()); 35 DCHECK(picture_.get());
35 SkPicture* clone = picture_->clone(); 36 SkPicture* clone = picture_->clone();
36 return make_scoped_refptr(new Picture(clone, layer_rect_, opaque_rect_)); 37 return make_scoped_refptr(new Picture(clone, layer_rect_, opaque_rect_));
37 } 38 }
38 39
39 void Picture::Record(ContentLayerClient* painter, gfx::Rect layer_rect, 40 void Picture::Record(ContentLayerClient* painter,
40 RenderingStats& stats) { 41 RenderingStats& stats) {
41 TRACE_EVENT0("cc", "Picture::Record"); 42 TRACE_EVENT0("cc", "Picture::Record");
42 43
43 // Record() should only be called once. 44 // Record() should only be called once.
44 DCHECK(!picture_.get()); 45 DCHECK(!picture_.get());
45 picture_.reset(new SkPicture); 46 picture_.reset(new SkPicture);
46 47
47 SkCanvas* canvas = picture_->beginRecording( 48 SkCanvas* canvas = picture_->beginRecording(
48 layer_rect.width(), 49 layer_rect_.width(),
49 layer_rect.height(), 50 layer_rect_.height(),
50 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); 51 SkPicture::kOptimizeForClippedPlayback_RecordingFlag);
51 52
52 canvas->save(); 53 canvas->save();
53 canvas->translate(SkFloatToScalar(-layer_rect.x()), 54 canvas->translate(SkFloatToScalar(-layer_rect_.x()),
54 SkFloatToScalar(-layer_rect.y())); 55 SkFloatToScalar(-layer_rect_.y()));
55 56
56 SkPaint paint; 57 SkPaint paint;
57 paint.setAntiAlias(false); 58 paint.setAntiAlias(false);
58 paint.setXfermodeMode(SkXfermode::kClear_Mode); 59 paint.setXfermodeMode(SkXfermode::kClear_Mode);
59 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect.x(), 60 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(),
60 layer_rect.y(), 61 layer_rect_.y(),
61 layer_rect.width(), 62 layer_rect_.width(),
62 layer_rect.height()); 63 layer_rect_.height());
63 canvas->drawRect(layer_skrect, paint); 64 canvas->drawRect(layer_skrect, paint);
64 canvas->clipRect(layer_skrect); 65 canvas->clipRect(layer_skrect);
65 66
66 gfx::RectF opaque_layer_rect; 67 gfx::RectF opaque_layer_rect;
67 base::TimeTicks beginPaintTime = base::TimeTicks::Now(); 68 base::TimeTicks beginPaintTime = base::TimeTicks::Now();
68 painter->paintContents(canvas, layer_rect, opaque_layer_rect); 69 painter->paintContents(canvas, layer_rect_, opaque_layer_rect);
69 double delta = (base::TimeTicks::Now() - beginPaintTime).InSecondsF(); 70 double delta = (base::TimeTicks::Now() - beginPaintTime).InSecondsF();
70 stats.totalPaintTimeInSeconds += delta; 71 stats.totalPaintTimeInSeconds += delta;
71 stats.totalPixelsPainted += layer_rect.width() * 72 stats.totalPixelsPainted += layer_rect_.width() *
72 layer_rect.height(); 73 layer_rect_.height();
73 74
74 canvas->restore(); 75 canvas->restore();
75 picture_->endRecording(); 76 picture_->endRecording();
76 77
77 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); 78 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect);
78 layer_rect_ = layer_rect;
79 } 79 }
80 80
81 void Picture::Raster(SkCanvas* canvas) { 81 void Picture::Raster(SkCanvas* canvas) {
82 TRACE_EVENT0("cc", "Picture::Raster"); 82 TRACE_EVENT0("cc", "Picture::Raster");
83 DCHECK(picture_.get()); 83 DCHECK(picture_.get());
84 canvas->save(); 84 canvas->save();
85 canvas->translate(layer_rect_.x(), layer_rect_.y()); 85 canvas->translate(layer_rect_.x(), layer_rect_.y());
86 canvas->drawPicture(*picture_); 86 canvas->drawPicture(*picture_);
87 canvas->restore(); 87 canvas->restore();
88 } 88 }
89 89
90 } // namespace cc 90 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture.h ('k') | cc/picture_pile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698