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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 173023005: Adds support for capturing a sub rect of the compositing surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to reland Created 6 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 "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 WasResized(); 247 WasResized();
248 } 248 }
249 249
250 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 250 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
251 SetSize(rect.size()); 251 SetSize(rect.size());
252 } 252 }
253 253
254 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( 254 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
255 float scale, 255 float scale,
256 SkBitmap::Config bitmap_config, 256 SkBitmap::Config bitmap_config,
257 gfx::Rect src_subrect,
257 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { 258 const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
258 if (!IsSurfaceAvailableForCopy()) { 259 if (!IsSurfaceAvailableForCopy()) {
259 result_callback.Run(false, SkBitmap()); 260 result_callback.Run(false, SkBitmap());
260 return; 261 return;
261 } 262 }
262 263
263 gfx::Size bounds = layer_->bounds(); 264 gfx::Size bounds = layer_->bounds();
264 gfx::Rect src_subrect(bounds); 265 if (src_subrect.IsEmpty())
266 src_subrect = gfx::Rect(bounds);
267 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
268 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
265 const gfx::Display& display = 269 const gfx::Display& display =
266 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 270 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
267 float device_scale_factor = display.device_scale_factor(); 271 float device_scale_factor = display.device_scale_factor();
268 DCHECK_GT(device_scale_factor, 0); 272 DCHECK_GT(device_scale_factor, 0);
269 gfx::Size dst_size( 273 gfx::Size dst_size(
270 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); 274 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor)));
271 CopyFromCompositingSurface( 275 CopyFromCompositingSurface(
272 src_subrect, dst_size, result_callback, bitmap_config); 276 src_subrect, dst_size, result_callback, bitmap_config);
273 } 277 }
274 278
275 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
276 if (!CompositorImpl::IsInitialized() ||
277 texture_id_in_layer_ == 0 ||
278 texture_size_in_layer_.IsEmpty())
279 return false;
280
281 gfx::JavaBitmap bitmap(jbitmap);
282
283 // TODO(dtrainor): Eventually add support for multiple formats here.
284 DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888);
285
286 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
287
288 GLuint texture = helper->CopyAndScaleTexture(
289 texture_id_in_layer_,
290 texture_size_in_layer_,
291 bitmap.size(),
292 true,
293 GLHelper::SCALER_QUALITY_FAST);
294 if (texture == 0u)
295 return false;
296
297 helper->ReadbackTextureSync(texture,
298 gfx::Rect(bitmap.size()),
299 static_cast<unsigned char*> (bitmap.pixels()),
300 SkBitmap::kARGB_8888_Config);
301
302 gpu::gles2::GLES2Interface* gl =
303 ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
304 gl->DeleteTextures(1, &texture);
305
306 return true;
307 }
308
309 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 279 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
310 if (!content_view_core_) 280 if (!content_view_core_)
311 return false; 281 return false;
312 if (!layer_) 282 if (!layer_)
313 return false; 283 return false;
314 284
315 if (texture_size_in_layer_.IsEmpty()) 285 if (texture_size_in_layer_.IsEmpty())
316 return false; 286 return false;
317 287
318 if (using_delegated_renderer_) { 288 if (using_delegated_renderer_) {
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 // RenderWidgetHostView, public: 1410 // RenderWidgetHostView, public:
1441 1411
1442 // static 1412 // static
1443 RenderWidgetHostView* 1413 RenderWidgetHostView*
1444 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1414 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1445 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1415 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1446 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1416 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1447 } 1417 }
1448 1418
1449 } // namespace content 1419 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698