Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
|
no sievers
2012/10/20 00:42:36
already included in header
David Trainor- moved to gerrit
2012/10/22 17:56:16
Done.
| |
| 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 Loading... | |
| 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->CopyAndScaleTexture(texture_id_in_layer_, | |
| 142 requested_size_, | |
| 143 size); | |
| 144 } | |
| 145 | |
| 146 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { | |
| 147 if (texture_id_in_layer_ == 0) | |
| 148 return false; | |
| 149 | |
| 150 gfx::JavaBitmap bitmap(jbitmap); | |
| 151 | |
| 152 // TODO(dtrainor): Eventually add support for multiple formats here. | |
| 153 DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888); | |
| 154 | |
| 155 WebKit::WebGLId texture = texture_id_in_layer_; | |
| 156 | |
| 157 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | |
| 158 | |
| 159 // If we're trying to read to a bitmap of a different size, we need to copy | |
| 160 // and scale the texture before we can read it back. | |
| 161 if (bitmap.size() != requested_size_) { | |
| 162 texture = helper->CopyAndScaleTexture(texture_id_in_layer_, | |
| 163 requested_size_, | |
| 164 bitmap.size()); | |
| 165 if (texture == 0) | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 helper->ReadbackTextureSync(texture, | |
| 170 bitmap.size(), | |
| 171 static_cast<unsigned char*> (bitmap.pixels())); | |
| 172 | |
| 173 if (texture != texture_id_in_layer_) { | |
| 174 // We created a temporary texture. We need to clean it up. | |
| 175 WebKit::WebGraphicsContext3D* context = | |
| 176 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | |
| 177 context->deleteTexture(texture); | |
| 178 } | |
| 179 | |
| 180 return true; | |
| 181 } | |
| 182 | |
| 127 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { | 183 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { |
| 128 return content_view_core_; | 184 return content_view_core_; |
| 129 } | 185 } |
| 130 | 186 |
| 131 gfx::NativeViewId RenderWidgetHostViewAndroid::GetNativeViewId() const { | 187 gfx::NativeViewId RenderWidgetHostViewAndroid::GetNativeViewId() const { |
| 132 return reinterpret_cast<gfx::NativeViewId>( | 188 return reinterpret_cast<gfx::NativeViewId>( |
| 133 const_cast<RenderWidgetHostViewAndroid*>(this)); | 189 const_cast<RenderWidgetHostViewAndroid*>(this)); |
| 134 } | 190 } |
| 135 | 191 |
| 136 gfx::NativeViewAccessible | 192 gfx::NativeViewAccessible |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 callback.Run(false); | 359 callback.Run(false); |
| 304 } | 360 } |
| 305 | 361 |
| 306 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { | 362 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { |
| 307 } | 363 } |
| 308 | 364 |
| 309 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( | 365 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( |
| 310 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 366 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 311 int gpu_host_id) { | 367 int gpu_host_id) { |
| 312 texture_layer_->setTextureId(params.surface_handle); | 368 texture_layer_->setTextureId(params.surface_handle); |
| 369 texture_id_in_layer_ = params.surface_handle; | |
| 313 texture_layer_->layer()->invalidate(); | 370 texture_layer_->layer()->invalidate(); |
| 314 // TODO(sievers): The view and layer should get sized proactively. | 371 // TODO(sievers): The view and layer should get sized proactively. |
| 315 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) | 372 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) |
| 316 texture_layer_->layer()->setBounds( | 373 texture_layer_->layer()->setBounds( |
| 317 DrawDelegateImpl::GetInstance()->GetBounds()); | 374 DrawDelegateImpl::GetInstance()->GetBounds()); |
| 318 | 375 |
| 319 // TODO(sievers): When running the impl thread in the browser we | 376 // TODO(sievers): When running the impl thread in the browser we |
| 320 // need to delay the ACK until after commit. | 377 // need to delay the ACK until after commit. |
| 321 DCHECK(!WebKit::Platform::current()->compositorSupport()-> | 378 DCHECK(!WebKit::Platform::current()->compositorSupport()-> |
| 322 isThreadingEnabled()); | 379 isThreadingEnabled()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // RenderWidgetHostView, public: | 567 // RenderWidgetHostView, public: |
| 511 | 568 |
| 512 // static | 569 // static |
| 513 RenderWidgetHostView* | 570 RenderWidgetHostView* |
| 514 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 571 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 515 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 572 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 516 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 573 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 517 } | 574 } |
| 518 | 575 |
| 519 } // namespace content | 576 } // namespace content |
| OLD | NEW |