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 "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 "skia/ext/analysis_canvas.h" | 9 #include "skia/ext/analysis_canvas.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 canvas->restore(); | 94 canvas->restore(); |
| 95 picture_->endRecording(); | 95 picture_->endRecording(); |
| 96 | 96 |
| 97 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); | 97 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void Picture::Raster( | 100 void Picture::Raster( |
| 101 SkCanvas* canvas, | 101 SkCanvas* canvas, |
| 102 gfx::Rect content_rect, | 102 gfx::Rect content_rect, |
| 103 float contents_scale) { | 103 float contents_scale) { |
| 104 char strbuf[256]; | 104 TRACE_EVENT2("cc", "Picture::Raster", |
| 105 if (IsCheapInRect(content_rect)) { | 105 "width", layer_rect_.width(), "height", layer_rect_.height()); |
| 106 sprintf(strbuf, "CHEAP Picture::Raster"); | |
| 107 } else { | |
| 108 sprintf(strbuf, "EXPENSIVE Picture::Raster"); | |
| 109 } | |
| 110 SkBitmap emptyBitmap; | |
| 111 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, picture_->width(), | |
| 112 picture_->height()); | |
| 113 skia::AnalysisDevice device(emptyBitmap); | |
| 114 skia::AnalysisCanvas aCanvas(&device, gfx::RectToSkRect(content_rect)); | |
| 115 aCanvas.drawPicture(*picture_); | |
| 116 TRACE_EVENT1("cc", strdup(strbuf), "cost", aCanvas.getEstimatedCost()); | |
| 117 //TRACE_EVENT2("cc", strdup(strbuf), | |
| 118 //"width", layer_rect_.width(), "height", layer_rect_.height()); | |
| 119 DCHECK(picture_); | 106 DCHECK(picture_); |
| 120 | 107 |
| 108 bool isCheap = IsCheapInRect(content_rect, contents_scale); | |
| 121 canvas->save(); | 109 canvas->save(); |
| 122 canvas->clipRect(gfx::RectToSkRect(content_rect)); | 110 canvas->clipRect(gfx::RectToSkRect(content_rect)); |
| 123 canvas->scale(contents_scale, contents_scale); | 111 canvas->scale(contents_scale, contents_scale); |
| 124 canvas->translate(layer_rect_.x(), layer_rect_.y()); | 112 canvas->translate(layer_rect_.x(), layer_rect_.y()); |
| 125 canvas->drawPicture(*picture_); | 113 canvas->drawPicture(*picture_); |
| 126 canvas->restore(); | 114 canvas->restore(); |
| 127 } | 115 } |
| 128 | 116 |
| 129 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect) { | 117 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect, |
| 130 TRACE_EVENT0("cc", "Picture::IsCheapInRect"); | 118 float contents_scale) const { |
| 119 TRACE_EVENT0("cc", "Picture::IsCheapInRect"); | |
|
nduca
2013/02/06 08:42:25
is your git branch mucked up? this looks like its
| |
| 120 | |
| 131 SkBitmap emptyBitmap; | 121 SkBitmap emptyBitmap; |
| 132 emptyBitmap.setConfig(SkBitmap::kNo_Config, picture_->width(), | 122 emptyBitmap.setConfig(SkBitmap::kNo_Config, layer_rect.width(), |
| 133 picture_->height()); | 123 layer_rect.height()); |
| 134 skia::AnalysisDevice device(emptyBitmap); | 124 skia::AnalysisDevice device(emptyBitmap); |
| 135 skia::AnalysisCanvas canvas(&device, gfx::RectToSkRect(layer_rect)); | 125 skia::AnalysisCanvas canvas(&device); |
| 136 // If a picture has low estimated cost, go ahead and | 126 |
| 137 // wait until we have more pictures to draw (to amortize startup costs). | 127 canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
|
nduca
2013/02/06 08:42:25
this line looks a little different than the call i
| |
| 138 // If estimated cost is high, start it now so that compositing isn't | 128 canvas.scale(contents_scale, contents_scale); |
| 139 // blocked waiting for it. | 129 canvas.translate(layer_rect_.x(), layer_rect_.y()); |
| 140 canvas.drawPicture(*picture_); | 130 canvas.drawPicture(*picture_); |
| 141 return canvas.isCheap(); | 131 return canvas.isCheap(); |
| 142 } | 132 } |
| 143 | 133 |
| 144 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, | 134 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, |
| 145 std::list<skia::LazyPixelRef*>& pixel_ref_list) { | 135 std::list<skia::LazyPixelRef*>& pixel_ref_list) { |
| 146 DCHECK(picture_); | 136 DCHECK(picture_); |
| 147 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( | 137 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( |
| 148 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), | 138 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), |
| 149 layer_rect.y(), | 139 layer_rect.y(), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 163 if (*refs && (*refs)->getURI() && !strncmp( | 153 if (*refs && (*refs)->getURI() && !strncmp( |
| 164 (*refs)->getURI(), labelLazyDecoded, 4)) { | 154 (*refs)->getURI(), labelLazyDecoded, 4)) { |
| 165 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); | 155 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); |
| 166 } | 156 } |
| 167 refs++; | 157 refs++; |
| 168 } | 158 } |
| 169 pixel_refs->unref(); | 159 pixel_refs->unref(); |
| 170 } | 160 } |
| 171 | 161 |
| 172 } // namespace cc | 162 } // namespace cc |
| OLD | NEW |