Index: content/browser/renderer_host/render_widget_host_view_android.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc |
index f29806a0d39156454381aaea89f7707545793c88..c405922e382878b6d32a7f792605a839567eda45 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_android.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc |
@@ -75,7 +75,7 @@ |
#include "third_party/khronos/GLES2/gl2.h" |
#include "third_party/khronos/GLES2/gl2ext.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
-#include "ui/android/context_provider_factory.h" |
+#include "ui/android/delegated_frame_host_android.h" |
#include "ui/android/window_android.h" |
#include "ui/android/window_android_compositor.h" |
#include "ui/base/layout.h" |
@@ -95,24 +95,6 @@ namespace content { |
namespace { |
-void SatisfyCallback(cc::SurfaceManager* manager, |
- const cc::SurfaceSequence& sequence) { |
- std::vector<uint32_t> sequences; |
- sequences.push_back(sequence.sequence); |
- manager->DidSatisfySequences(sequence.client_id, &sequences); |
-} |
- |
-void RequireCallback(cc::SurfaceManager* manager, |
- const cc::SurfaceId& id, |
- const cc::SurfaceSequence& sequence) { |
- cc::Surface* surface = manager->GetSurfaceForId(id); |
- if (!surface) { |
- LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
- return; |
- } |
- surface->AddDestructionDependency(sequence); |
-} |
- |
const int kUndefinedOutputSurfaceId = -1; |
static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
@@ -286,25 +268,6 @@ gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { |
return rect; |
} |
-scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( |
- const cc::SurfaceId& surface_id, |
- const gfx::Size& size) { |
- DCHECK(!surface_id.is_null()); |
- cc::SurfaceManager* manager = |
- ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); |
- DCHECK(manager); |
- // manager must outlive compositors using it. |
- scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create( |
- base::Bind(&SatisfyCallback, base::Unretained(manager)), |
- base::Bind(&RequireCallback, base::Unretained(manager))); |
- surface_layer->SetSurfaceId(surface_id, 1.f, size); |
- surface_layer->SetBounds(size); |
- surface_layer->SetIsDrawable(true); |
- surface_layer->SetContentsOpaque(true); |
- |
- return surface_layer; |
-} |
- |
} // anonymous namespace |
RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
@@ -346,12 +309,14 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
locks_on_frame_count_(0), |
observing_root_window_(false), |
weak_ptr_factory_(this) { |
+ // Set the layer which will hold the content layer for this view. The content |
+ // layer is managed by the DelegatedFrameHost. |
+ view_.SetLayer(cc::Layer::Create()); |
if (using_browser_compositor_) { |
- id_allocator_.reset(new cc::SurfaceIdAllocator( |
- ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId())); |
- ui::ContextProviderFactory::GetInstance() |
- ->GetSurfaceManager() |
- ->RegisterSurfaceClientId(id_allocator_->client_id()); |
+ delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
+ &view_, cached_background_color_, |
+ base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, |
+ weak_ptr_factory_.GetWeakPtr()))); |
} |
host_->SetView(this); |
@@ -363,8 +328,7 @@ RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
content_view_core_->RemoveObserver(this); |
SetContentViewCore(NULL); |
DCHECK(ack_callbacks_.empty()); |
- DCHECK(!surface_factory_); |
- DCHECK(surface_id_.is_null()); |
+ DCHECK(!delegated_frame_host_); |
} |
void RenderWidgetHostViewAndroid::Blur() { |
@@ -418,6 +382,7 @@ RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
} |
void RenderWidgetHostViewAndroid::WasResized() { |
+ delegated_frame_host_->UpdateSize(GetViewSize()); |
no sievers
2016/08/12 19:33:04
I *think* you are passing DIP here but when you co
Khushal
2016/08/16 01:34:23
You're right. Fixed that.
|
host_->WasResized(); |
} |
@@ -440,7 +405,7 @@ void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
return; |
} |
- gfx::Size bounds = view_.GetLayer()->bounds(); |
+ gfx::Size bounds = delegated_frame_host_->GetContentLayer()->bounds(); |
no sievers
2016/08/12 19:33:04
I think this should be the same as |texture_size_i
Khushal
2016/08/16 01:34:23
Done.
|
if (src_subrect.IsEmpty()) |
src_subrect = gfx::Rect(bounds); |
DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); |
@@ -460,7 +425,7 @@ void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
if (!content_view_core_) |
return false; |
- if (!view_.GetLayer()) |
+ if (!delegated_frame_host_->GetContentLayer()) |
no sievers
2016/08/12 19:33:03
I think you can just remove this check. It should
Khushal
2016/08/16 01:34:23
Should there be a DCHECK at the end then? The Dele
|
return false; |
if (texture_size_in_layer_.IsEmpty()) |
@@ -506,8 +471,7 @@ bool RenderWidgetHostViewAndroid::HasFocus() const { |
} |
bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
- return !using_browser_compositor_ || |
- (HasValidFrame() && surface_factory_.get()); |
+ return !using_browser_compositor_ || HasValidFrame(); |
} |
void RenderWidgetHostViewAndroid::Show() { |
@@ -558,8 +522,8 @@ void RenderWidgetHostViewAndroid::UnlockCompositingSurface() { |
last_frame_info_.reset(); |
} |
- if (!is_showing_ && view_.GetLayer()) |
- view_.GetLayer()->SetHideLayerAndSubtree(true); |
+ if (!is_showing_ && delegated_frame_host_->GetContentLayer()) |
+ delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true); |
no sievers
2016/08/12 19:33:04
Make this DFH::SetVisible()
Khushal
2016/08/16 01:34:23
Had it update the view's layer directly.
|
} |
} |
@@ -587,14 +551,7 @@ void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { |
} |
gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
- if (!content_view_core_) |
- return gfx::Rect(default_size_); |
- |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableOSKOverscroll)) |
- return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden()); |
- |
- return gfx::Rect(content_view_core_->GetViewSize()); |
+ return gfx::Rect(GetViewSize()); |
} |
gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { |
@@ -662,6 +619,7 @@ void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { |
return; |
cached_background_color_ = color; |
+ delegated_frame_host_->UpdateBackgroundColor(color); |
if (content_view_core_) |
content_view_core_->OnBackgroundColorChanged(color); |
} |
@@ -794,20 +752,8 @@ void RenderWidgetHostViewAndroid::RenderProcessGone( |
void RenderWidgetHostViewAndroid::Destroy() { |
host_->ViewDestroyed(); |
- RemoveLayers(); |
SetContentViewCore(NULL); |
- |
- if (!surface_id_.is_null()) { |
- DCHECK(surface_factory_.get()); |
- surface_factory_->Destroy(surface_id_); |
- surface_id_ = cc::SurfaceId(); |
- } |
- surface_factory_.reset(); |
- if (id_allocator_) { |
- ui::ContextProviderFactory::GetInstance() |
- ->GetSurfaceManager() |
- ->InvalidateSurfaceClientId(id_allocator_->client_id()); |
- } |
+ delegated_frame_host_.reset(); |
// The RenderWidgetHost's destruction led here, so don't call it. |
host_ = NULL; |
@@ -893,7 +839,7 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
ui::WindowAndroidCompositor* compositor = |
content_view_core_->GetWindowAndroid()->GetCompositor(); |
DCHECK(compositor); |
- DCHECK(!surface_id_.is_null()); |
+ DCHECK(delegated_frame_host_->GetContentLayer()); |
no sievers
2016/08/12 19:33:04
You can move this DCHECK() into DFH.
Khushal
2016/08/16 01:34:23
Done.
|
std::unique_ptr<cc::CopyOutputRequest> request = |
cc::CopyOutputRequest::CreateRequest(base::Bind( |
&PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(), |
@@ -903,7 +849,7 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
// Make sure the current frame doesn't get deleted until we fulfill the |
// request. |
LockCompositingSurface(); |
- surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); |
+ delegated_frame_host_->RequestCopyOfSurface(std::move(request)); |
} |
void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
@@ -954,28 +900,12 @@ void RenderWidgetHostViewAndroid::ReturnResources( |
false /* is_swap_ack */); |
} |
-void RenderWidgetHostViewAndroid::SetBeginFrameSource( |
- cc::BeginFrameSource* begin_frame_source) { |
- // TODO(tansell): Hook this up. |
-} |
- |
-void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { |
- RemoveLayers(); |
- if (!surface_id_.is_null()) { |
- DCHECK(surface_factory_.get()); |
- cc::SurfaceId surface_id; |
- std::swap(surface_id, surface_id_); |
- surface_factory_->Destroy(surface_id); |
- } |
- view_.SetLayer(nullptr); |
-} |
- |
void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
uint32_t output_surface_id) { |
if (output_surface_id == last_output_surface_id_) |
return; |
- DestroyDelegatedContent(); |
- surface_factory_.reset(); |
+ delegated_frame_host_->OutputSurfaceChanged(); |
+ |
if (!surface_returned_resources_.empty()) |
SendReclaimCompositorResources(last_output_surface_id_, |
false /* is_swap_ack */); |
@@ -983,46 +913,12 @@ void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
last_output_surface_id_ = output_surface_id; |
} |
-void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
- cc::CompositorFrame frame) { |
- cc::SurfaceManager* manager = |
- ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); |
- if (!surface_factory_) { |
- surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); |
- } |
- if (surface_id_.is_null() || |
- texture_size_in_layer_ != current_surface_size_ || |
- location_bar_content_translation_ != |
- frame.metadata.location_bar_content_translation || |
- current_viewport_selection_ != frame.metadata.selection) { |
- RemoveLayers(); |
- if (!surface_id_.is_null()) |
- surface_factory_->Destroy(surface_id_); |
- surface_id_ = id_allocator_->GenerateId(); |
- surface_factory_->Create(surface_id_); |
- view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_)); |
- |
- DCHECK(view_.GetLayer()); |
- |
- current_surface_size_ = texture_size_in_layer_; |
- location_bar_content_translation_ = |
- frame.metadata.location_bar_content_translation; |
- current_viewport_selection_ = frame.metadata.selection; |
- AttachLayers(); |
- } |
- |
- cc::SurfaceFactory::DrawCallback ack_callback = |
- base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
- weak_ptr_factory_.GetWeakPtr()); |
- surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
- ack_callback); |
-} |
- |
void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
uint32_t output_surface_id, |
cc::CompositorFrame frame) { |
last_scroll_offset_ = frame.metadata.root_scroll_offset; |
DCHECK(frame.delegated_frame_data); |
+ DCHECK(delegated_frame_host_); |
if (locks_on_frame_count_ > 0) { |
DCHECK(HasValidFrame()); |
@@ -1049,12 +945,13 @@ void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
ack_callbacks_.push(ack_callback); |
if (!has_content) { |
- DestroyDelegatedContent(); |
+ delegated_frame_host_->DestroyDelegatedContent(); |
} else { |
- SubmitCompositorFrame(std::move(frame)); |
- view_.GetLayer()->SetIsDrawable(true); |
- view_.GetLayer()->SetContentsOpaque(true); |
- view_.GetLayer()->SetBounds(texture_size_in_layer_); |
+ cc::SurfaceFactory::DrawCallback ack_callback = |
+ base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
+ weak_ptr_factory_.GetWeakPtr()); |
+ delegated_frame_host_->SubmitCompositorFrame(std::move(frame), |
+ ack_callback); |
} |
if (host_->is_hidden()) |
@@ -1073,7 +970,7 @@ void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
} |
void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
- DestroyDelegatedContent(); |
+ delegated_frame_host_->DestroyDelegatedContent(); |
} |
void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, |
@@ -1122,8 +1019,8 @@ void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
} |
void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { |
- if (view_.GetLayer()) |
- view_.GetLayer()->SetContentsOpaque(!enabled); |
+ if (delegated_frame_host_->GetContentLayer()) |
+ delegated_frame_host_->GetContentLayer()->SetContentsOpaque(!enabled); |
no sievers
2016/08/12 19:33:04
Make this DFH::SetContentsOpaque().
Khushal
2016/08/16 01:34:23
Done.
|
} |
bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
@@ -1279,6 +1176,17 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
#endif // defined(VIDEO_HOLE) |
} |
+gfx::Size RenderWidgetHostViewAndroid::GetViewSize() const { |
no sievers
2016/08/12 19:33:03
nit: Can you not add this method, since RWHV alrea
Khushal
2016/08/16 01:34:23
Done.
|
+ if (!content_view_core_) |
+ return default_size_; |
+ |
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableOSKOverscroll)) |
+ return content_view_core_->GetViewSizeWithOSKHidden(); |
+ |
+ return content_view_core_->GetViewSize(); |
+} |
+ |
void RenderWidgetHostViewAndroid::ShowInternal() { |
bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; |
if (!show) |
@@ -1287,8 +1195,8 @@ void RenderWidgetHostViewAndroid::ShowInternal() { |
if (!host_ || !host_->is_hidden()) |
return; |
- if (view_.GetLayer()) |
- view_.GetLayer()->SetHideLayerAndSubtree(false); |
+ if (delegated_frame_host_->GetContentLayer()) |
+ delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(false); |
frame_evictor_->SetVisible(true); |
@@ -1318,8 +1226,8 @@ void RenderWidgetHostViewAndroid::HideInternal() { |
bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; |
if (hide_frontbuffer) { |
- if (view_.GetLayer() && locks_on_frame_count_ == 0) |
- view_.GetLayer()->SetHideLayerAndSubtree(true); |
+ if (delegated_frame_host_->GetContentLayer() && locks_on_frame_count_ == 0) |
Khushal
2016/08/16 01:34:23
Btw, why do we have this lock check here?
|
+ delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true); |
frame_evictor_->SetVisible(false); |
} |
@@ -1342,26 +1250,6 @@ void RenderWidgetHostViewAndroid::HideInternal() { |
host_->WasHidden(); |
} |
-void RenderWidgetHostViewAndroid::AttachLayers() { |
- if (!content_view_core_) |
- return; |
- if (!view_.GetLayer()) |
- return; |
- |
- content_view_core_->AttachLayer(view_.GetLayer()); |
- view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); |
-} |
- |
-void RenderWidgetHostViewAndroid::RemoveLayers() { |
- if (!content_view_core_) |
- return; |
- |
- if (!view_.GetLayer()) |
- return; |
- |
- content_view_core_->RemoveLayer(view_.GetLayer()); |
-} |
- |
void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { |
bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
outstanding_vsync_requests_ |= requests; |
@@ -1448,8 +1336,7 @@ void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { |
void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { |
DCHECK_EQ(locks_on_frame_count_, 0u); |
frame_evictor_->DiscardedFrame(); |
- if (view_.GetLayer()) |
- DestroyDelegatedContent(); |
+ delegated_frame_host_->DestroyDelegatedContent(); |
} |
bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
@@ -1659,7 +1546,8 @@ void RenderWidgetHostViewAndroid::DidOverscroll( |
if (sync_compositor_) |
sync_compositor_->DidOverscroll(params); |
- if (!content_view_core_ || !view_.GetLayer() || !is_showing_) |
+ if (!content_view_core_ || !delegated_frame_host_->GetContentLayer() || |
no sievers
2016/08/12 19:33:03
I don't understand the layer check here. I'd just
Khushal
2016/08/16 01:34:23
I added a check for DFH::HasDelegatedContent inste
|
+ !is_showing_) |
return; |
if (overscroll_controller_) |
@@ -1672,16 +1560,16 @@ void RenderWidgetHostViewAndroid::DidStopFlinging() { |
} |
uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { |
- if (id_allocator_) |
- return id_allocator_->client_id(); |
- return 0; |
+ if (!delegated_frame_host_) |
+ return 0; |
+ |
+ return delegated_frame_host_->GetSurfaceClientId(); |
} |
void RenderWidgetHostViewAndroid::SetContentViewCore( |
ContentViewCoreImpl* content_view_core) { |
DCHECK(!content_view_core || !content_view_core_ || |
(content_view_core_ == content_view_core)); |
- RemoveLayers(); |
StopObservingRootWindow(); |
bool resize = false; |
@@ -1699,10 +1587,13 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( |
if (content_view_core_) { |
content_view_core_->RemoveObserver(this); |
view_.RemoveFromParent(); |
+ view_.GetLayer()->RemoveFromParent(); |
} |
if (content_view_core) { |
content_view_core->AddObserver(this); |
- content_view_core->GetViewAndroid()->AddChild(&view_); |
+ ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid(); |
+ parent_view->AddChild(&view_); |
+ parent_view->GetLayer()->AddChild(view_.GetLayer()); |
} |
content_view_core_ = content_view_core; |
} |
@@ -1717,7 +1608,6 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( |
manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
} |
- AttachLayers(); |
if (!content_view_core_) { |
sync_compositor_.reset(); |
return; |
@@ -1862,8 +1752,7 @@ void RenderWidgetHostViewAndroid::OnActivityStarted() { |
void RenderWidgetHostViewAndroid::OnLostResources() { |
ReleaseLocksOnSurface(); |
- if (view_.GetLayer()) |
- DestroyDelegatedContent(); |
+ delegated_frame_host_->DestroyDelegatedContent(); |
DCHECK(ack_callbacks_.empty()); |
} |