| 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> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 void RenderWidgetHostViewAndroid::OnLostResources() { | 1962 void RenderWidgetHostViewAndroid::OnLostResources() { |
| 1963 ReleaseLocksOnSurface(); | 1963 ReleaseLocksOnSurface(); |
| 1964 if (layer_.get()) | 1964 if (layer_.get()) |
| 1965 DestroyDelegatedContent(); | 1965 DestroyDelegatedContent(); |
| 1966 DCHECK(ack_callbacks_.empty()); | 1966 DCHECK(ack_callbacks_.empty()); |
| 1967 // We should not loose a frame if we have readback requests pending. | 1967 // We should not loose a frame if we have readback requests pending. |
| 1968 DCHECK(readbacks_waiting_for_frame_.empty()); | 1968 DCHECK(readbacks_waiting_for_frame_.empty()); |
| 1969 } | 1969 } |
| 1970 | 1970 |
| 1971 // static | 1971 // static |
| 1972 void | 1972 void RenderWidgetHostViewAndroid:: |
| 1973 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( | 1973 PrepareTextureCopyOutputResultForDelegatedReadback( |
| 1974 const gfx::Size& dst_size_in_pixel, | 1974 const gfx::Size& dst_size_in_pixel, |
| 1975 const SkColorType color_type, | 1975 SkColorType color_type, |
| 1976 const base::TimeTicks& start_time, | 1976 const base::TimeTicks& start_time, |
| 1977 scoped_refptr<cc::Layer> readback_layer, | 1977 scoped_refptr<cc::Layer> readback_layer, |
| 1978 ReadbackRequestCallback& callback, | 1978 ReadbackRequestCallback& callback, |
| 1979 scoped_ptr<cc::CopyOutputResult> result) { | 1979 scoped_ptr<cc::CopyOutputResult> result) { |
| 1980 readback_layer->RemoveFromParent(); | 1980 readback_layer->RemoveFromParent(); |
| 1981 PrepareTextureCopyOutputResult( | 1981 PrepareTextureCopyOutputResult( |
| 1982 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); | 1982 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); |
| 1983 } | 1983 } |
| 1984 | 1984 |
| 1985 // static | 1985 // static |
| 1986 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1986 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| 1987 const gfx::Size& dst_size_in_pixel, | 1987 const gfx::Size& dst_size_in_pixel, |
| 1988 const SkColorType color_type, | 1988 SkColorType color_type, |
| 1989 const base::TimeTicks& start_time, | 1989 const base::TimeTicks& start_time, |
| 1990 ReadbackRequestCallback& callback, | 1990 ReadbackRequestCallback& callback, |
| 1991 scoped_ptr<cc::CopyOutputResult> result) { | 1991 scoped_ptr<cc::CopyOutputResult> result) { |
| 1992 base::ScopedClosureRunner scoped_callback_runner( | 1992 base::ScopedClosureRunner scoped_callback_runner( |
| 1993 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1993 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
| 1994 TRACE_EVENT0("cc", | 1994 TRACE_EVENT0("cc", |
| 1995 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1995 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
| 1996 | 1996 |
| 1997 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1997 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
| 1998 return; | 1998 return; |
| 1999 | 1999 |
| 2000 gfx::Size output_size_in_pixel; | 2000 gfx::Size output_size_in_pixel; |
| 2001 if (dst_size_in_pixel.IsEmpty()) | 2001 if (dst_size_in_pixel.IsEmpty()) |
| 2002 output_size_in_pixel = result->size(); | 2002 output_size_in_pixel = result->size(); |
| 2003 else | 2003 else |
| 2004 output_size_in_pixel = dst_size_in_pixel; | 2004 output_size_in_pixel = dst_size_in_pixel; |
| 2005 | 2005 |
| 2006 GLHelper* gl_helper = GetPostReadbackGLHelper(); |
| 2007 if (!gl_helper) |
| 2008 return; |
| 2009 if (!gl_helper->IsReadbackConfigSupported(color_type)) |
| 2010 color_type = kRGBA_8888_SkColorType; |
| 2006 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 2011 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 2007 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), | 2012 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
| 2008 output_size_in_pixel.height(), | 2013 output_size_in_pixel.height(), |
| 2009 color_type, | 2014 color_type, |
| 2010 kOpaque_SkAlphaType))) { | 2015 kOpaque_SkAlphaType))) { |
| 2011 return; | 2016 return; |
| 2012 } | 2017 } |
| 2013 | 2018 |
| 2014 GLHelper* gl_helper = GetPostReadbackGLHelper(); | |
| 2015 if (!gl_helper || !gl_helper->IsReadbackConfigSupported(color_type)) | |
| 2016 return; | |
| 2017 | 2019 |
| 2018 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 2020 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 2019 new SkAutoLockPixels(*bitmap)); | 2021 new SkAutoLockPixels(*bitmap)); |
| 2020 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 2022 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 2021 | 2023 |
| 2022 cc::TextureMailbox texture_mailbox; | 2024 cc::TextureMailbox texture_mailbox; |
| 2023 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 2025 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
| 2024 result->TakeTexture(&texture_mailbox, &release_callback); | 2026 result->TakeTexture(&texture_mailbox, &release_callback); |
| 2025 DCHECK(texture_mailbox.IsTexture()); | 2027 DCHECK(texture_mailbox.IsTexture()); |
| 2026 if (!texture_mailbox.IsTexture()) | 2028 if (!texture_mailbox.IsTexture()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2038 color_type, | 2040 color_type, |
| 2039 base::Bind(&CopyFromCompositingSurfaceFinished, | 2041 base::Bind(&CopyFromCompositingSurfaceFinished, |
| 2040 callback, | 2042 callback, |
| 2041 base::Passed(&release_callback), | 2043 base::Passed(&release_callback), |
| 2042 base::Passed(&bitmap), | 2044 base::Passed(&bitmap), |
| 2043 start_time, | 2045 start_time, |
| 2044 base::Passed(&bitmap_pixels_lock)), | 2046 base::Passed(&bitmap_pixels_lock)), |
| 2045 GLHelper::SCALER_QUALITY_GOOD); | 2047 GLHelper::SCALER_QUALITY_GOOD); |
| 2046 } | 2048 } |
| 2047 | 2049 |
| 2048 SkColorType RenderWidgetHostViewAndroid::PreferredReadbackFormat() { | |
| 2049 // Define the criteria here. If say the 16 texture readback is | |
| 2050 // supported we should go with that (this degrades quality) | |
| 2051 // or stick back to the default format. | |
| 2052 if (base::SysInfo::IsLowEndDevice()) { | |
| 2053 // TODO(sievers): Cannot use GLHelper here. Instead remove this API | |
| 2054 // and have CopyFromCompositingSurface() fall back to RGB8 if 565 was | |
| 2055 // requested but is not supported. | |
| 2056 GLHelper* gl_helper = GetPostReadbackGLHelper(); | |
| 2057 if (gl_helper && gl_helper->IsReadbackConfigSupported(kRGB_565_SkColorType)) | |
| 2058 return kRGB_565_SkColorType; | |
| 2059 } | |
| 2060 return kN32_SkColorType; | |
| 2061 } | |
| 2062 | |
| 2063 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, | 2050 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, |
| 2064 float y0, | 2051 float y0, |
| 2065 float x1, | 2052 float x1, |
| 2066 float y1) { | 2053 float y1) { |
| 2067 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); | 2054 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); |
| 2068 } | 2055 } |
| 2069 | 2056 |
| 2070 void RenderWidgetHostViewAndroid::OnStylusSelectUpdate(float x, float y) { | 2057 void RenderWidgetHostViewAndroid::OnStylusSelectUpdate(float x, float y) { |
| 2071 MoveRangeSelectionExtent(gfx::PointF(x, y)); | 2058 MoveRangeSelectionExtent(gfx::PointF(x, y)); |
| 2072 } | 2059 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2099 results->orientationAngle = display.RotationAsDegree(); | 2086 results->orientationAngle = display.RotationAsDegree(); |
| 2100 results->orientationType = | 2087 results->orientationType = |
| 2101 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2088 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 2102 gfx::DeviceDisplayInfo info; | 2089 gfx::DeviceDisplayInfo info; |
| 2103 results->depth = info.GetBitsPerPixel(); | 2090 results->depth = info.GetBitsPerPixel(); |
| 2104 results->depthPerComponent = info.GetBitsPerComponent(); | 2091 results->depthPerComponent = info.GetBitsPerComponent(); |
| 2105 results->isMonochrome = (results->depthPerComponent == 0); | 2092 results->isMonochrome = (results->depthPerComponent == 0); |
| 2106 } | 2093 } |
| 2107 | 2094 |
| 2108 } // namespace content | 2095 } // namespace content |
| OLD | NEW |