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 "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkData.h" | 11 #include "third_party/skia/include/core/SkData.h" |
| 11 #include "third_party/skia/include/core/SkTileGridPicture.h" | 12 #include "third_party/skia/include/core/SkTileGridPicture.h" |
| 12 #include "third_party/skia/include/utils/SkPictureUtils.h" | 13 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 13 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" |
| 14 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 // URI label for a lazily decoded SkPixelRef. | 18 // URI label for a lazily decoded SkPixelRef. |
| 18 const char labelLazyDecoded[] = "lazy"; | 19 const char labelLazyDecoded[] = "lazy"; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 canvas->restore(); | 90 canvas->restore(); |
| 90 picture_->endRecording(); | 91 picture_->endRecording(); |
| 91 | 92 |
| 92 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); | 93 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void Picture::Raster( | 96 void Picture::Raster( |
| 96 SkCanvas* canvas, | 97 SkCanvas* canvas, |
| 97 gfx::Rect content_rect, | 98 gfx::Rect content_rect, |
| 98 float contents_scale) { | 99 float contents_scale) { |
| 99 TRACE_EVENT2("cc", "Picture::Raster", | 100 char strbuf[256]; |
| 100 "width", layer_rect_.width(), "height", layer_rect_.height()); | 101 if (IsCheapInRect(content_rect)) { |
| 102 sprintf(strbuf, "CHEAP Picture::Raster"); | |
| 103 } else { | |
| 104 sprintf(strbuf, "EXPENSIVE Picture::Raster"); | |
| 105 } | |
| 106 SkBitmap emptyBitmap; | |
| 107 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, picture_->width(), | |
|
Justin Novosad
2013/02/04 20:23:55
Config should be SkBitmap::kNo_Config
Tom Hudson
2013/02/05 10:23:24
Done.
I'd cribbed this from GatherPixelRefDevice,
| |
| 108 picture_->height()); | |
| 109 skia::AnalysisDevice device(emptyBitmap); | |
| 110 skia::AnalysisCanvas aCanvas(&device, gfx::RectToSkRect(content_rect)); | |
| 111 aCanvas.drawPicture(*picture_); | |
| 112 TRACE_EVENT1("cc", strdup(strbuf), "cost", aCanvas.getEstimatedCost()); | |
| 113 //TRACE_EVENT2("cc", strdup(strbuf), | |
| 114 //"width", layer_rect_.width(), "height", layer_rect_.height()); | |
| 101 DCHECK(picture_); | 115 DCHECK(picture_); |
| 102 | 116 |
| 103 canvas->save(); | 117 canvas->save(); |
| 104 canvas->clipRect(gfx::RectToSkRect(content_rect)); | 118 canvas->clipRect(gfx::RectToSkRect(content_rect)); |
| 105 canvas->scale(contents_scale, contents_scale); | 119 canvas->scale(contents_scale, contents_scale); |
| 106 canvas->translate(layer_rect_.x(), layer_rect_.y()); | 120 canvas->translate(layer_rect_.x(), layer_rect_.y()); |
| 107 canvas->drawPicture(*picture_); | 121 canvas->drawPicture(*picture_); |
| 108 canvas->restore(); | 122 canvas->restore(); |
| 109 } | 123 } |
| 110 | 124 |
| 111 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect) { | 125 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect) { |
| 126 TRACE_EVENT0("cc", "Picture::IsCheapInRect"); | |
| 127 SkBitmap emptyBitmap; | |
| 128 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, picture_->width(), | |
| 129 picture_->height()); | |
| 130 skia::AnalysisDevice device(emptyBitmap); | |
| 131 skia::AnalysisCanvas canvas(&device, gfx::RectToSkRect(layer_rect)); | |
| 132 // If a picture has estimatd cost below this threshold, go ahead and | |
| 133 // wait until we have more pictures to draw (to amortize startup costs). | |
| 134 // If cost exceeds this threshold, start it now so we aren't blocked | |
| 135 // waiting for it. | |
| 136 // FIXME: Arbitrary number. Requires tuning & experimentation. | |
| 137 // Probably requires per-platform tuning; N10 average draw call takes | |
| 138 // 25x as long as Z620. | |
| 139 int pictureCostThreshold = 100; | |
| 140 canvas.drawPicture(*picture_); | |
| 141 if (canvas.getEstimatedCost() <= pictureCostThreshold) { | |
| 142 return true; | |
| 143 } | |
| 112 return false; | 144 return false; |
| 113 } | 145 } |
| 114 | 146 |
| 115 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, | 147 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, |
| 116 std::list<skia::LazyPixelRef*>& pixel_ref_list) { | 148 std::list<skia::LazyPixelRef*>& pixel_ref_list) { |
| 117 DCHECK(picture_); | 149 DCHECK(picture_); |
| 118 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( | 150 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( |
| 119 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), | 151 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), |
| 120 layer_rect.y(), | 152 layer_rect.y(), |
| 121 layer_rect.width(), | 153 layer_rect.width(), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 134 if (*refs && (*refs)->getURI() && !strncmp( | 166 if (*refs && (*refs)->getURI() && !strncmp( |
| 135 (*refs)->getURI(), labelLazyDecoded, 4)) { | 167 (*refs)->getURI(), labelLazyDecoded, 4)) { |
| 136 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); | 168 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); |
| 137 } | 169 } |
| 138 refs++; | 170 refs++; |
| 139 } | 171 } |
| 140 pixel_refs->unref(); | 172 pixel_refs->unref(); |
| 141 } | 173 } |
| 142 | 174 |
| 143 } // namespace cc | 175 } // namespace cc |
| OLD | NEW |