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

Side by Side Diff: cc/picture.cc

Issue 12184010: skia::AnalysisCanvas: implementation for IsCheapInRect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to reviewer comments Created 7 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | skia/ext/analysis_canvas.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 "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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 canvas->restore(); 94 canvas->restore();
94 picture_->endRecording(); 95 picture_->endRecording();
95 96
96 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); 97 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect);
97 } 98 }
98 99
99 void Picture::Raster( 100 void Picture::Raster(
100 SkCanvas* canvas, 101 SkCanvas* canvas,
101 gfx::Rect content_rect, 102 gfx::Rect content_rect,
102 float contents_scale) { 103 float contents_scale) {
103 TRACE_EVENT2("cc", "Picture::Raster", 104 char strbuf[256];
104 "width", layer_rect_.width(), "height", layer_rect_.height()); 105 if (IsCheapInRect(content_rect)) {
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());
105 DCHECK(picture_); 119 DCHECK(picture_);
106 120
107 canvas->save(); 121 canvas->save();
108 canvas->clipRect(gfx::RectToSkRect(content_rect)); 122 canvas->clipRect(gfx::RectToSkRect(content_rect));
109 canvas->scale(contents_scale, contents_scale); 123 canvas->scale(contents_scale, contents_scale);
110 canvas->translate(layer_rect_.x(), layer_rect_.y()); 124 canvas->translate(layer_rect_.x(), layer_rect_.y());
111 canvas->drawPicture(*picture_); 125 canvas->drawPicture(*picture_);
112 canvas->restore(); 126 canvas->restore();
113 } 127 }
114 128
115 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect) { 129 bool Picture::IsCheapInRect(const gfx::Rect& layer_rect) {
116 return false; 130 TRACE_EVENT0("cc", "Picture::IsCheapInRect");
131 SkBitmap emptyBitmap;
132 emptyBitmap.setConfig(SkBitmap::kNo_Config, picture_->width(),
133 picture_->height());
134 skia::AnalysisDevice device(emptyBitmap);
135 skia::AnalysisCanvas canvas(&device, gfx::RectToSkRect(layer_rect));
136 // If a picture has low estimated cost, go ahead and
137 // wait until we have more pictures to draw (to amortize startup costs).
138 // If estimated cost is high, start it now so that compositing isn't
139 // blocked waiting for it.
140 canvas.drawPicture(*picture_);
141 return canvas.isCheap();
117 } 142 }
118 143
119 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, 144 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect,
120 std::list<skia::LazyPixelRef*>& pixel_ref_list) { 145 std::list<skia::LazyPixelRef*>& pixel_ref_list) {
121 DCHECK(picture_); 146 DCHECK(picture_);
122 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( 147 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs(
123 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), 148 picture_.get(), SkRect::MakeXYWH(layer_rect.x(),
124 layer_rect.y(), 149 layer_rect.y(),
125 layer_rect.width(), 150 layer_rect.width(),
126 layer_rect.height())); 151 layer_rect.height()));
(...skipping 11 matching lines...) Expand all
138 if (*refs && (*refs)->getURI() && !strncmp( 163 if (*refs && (*refs)->getURI() && !strncmp(
139 (*refs)->getURI(), labelLazyDecoded, 4)) { 164 (*refs)->getURI(), labelLazyDecoded, 4)) {
140 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); 165 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs));
141 } 166 }
142 refs++; 167 refs++;
143 } 168 }
144 pixel_refs->unref(); 169 pixel_refs->unref();
145 } 170 }
146 171
147 } // namespace cc 172 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | skia/ext/analysis_canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698