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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 friend class base::RefCounted<MemoryHolder>; | 112 friend class base::RefCounted<MemoryHolder>; |
113 ~MemoryHolder() { callback_.Run(); } | 113 ~MemoryHolder() { callback_.Run(); } |
114 | 114 |
115 scoped_ptr<base::SharedMemory> shared_memory_; | 115 scoped_ptr<base::SharedMemory> shared_memory_; |
116 gfx::Size frame_size_; | 116 gfx::Size frame_size_; |
117 base::Callback<void()> callback_; | 117 base::Callback<void()> callback_; |
118 }; | 118 }; |
119 | 119 |
120 namespace { | 120 namespace { |
121 | 121 |
122 void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory, | |
123 unsigned sync_point, bool lost_resource) { | |
124 // NOTE: shared_memory will get released when we go out of scope. | |
125 } | |
126 | |
122 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting | 127 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting |
123 // the border of the view, in order to get valid movement information. However, | 128 // the border of the view, in order to get valid movement information. However, |
124 // forcing the cursor back to the center of the view after each mouse move | 129 // forcing the cursor back to the center of the view after each mouse move |
125 // doesn't work well. It reduces the frequency of useful mouse move messages | 130 // doesn't work well. It reduces the frequency of useful mouse move messages |
126 // significantly. Therefore, we move the cursor to the center of the view only | 131 // significantly. Therefore, we move the cursor to the center of the view only |
127 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width | 132 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width |
128 // of the border area, in percentage of the corresponding dimension. | 133 // of the border area, in percentage of the corresponding dimension. |
129 const int kMouseLockBorderPercentage = 15; | 134 const int kMouseLockBorderPercentage = 15; |
130 | 135 |
131 // When accelerated compositing is enabled and a widget resize is pending, | 136 // When accelerated compositing is enabled and a widget resize is pending, |
(...skipping 2352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2484 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { | 2489 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { |
2485 } | 2490 } |
2486 | 2491 |
2487 bool RenderWidgetHostViewAura::HasHitTestMask() const { | 2492 bool RenderWidgetHostViewAura::HasHitTestMask() const { |
2488 return false; | 2493 return false; |
2489 } | 2494 } |
2490 | 2495 |
2491 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { | 2496 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { |
2492 } | 2497 } |
2493 | 2498 |
2494 scoped_refptr<ui::Texture> RenderWidgetHostViewAura::CopyTexture() { | 2499 void RenderWidgetHostViewAura::DidRecreateLayer(ui::Layer *old_layer, |
2495 if (!host_->is_accelerated_compositing_active()) | 2500 ui::Layer *new_layer) { |
2496 return scoped_refptr<ui::Texture>(); | 2501 float mailbox_scale_factor; |
2502 cc::TextureMailbox old_mailbox = | |
2503 old_layer->GetTextureMailbox(&mailbox_scale_factor); | |
2504 scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); | |
2505 // Move the original texture to the new layer if the old layer has a | |
2506 // texture and we could copy it into the old layer, | |
2507 // crbug.com/175211. | |
danakj
2013/09/11 17:55:05
This bug is marked as fixed, but has no context at
piman
2013/09/12 01:02:33
Done.
| |
2508 if (old_texture.get()) { | |
2509 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
2510 GLHelper* gl_helper = factory->GetGLHelper(); | |
2511 scoped_refptr<ui::Texture> new_texture; | |
2512 if (host_->is_accelerated_compositing_active() && | |
danakj
2013/09/11 17:55:05
Can you explain how do we have old_texture.get() b
| |
2513 gl_helper && current_surface_.get()) { | |
2514 WebKit::WebGLId texture_id = | |
2515 gl_helper->CopyTexture(current_surface_->PrepareTexture(), | |
2516 current_surface_->size()); | |
2517 if (texture_id) { | |
2518 new_texture = factory->CreateOwnedTexture( | |
2519 current_surface_->size(), | |
2520 current_surface_->device_scale_factor(), texture_id); | |
2521 } | |
2522 } | |
2523 old_layer->SetExternalTexture(new_texture); | |
2524 new_layer->SetExternalTexture(old_texture); | |
2525 } else if (old_mailbox.IsSharedMemory()) { | |
2526 base::SharedMemory* old_buffer = old_mailbox.shared_memory(); | |
2527 const size_t size = old_mailbox.shared_memory_size_in_bytes(); | |
2497 | 2528 |
2498 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 2529 scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); |
2499 GLHelper* gl_helper = factory->GetGLHelper(); | 2530 new_buffer->CreateAndMapAnonymous(size); |
2500 if (!gl_helper) | |
2501 return scoped_refptr<ui::Texture>(); | |
2502 | 2531 |
2503 if (!current_surface_.get()) | 2532 if (old_buffer->memory() && new_buffer->memory()) { |
2504 return scoped_refptr<ui::Texture>(); | 2533 memcpy(new_buffer->memory(), old_buffer->memory(), size); |
2505 | 2534 base::SharedMemory* new_buffer_raw_ptr = new_buffer.get(); |
2506 WebKit::WebGLId texture_id = | 2535 cc::TextureMailbox::ReleaseCallback callback = |
2507 gl_helper->CopyTexture(current_surface_->PrepareTexture(), | 2536 base::Bind(MailboxReleaseCallback, Passed(&new_buffer)); |
2508 current_surface_->size()); | 2537 cc::TextureMailbox new_mailbox(new_buffer_raw_ptr, |
2509 if (!texture_id) | 2538 old_mailbox.shared_memory_size(), |
2510 return scoped_refptr<ui::Texture>(); | 2539 callback); |
2511 | 2540 new_layer->SetTextureMailbox(new_mailbox, mailbox_scale_factor); |
2512 return scoped_refptr<ui::Texture>( | 2541 } |
2513 factory->CreateOwnedTexture( | 2542 } |
2514 current_surface_->size(), | 2543 // TODO(piman): handle delegated frames. |
2515 current_surface_->device_scale_factor(), texture_id)); | |
2516 } | 2544 } |
2517 | 2545 |
2518 //////////////////////////////////////////////////////////////////////////////// | 2546 //////////////////////////////////////////////////////////////////////////////// |
2519 // RenderWidgetHostViewAura, ui::EventHandler implementation: | 2547 // RenderWidgetHostViewAura, ui::EventHandler implementation: |
2520 | 2548 |
2521 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { | 2549 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
2522 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); | 2550 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); |
2523 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) | 2551 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
2524 return; | 2552 return; |
2525 | 2553 |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3269 RenderWidgetHost* widget) { | 3297 RenderWidgetHost* widget) { |
3270 return new RenderWidgetHostViewAura(widget); | 3298 return new RenderWidgetHostViewAura(widget); |
3271 } | 3299 } |
3272 | 3300 |
3273 // static | 3301 // static |
3274 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3302 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3275 GetScreenInfoForWindow(results, NULL); | 3303 GetScreenInfoForWindow(results, NULL); |
3276 } | 3304 } |
3277 | 3305 |
3278 } // namespace content | 3306 } // namespace content |
OLD | NEW |