| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 class MemoryHolder : public base::RefCounted<MemoryHolder> { | 95 class MemoryHolder : public base::RefCounted<MemoryHolder> { |
| 96 public: | 96 public: |
| 97 MemoryHolder(scoped_ptr<base::SharedMemory> shared_memory, | 97 MemoryHolder(scoped_ptr<base::SharedMemory> shared_memory, |
| 98 gfx::Size frame_size, | 98 gfx::Size frame_size, |
| 99 base::Callback<void()> callback) | 99 base::Callback<void()> callback) |
| 100 : shared_memory_(shared_memory.Pass()), | 100 : shared_memory_(shared_memory.Pass()), |
| 101 frame_size_(frame_size), | 101 frame_size_(frame_size), |
| 102 callback_(callback) {} | 102 callback_(callback) {} |
| 103 | 103 |
| 104 cc::TextureMailbox GetMailbox() { | 104 void GetMailbox(cc::TextureMailbox* mailbox, |
| 105 return cc::TextureMailbox( | 105 scoped_ptr<cc::ScopedReleaseCallback>* release_callback) { |
| 106 shared_memory_.get(), | 106 *mailbox = cc::TextureMailbox(shared_memory_.get(), frame_size_); |
| 107 frame_size_, | 107 *release_callback = cc::ScopedReleaseCallback::Create( |
| 108 base::Bind(ReleaseMailbox, make_scoped_refptr(this))); | 108 base::Bind(ReleaseMailbox, make_scoped_refptr(this))); |
| 109 } | 109 } |
| 110 | 110 |
| 111 private: | 111 private: |
| 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_; |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 accelerated_compositing_state_changed_ = false; | 1296 accelerated_compositing_state_changed_ = false; |
| 1297 | 1297 |
| 1298 bool is_compositing_active = host_->is_accelerated_compositing_active(); | 1298 bool is_compositing_active = host_->is_accelerated_compositing_active(); |
| 1299 if (is_compositing_active && current_surface_.get()) { | 1299 if (is_compositing_active && current_surface_.get()) { |
| 1300 window_->layer()->SetExternalTexture(current_surface_.get()); | 1300 window_->layer()->SetExternalTexture(current_surface_.get()); |
| 1301 current_frame_size_ = ConvertSizeToDIP( | 1301 current_frame_size_ = ConvertSizeToDIP( |
| 1302 current_surface_->device_scale_factor(), current_surface_->size()); | 1302 current_surface_->device_scale_factor(), current_surface_->size()); |
| 1303 CheckResizeLock(); | 1303 CheckResizeLock(); |
| 1304 framebuffer_holder_ = NULL; | 1304 framebuffer_holder_ = NULL; |
| 1305 } else if (is_compositing_active && framebuffer_holder_) { | 1305 } else if (is_compositing_active && framebuffer_holder_) { |
| 1306 cc::TextureMailbox mailbox = framebuffer_holder_->GetMailbox(); | 1306 cc::TextureMailbox mailbox; |
| 1307 scoped_ptr<cc::ScopedReleaseCallback> callback; |
| 1308 framebuffer_holder_->GetMailbox(&mailbox, &callback); |
| 1307 window_->layer()->SetTextureMailbox(mailbox, | 1309 window_->layer()->SetTextureMailbox(mailbox, |
| 1310 callback.Pass(), |
| 1308 last_swapped_surface_scale_factor_); | 1311 last_swapped_surface_scale_factor_); |
| 1309 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, | 1312 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, |
| 1310 mailbox.shared_memory_size()); | 1313 mailbox.shared_memory_size()); |
| 1311 CheckResizeLock(); | 1314 CheckResizeLock(); |
| 1312 } else { | 1315 } else { |
| 1313 window_->layer()->SetExternalTexture(NULL); | 1316 window_->layer()->SetExternalTexture(NULL); |
| 1314 resize_lock_.reset(); | 1317 resize_lock_.reset(); |
| 1315 host_->WasResized(); | 1318 host_->WasResized(); |
| 1316 framebuffer_holder_ = NULL; | 1319 framebuffer_holder_ = NULL; |
| 1317 } | 1320 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 | 1532 |
| 1530 scoped_refptr<MemoryHolder> holder(new MemoryHolder( | 1533 scoped_refptr<MemoryHolder> holder(new MemoryHolder( |
| 1531 shared_memory.Pass(), | 1534 shared_memory.Pass(), |
| 1532 frame_size, | 1535 frame_size, |
| 1533 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, | 1536 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
| 1534 AsWeakPtr(), | 1537 AsWeakPtr(), |
| 1535 output_surface_id, | 1538 output_surface_id, |
| 1536 frame_data->id))); | 1539 frame_data->id))); |
| 1537 bool first_frame = !framebuffer_holder_; | 1540 bool first_frame = !framebuffer_holder_; |
| 1538 framebuffer_holder_.swap(holder); | 1541 framebuffer_holder_.swap(holder); |
| 1539 cc::TextureMailbox mailbox = framebuffer_holder_->GetMailbox(); | 1542 cc::TextureMailbox mailbox; |
| 1543 scoped_ptr<cc::ScopedReleaseCallback> callback; |
| 1544 framebuffer_holder_->GetMailbox(&mailbox, &callback); |
| 1540 DCHECK(mailbox.IsSharedMemory()); | 1545 DCHECK(mailbox.IsSharedMemory()); |
| 1541 current_frame_size_ = frame_size_in_dip; | 1546 current_frame_size_ = frame_size_in_dip; |
| 1542 | 1547 |
| 1543 released_front_lock_ = NULL; | 1548 released_front_lock_ = NULL; |
| 1544 CheckResizeLock(); | 1549 CheckResizeLock(); |
| 1545 window_->layer()->SetTextureMailbox(mailbox, frame_device_scale_factor); | 1550 window_->layer()->SetTextureMailbox(mailbox, |
| 1551 callback.Pass(), |
| 1552 frame_device_scale_factor); |
| 1546 window_->SchedulePaintInRect( | 1553 window_->SchedulePaintInRect( |
| 1547 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); | 1554 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); |
| 1548 | 1555 |
| 1549 ui::Compositor* compositor = GetCompositor(); | 1556 ui::Compositor* compositor = GetCompositor(); |
| 1550 if (compositor) { | 1557 if (compositor) { |
| 1551 compositor->SetLatencyInfo(latency_info); | 1558 compositor->SetLatencyInfo(latency_info); |
| 1552 if (first_frame) { | 1559 if (first_frame) { |
| 1553 // Send swap for first frame, because no frame will be released due to | 1560 // Send swap for first frame, because no frame will be released due to |
| 1554 // that. | 1561 // that. |
| 1555 AddOnCommitCallbackAndDisableLocks( | 1562 AddOnCommitCallbackAndDisableLocks( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 PrepareTextureCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | 1777 PrepareTextureCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); |
| 1771 return; | 1778 return; |
| 1772 } | 1779 } |
| 1773 | 1780 |
| 1774 DCHECK(result->HasBitmap()); | 1781 DCHECK(result->HasBitmap()); |
| 1775 PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | 1782 PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); |
| 1776 } | 1783 } |
| 1777 | 1784 |
| 1778 static void CopyFromCompositingSurfaceFinished( | 1785 static void CopyFromCompositingSurfaceFinished( |
| 1779 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1786 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1780 const cc::TextureMailbox::ReleaseCallback& release_callback, | 1787 scoped_ptr<cc::ScopedReleaseCallback> release_callback, |
| 1781 scoped_ptr<SkBitmap> bitmap, | 1788 scoped_ptr<SkBitmap> bitmap, |
| 1782 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 1789 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
| 1783 bool result) { | 1790 bool result) { |
| 1784 bitmap_pixels_lock.reset(); | 1791 bitmap_pixels_lock.reset(); |
| 1785 release_callback.Run(0, false); | 1792 release_callback->Run(0, false); |
| 1786 callback.Run(result, *bitmap); | 1793 callback.Run(result, *bitmap); |
| 1787 } | 1794 } |
| 1788 | 1795 |
| 1789 // static | 1796 // static |
| 1790 void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult( | 1797 void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult( |
| 1791 const gfx::Size& dst_size_in_pixel, | 1798 const gfx::Size& dst_size_in_pixel, |
| 1792 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1799 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1793 scoped_ptr<cc::CopyOutputResult> result) { | 1800 scoped_ptr<cc::CopyOutputResult> result) { |
| 1794 base::ScopedClosureRunner scoped_callback_runner( | 1801 base::ScopedClosureRunner scoped_callback_runner( |
| 1795 base::Bind(callback, false, SkBitmap())); | 1802 base::Bind(callback, false, SkBitmap())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1807 | 1814 |
| 1808 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1815 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1809 GLHelper* gl_helper = factory->GetGLHelper(); | 1816 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1810 if (!gl_helper) | 1817 if (!gl_helper) |
| 1811 return; | 1818 return; |
| 1812 | 1819 |
| 1813 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1820 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 1814 new SkAutoLockPixels(*bitmap)); | 1821 new SkAutoLockPixels(*bitmap)); |
| 1815 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1822 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 1816 | 1823 |
| 1817 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture(); | 1824 cc::TextureMailbox texture_mailbox; |
| 1818 DCHECK(texture_mailbox->IsTexture()); | 1825 scoped_ptr<cc::ScopedReleaseCallback> release_callback; |
| 1819 if (!texture_mailbox->IsTexture()) | 1826 result->TakeTexture(&texture_mailbox, &release_callback); |
| 1827 DCHECK(texture_mailbox.IsTexture()); |
| 1828 if (!texture_mailbox.IsTexture()) |
| 1820 return; | 1829 return; |
| 1821 | 1830 |
| 1822 ignore_result(scoped_callback_runner.Release()); | 1831 ignore_result(scoped_callback_runner.Release()); |
| 1823 | 1832 |
| 1824 gl_helper->CropScaleReadbackAndCleanMailbox( | 1833 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 1825 texture_mailbox->name(), | 1834 texture_mailbox.name(), |
| 1826 texture_mailbox->sync_point(), | 1835 texture_mailbox.sync_point(), |
| 1827 result->size(), | 1836 result->size(), |
| 1828 gfx::Rect(result->size()), | 1837 gfx::Rect(result->size()), |
| 1829 dst_size_in_pixel, | 1838 dst_size_in_pixel, |
| 1830 pixels, | 1839 pixels, |
| 1831 base::Bind(&CopyFromCompositingSurfaceFinished, | 1840 base::Bind(&CopyFromCompositingSurfaceFinished, |
| 1832 callback, | 1841 callback, |
| 1833 texture_mailbox->callback(), | 1842 base::Passed(&release_callback), |
| 1834 base::Passed(&bitmap), | 1843 base::Passed(&bitmap), |
| 1835 base::Passed(&bitmap_pixels_lock))); | 1844 base::Passed(&bitmap_pixels_lock))); |
| 1836 } | 1845 } |
| 1837 | 1846 |
| 1838 // static | 1847 // static |
| 1839 void RenderWidgetHostViewAura::PrepareBitmapCopyOutputResult( | 1848 void RenderWidgetHostViewAura::PrepareBitmapCopyOutputResult( |
| 1840 const gfx::Size& dst_size_in_pixel, | 1849 const gfx::Size& dst_size_in_pixel, |
| 1841 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1850 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1842 scoped_ptr<cc::CopyOutputResult> result) { | 1851 scoped_ptr<cc::CopyOutputResult> result) { |
| 1843 DCHECK(result->HasBitmap()); | 1852 DCHECK(result->HasBitmap()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1857 SkBitmap bitmap = skia::ImageOperations::Resize( | 1866 SkBitmap bitmap = skia::ImageOperations::Resize( |
| 1858 *source, | 1867 *source, |
| 1859 skia::ImageOperations::RESIZE_BEST, | 1868 skia::ImageOperations::RESIZE_BEST, |
| 1860 dst_size_in_pixel.width(), | 1869 dst_size_in_pixel.width(), |
| 1861 dst_size_in_pixel.height()); | 1870 dst_size_in_pixel.height()); |
| 1862 callback.Run(true, bitmap); | 1871 callback.Run(true, bitmap); |
| 1863 } | 1872 } |
| 1864 | 1873 |
| 1865 static void CopyFromCompositingSurfaceFinishedForVideo( | 1874 static void CopyFromCompositingSurfaceFinishedForVideo( |
| 1866 const base::Callback<void(bool)>& callback, | 1875 const base::Callback<void(bool)>& callback, |
| 1867 const cc::TextureMailbox::ReleaseCallback& release_callback, | 1876 scoped_ptr<cc::ScopedReleaseCallback> release_callback, |
| 1868 bool result) { | 1877 bool result) { |
| 1869 release_callback.Run(0, false); | 1878 release_callback->Run(0, false); |
| 1870 callback.Run(result); | 1879 callback.Run(result); |
| 1871 } | 1880 } |
| 1872 | 1881 |
| 1873 // static | 1882 // static |
| 1874 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResultForVideo( | 1883 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResultForVideo( |
| 1875 base::WeakPtr<RenderWidgetHostViewAura> rwhva, | 1884 base::WeakPtr<RenderWidgetHostViewAura> rwhva, |
| 1876 scoped_refptr<media::VideoFrame> video_frame, | 1885 scoped_refptr<media::VideoFrame> video_frame, |
| 1877 const base::Callback<void(bool)>& callback, | 1886 const base::Callback<void(bool)>& callback, |
| 1878 scoped_ptr<cc::CopyOutputResult> result) { | 1887 scoped_ptr<cc::CopyOutputResult> result) { |
| 1879 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 1888 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 ignore_result(scoped_callback_runner.Release()); | 1941 ignore_result(scoped_callback_runner.Release()); |
| 1933 callback.Run(true); | 1942 callback.Run(true); |
| 1934 return; | 1943 return; |
| 1935 } | 1944 } |
| 1936 | 1945 |
| 1937 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1946 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1938 GLHelper* gl_helper = factory->GetGLHelper(); | 1947 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1939 if (!gl_helper) | 1948 if (!gl_helper) |
| 1940 return; | 1949 return; |
| 1941 | 1950 |
| 1942 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture(); | 1951 cc::TextureMailbox texture_mailbox; |
| 1943 DCHECK(texture_mailbox->IsTexture()); | 1952 scoped_ptr<cc::ScopedReleaseCallback> release_callback; |
| 1944 if (!texture_mailbox->IsTexture()) | 1953 result->TakeTexture(&texture_mailbox, &release_callback); |
| 1954 DCHECK(texture_mailbox.IsTexture()); |
| 1955 if (!texture_mailbox.IsTexture()) |
| 1945 return; | 1956 return; |
| 1946 | 1957 |
| 1947 gfx::Rect result_rect(result->size()); | 1958 gfx::Rect result_rect(result->size()); |
| 1948 | 1959 |
| 1949 content::ReadbackYUVInterface* yuv_readback_pipeline = | 1960 content::ReadbackYUVInterface* yuv_readback_pipeline = |
| 1950 rwhva->yuv_readback_pipeline_.get(); | 1961 rwhva->yuv_readback_pipeline_.get(); |
| 1951 if (yuv_readback_pipeline == NULL || | 1962 if (yuv_readback_pipeline == NULL || |
| 1952 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || | 1963 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || |
| 1953 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || | 1964 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || |
| 1954 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { | 1965 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1976 region_in_frame, | 1987 region_in_frame, |
| 1977 true, | 1988 true, |
| 1978 false)); | 1989 false)); |
| 1979 yuv_readback_pipeline = rwhva->yuv_readback_pipeline_.get(); | 1990 yuv_readback_pipeline = rwhva->yuv_readback_pipeline_.get(); |
| 1980 } | 1991 } |
| 1981 | 1992 |
| 1982 ignore_result(scoped_callback_runner.Release()); | 1993 ignore_result(scoped_callback_runner.Release()); |
| 1983 base::Callback<void(bool result)> finished_callback = base::Bind( | 1994 base::Callback<void(bool result)> finished_callback = base::Bind( |
| 1984 &CopyFromCompositingSurfaceFinishedForVideo, | 1995 &CopyFromCompositingSurfaceFinishedForVideo, |
| 1985 callback, | 1996 callback, |
| 1986 texture_mailbox->callback()); | 1997 base::Passed(&release_callback)); |
| 1987 yuv_readback_pipeline->ReadbackYUV( | 1998 yuv_readback_pipeline->ReadbackYUV( |
| 1988 texture_mailbox->name(), | 1999 texture_mailbox.name(), |
| 1989 texture_mailbox->sync_point(), | 2000 texture_mailbox.sync_point(), |
| 1990 video_frame.get(), | 2001 video_frame.get(), |
| 1991 finished_callback); | 2002 finished_callback); |
| 1992 } | 2003 } |
| 1993 | 2004 |
| 1994 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { | 2005 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { |
| 1995 GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL); | 2006 GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL); |
| 1996 } | 2007 } |
| 1997 | 2008 |
| 1998 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() { | 2009 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() { |
| 1999 return window_->GetToplevelWindow()->GetBoundsInScreen(); | 2010 return window_->GetToplevelWindow()->GetBoundsInScreen(); |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3269 RenderWidgetHost* widget) { | 3280 RenderWidgetHost* widget) { |
| 3270 return new RenderWidgetHostViewAura(widget); | 3281 return new RenderWidgetHostViewAura(widget); |
| 3271 } | 3282 } |
| 3272 | 3283 |
| 3273 // static | 3284 // static |
| 3274 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3285 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3275 GetScreenInfoForWindow(results, NULL); | 3286 GetScreenInfoForWindow(results, NULL); |
| 3276 } | 3287 } |
| 3277 | 3288 |
| 3278 } // namespace content | 3289 } // namespace content |
| OLD | NEW |