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

Side by Side Diff: chrome/browser/thumbnails/thumbnail_tab_helper.cc

Issue 2702093002: Consistent CopyFromSurface() API, consolidated to RWHV (Closed)
Patch Set: REBASE Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/thumbnails/thumbnail_tab_helper.h" 5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/thumbnails/thumbnail_service.h" 10 #include "chrome/browser/thumbnails/thumbnail_service.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void ThumbnailTabHelper::AsyncProcessThumbnail( 143 void ThumbnailTabHelper::AsyncProcessThumbnail(
144 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service) { 144 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service) {
145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
146 RenderWidgetHost* render_widget_host = 146 RenderWidgetHost* render_widget_host =
147 web_contents()->GetRenderViewHost()->GetWidget(); 147 web_contents()->GetRenderViewHost()->GetWidget();
148 content::RenderWidgetHostView* view = render_widget_host->GetView(); 148 content::RenderWidgetHostView* view = render_widget_host->GetView();
149 if (!view || !view->IsSurfaceAvailableForCopy()) { 149 if (!view || !view->IsSurfaceAvailableForCopy()) {
150 return; 150 return;
151 } 151 }
152 152
153 // TODO(miu): This is the wrong size. It's the size of the view on-screen, and
154 // not the rendering size of the view. This will be replaced with the view's
155 // actual rendering size in a later change. http://crbug.com/73362
153 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); 156 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size());
154 // Clip the pixels that will commonly hold a scrollbar, which looks bad in 157 // Clip the pixels that will commonly hold a scrollbar, which looks bad in
155 // thumbnails. 158 // thumbnails.
156 int scrollbar_size = gfx::scrollbar_size(); 159 int scrollbar_size = gfx::scrollbar_size();
157 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); 160 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size);
158 161
159 if (copy_rect.IsEmpty()) { 162 if (copy_rect.IsEmpty()) {
160 return; 163 return;
161 } 164 }
162 165
163 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( 166 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm(
164 thumbnail_service->GetThumbnailingAlgorithm()); 167 thumbnail_service->GetThumbnailingAlgorithm());
165 168
166 thumbnailing_context_ = new ThumbnailingContext(web_contents(), 169 thumbnailing_context_ = new ThumbnailingContext(web_contents(),
167 thumbnail_service.get(), 170 thumbnail_service.get(),
168 load_interrupted_); 171 load_interrupted_);
169 172
170 ui::ScaleFactor scale_factor = 173 ui::ScaleFactor scale_factor =
171 ui::GetSupportedScaleFactor( 174 ui::GetSupportedScaleFactor(
172 ui::GetScaleFactorForNativeView(view->GetNativeView())); 175 ui::GetScaleFactorForNativeView(view->GetNativeView()));
173 thumbnailing_context_->clip_result = algorithm->GetCanvasCopyInfo( 176 thumbnailing_context_->clip_result = algorithm->GetCanvasCopyInfo(
174 copy_rect.size(), 177 copy_rect.size(),
175 scale_factor, 178 scale_factor,
176 &copy_rect, 179 &copy_rect,
177 &thumbnailing_context_->requested_copy_size); 180 &thumbnailing_context_->requested_copy_size);
178 render_widget_host->CopyFromBackingStore( 181 view->CopyFromSurface(copy_rect, thumbnailing_context_->requested_copy_size,
179 copy_rect, 182 base::Bind(&ThumbnailTabHelper::ProcessCapturedBitmap,
180 thumbnailing_context_->requested_copy_size, 183 weak_factory_.GetWeakPtr(), algorithm),
181 base::Bind(&ThumbnailTabHelper::ProcessCapturedBitmap, 184 kN32_SkColorType);
182 weak_factory_.GetWeakPtr(),
183 algorithm),
184 kN32_SkColorType);
185 } 185 }
186 186
187 void ThumbnailTabHelper::ProcessCapturedBitmap( 187 void ThumbnailTabHelper::ProcessCapturedBitmap(
188 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm, 188 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm,
189 const SkBitmap& bitmap, 189 const SkBitmap& bitmap,
190 content::ReadbackResponse response) { 190 content::ReadbackResponse response) {
191 if (response == content::READBACK_SUCCESS) { 191 if (response == content::READBACK_SUCCESS) {
192 // On success, we must be on the UI thread. 192 // On success, we must be on the UI thread.
193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
194 algorithm->ProcessBitmap(thumbnailing_context_, 194 algorithm->ProcessBitmap(thumbnailing_context_,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 content::Source<RenderWidgetHost>(renderer->GetWidget())); 234 content::Source<RenderWidgetHost>(renderer->GetWidget()));
235 if (!registered) { 235 if (!registered) {
236 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 236 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
237 content::Source<RenderWidgetHost>(renderer->GetWidget())); 237 content::Source<RenderWidgetHost>(renderer->GetWidget()));
238 } 238 }
239 } 239 }
240 240
241 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { 241 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) {
242 UpdateThumbnailIfNecessary(); 242 UpdateThumbnailIfNecessary();
243 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698