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

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

Issue 11234008: Enable texture readback support for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot to remove local GLHelper from a method Created 8 years, 2 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
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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
11 #include "content/browser/android/content_view_core_impl.h" 13 #include "content/browser/android/content_view_core_impl.h"
12 #include "content/browser/android/draw_delegate_impl.h" 14 #include "content/browser/android/draw_delegate_impl.h"
13 #include "content/browser/gpu/gpu_surface_tracker.h" 15 #include "content/browser/gpu/gpu_surface_tracker.h"
14 #include "content/browser/renderer_host/compositor_impl_android.h" 16 #include "content/browser/renderer_host/compositor_impl_android.h"
15 #include "content/browser/renderer_host/image_transport_factory_android.h" 17 #include "content/browser/renderer_host/image_transport_factory_android.h"
16 #include "content/browser/renderer_host/render_widget_host_impl.h" 18 #include "content/browser/renderer_host/render_widget_host_impl.h"
17 #include "content/common/android/device_info.h" 19 #include "content/common/android/device_info.h"
20 #include "content/common/gpu/client/gl_helper.h"
18 #include "content/common/gpu/gpu_messages.h" 21 #include "content/common/gpu/gpu_messages.h"
19 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
23 #include "third_party/khronos/GLES2/gl2.h"
24 #include "third_party/khronos/GLES2/gl2ext.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" 25 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h" 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
29 #include "ui/gfx/android/java_bitmap.h"
23 30
24 namespace content { 31 namespace content {
25 32
26 namespace { 33 namespace {
27 34
28 // TODO(pliard): http://crbug.com/142585. Remove this helper function and update 35 // TODO(pliard): http://crbug.com/142585. Remove this helper function and update
29 // the clients to deal directly with WebKit::WebTextDirection. 36 // the clients to deal directly with WebKit::WebTextDirection.
30 base::i18n::TextDirection ConvertTextDirection(WebKit::WebTextDirection dir) { 37 base::i18n::TextDirection ConvertTextDirection(WebKit::WebTextDirection dir) {
31 switch (dir) { 38 switch (dir) {
32 case WebKit::WebTextDirectionDefault: return base::i18n::UNKNOWN_DIRECTION; 39 case WebKit::WebTextDirectionDefault: return base::i18n::UNKNOWN_DIRECTION;
33 case WebKit::WebTextDirectionLeftToRight: return base::i18n::LEFT_TO_RIGHT; 40 case WebKit::WebTextDirectionLeftToRight: return base::i18n::LEFT_TO_RIGHT;
34 case WebKit::WebTextDirectionRightToLeft: return base::i18n::RIGHT_TO_LEFT; 41 case WebKit::WebTextDirectionRightToLeft: return base::i18n::RIGHT_TO_LEFT;
35 } 42 }
36 NOTREACHED() << "Unsupported text direction " << dir; 43 NOTREACHED() << "Unsupported text direction " << dir;
37 return base::i18n::UNKNOWN_DIRECTION; 44 return base::i18n::UNKNOWN_DIRECTION;
38 } 45 }
39 46
40 } // namespace 47 } // namespace
41 48
42 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 49 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
43 RenderWidgetHostImpl* widget_host, 50 RenderWidgetHostImpl* widget_host,
44 ContentViewCoreImpl* content_view_core) 51 ContentViewCoreImpl* content_view_core)
45 : host_(widget_host), 52 : host_(widget_host),
46 // ContentViewCoreImpl represents the native side of the Java 53 // ContentViewCoreImpl represents the native side of the Java
47 // ContentViewCore. It being NULL means that it is not attached to the 54 // ContentViewCore. It being NULL means that it is not attached to the
48 // View system yet, so we treat it as hidden. 55 // View system yet, so we treat it as hidden.
49 is_hidden_(!content_view_core), 56 is_hidden_(!content_view_core),
50 content_view_core_(content_view_core), 57 content_view_core_(content_view_core),
51 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 58 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
52 texture_layer_(WebKit::WebExternalTextureLayer::create()) { 59 texture_layer_(WebKit::WebExternalTextureLayer::create()),
60 texture_id_in_layer_(0) {
53 host_->SetView(this); 61 host_->SetView(this);
54 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell 62 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell
55 // RenderWidgetHost to hide. 63 // RenderWidgetHost to hide.
56 if (is_hidden_) 64 if (is_hidden_)
57 host_->WasHidden(); 65 host_->WasHidden();
58 texture_layer_->layer()->setDrawsContent(!is_hidden_); 66 texture_layer_->layer()->setDrawsContent(!is_hidden_);
59 host_->AttachLayer(texture_layer_->layer()); 67 host_->AttachLayer(texture_layer_->layer());
60 } 68 }
61 69
62 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 70 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 texture_layer_->layer()->setBounds(size); 125 texture_layer_->layer()->setBounds(size);
118 } 126 }
119 127
120 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 128 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
121 if (rect.origin().x() || rect.origin().y()) { 129 if (rect.origin().x() || rect.origin().y()) {
122 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; 130 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)";
123 } 131 }
124 SetSize(rect.size()); 132 SetSize(rect.size());
125 } 133 }
126 134
135 WebKit::WebGLId RenderWidgetHostViewAndroid::GetScaledContentTexture(
136 const gfx::Size& size) {
137 if (texture_id_in_layer_ == 0)
138 return 0;
139
140 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
141 return helper->CopyTexture(texture_id_in_layer_, requested_size_, size);
142 }
143
144 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
145 if (texture_id_in_layer_ == 0)
146 return false;
147
148 gfx::JavaBitmap bitmap(jbitmap);
149
150 // TODO(dtrainor): Eventually add support for multiple formats here.
151 DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888);
152
153 WebKit::WebGLId texture = texture_id_in_layer_;
154
155 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
156
157 // If we're trying to read to a bitmap of a different size, we need to copy
158 // and scale the texture before we can read it back.
159 if (bitmap.size() != requested_size_) {
160 texture = helper->CopyTexture(texture_id_in_layer_,
161 requested_size_,
162 bitmap.size());
163 if (texture == 0)
164 return false;
165 }
166
167 helper->SyncCopyRawTextureTo(texture,
168 bitmap.size(),
169 (unsigned char*) bitmap.pixels());
piman 2012/10/19 22:10:10 nit: static_cast or reinterpret_cast
David Trainor- moved to gerrit 2012/10/19 23:11:27 Done.
170
171 if (texture != texture_id_in_layer_) {
172 // We created a temporary texture. We need to clean it up.
173 WebKit::WebGraphicsContext3D* context =
174 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
175 context->deleteTexture(texture);
176 }
177
178 return true;
179 }
180
127 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { 181 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const {
128 return content_view_core_; 182 return content_view_core_;
129 } 183 }
130 184
131 gfx::NativeViewId RenderWidgetHostViewAndroid::GetNativeViewId() const { 185 gfx::NativeViewId RenderWidgetHostViewAndroid::GetNativeViewId() const {
132 return reinterpret_cast<gfx::NativeViewId>( 186 return reinterpret_cast<gfx::NativeViewId>(
133 const_cast<RenderWidgetHostViewAndroid*>(this)); 187 const_cast<RenderWidgetHostViewAndroid*>(this));
134 } 188 }
135 189
136 gfx::NativeViewAccessible 190 gfx::NativeViewAccessible
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 callback.Run(false); 357 callback.Run(false);
304 } 358 }
305 359
306 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { 360 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() {
307 } 361 }
308 362
309 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( 363 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
310 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 364 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
311 int gpu_host_id) { 365 int gpu_host_id) {
312 texture_layer_->setTextureId(params.surface_handle); 366 texture_layer_->setTextureId(params.surface_handle);
367 texture_id_in_layer_ = params.surface_handle;
313 texture_layer_->layer()->invalidate(); 368 texture_layer_->layer()->invalidate();
314 // TODO(sievers): The view and layer should get sized proactively. 369 // TODO(sievers): The view and layer should get sized proactively.
315 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) 370 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty())
316 texture_layer_->layer()->setBounds( 371 texture_layer_->layer()->setBounds(
317 DrawDelegateImpl::GetInstance()->GetBounds()); 372 DrawDelegateImpl::GetInstance()->GetBounds());
318 373
319 // TODO(sievers): When running the impl thread in the browser we 374 // TODO(sievers): When running the impl thread in the browser we
320 // need to delay the ACK until after commit. 375 // need to delay the ACK until after commit.
321 DCHECK(!WebKit::Platform::current()->compositorSupport()-> 376 DCHECK(!WebKit::Platform::current()->compositorSupport()->
322 isThreadingEnabled()); 377 isThreadingEnabled());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // RenderWidgetHostView, public: 565 // RenderWidgetHostView, public:
511 566
512 // static 567 // static
513 RenderWidgetHostView* 568 RenderWidgetHostView*
514 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 569 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
515 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 570 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
516 return new RenderWidgetHostViewAndroid(rwhi, NULL); 571 return new RenderWidgetHostViewAndroid(rwhi, NULL);
517 } 572 }
518 573
519 } // namespace content 574 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698