OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/compositor/surface_utils.h" | 5 #include "content/browser/compositor/surface_utils.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | |
8 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
9 #include "build/build_config.h" | 8 #include "build/build_config.h" |
10 #include "cc/output/copy_output_result.h" | 9 #include "cc/output/copy_output_result.h" |
11 #include "cc/resources/single_release_callback.h" | 10 #include "cc/resources/single_release_callback.h" |
12 #include "cc/surfaces/surface_id_allocator.h" | 11 #include "cc/surfaces/surface_id_allocator.h" |
13 #include "components/display_compositor/gl_helper.h" | 12 #include "components/display_compositor/gl_helper.h" |
14 #include "skia/ext/image_operations.h" | 13 #include "skia/ext/image_operations.h" |
15 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "third_party/skia/include/core/SkColorFilter.h" | 15 #include "third_party/skia/include/core/SkColorFilter.h" |
17 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 const gfx::Size& dst_size_in_pixel, | 58 const gfx::Size& dst_size_in_pixel, |
60 const SkColorType color_type, | 59 const SkColorType color_type, |
61 const content::ReadbackRequestCallback& callback, | 60 const content::ReadbackRequestCallback& callback, |
62 std::unique_ptr<cc::CopyOutputResult> result) { | 61 std::unique_ptr<cc::CopyOutputResult> result) { |
63 #if defined(OS_ANDROID) && !defined(USE_AURA) | 62 #if defined(OS_ANDROID) && !defined(USE_AURA) |
64 // TODO(wjmaclean): See if there's an equivalent pathway for Android and | 63 // TODO(wjmaclean): See if there's an equivalent pathway for Android and |
65 // implement it here. | 64 // implement it here. |
66 callback.Run(SkBitmap(), content::READBACK_FAILED); | 65 callback.Run(SkBitmap(), content::READBACK_FAILED); |
67 #else | 66 #else |
68 DCHECK(result->HasTexture()); | 67 DCHECK(result->HasTexture()); |
69 base::ScopedClosureRunner scoped_callback_runner( | |
70 base::Bind(callback, SkBitmap(), content::READBACK_FAILED)); | |
71 | 68 |
72 // TODO(siva.gunturi): We should be able to validate the format here using | 69 // TODO(siva.gunturi): We should be able to validate the format here using |
73 // GLHelper::IsReadbackConfigSupported before we processs the result. | 70 // GLHelper::IsReadbackConfigSupported before we processs the result. |
74 // See crbug.com/415682 and crbug.com/415131. | 71 // See crbug.com/415682 and crbug.com/415131. |
75 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); | 72 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
76 if (!bitmap->tryAllocPixels(SkImageInfo::Make( | 73 if (!bitmap->tryAllocPixels(SkImageInfo::Make( |
77 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, | 74 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, |
78 kOpaque_SkAlphaType))) { | 75 kOpaque_SkAlphaType))) { |
79 scoped_callback_runner.Reset(base::Bind( | 76 callback.Run(SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE); |
danakj
2016/06/24 23:57:27
Wait this actually want to call two callbacks, wit
Sergey Ulanov
2016/06/27 19:41:04
Are you saying that the old behavior is correct? T
| |
80 callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE)); | |
81 return; | 77 return; |
82 } | 78 } |
83 | 79 |
84 content::ImageTransportFactory* factory = | 80 content::ImageTransportFactory* factory = |
85 content::ImageTransportFactory::GetInstance(); | 81 content::ImageTransportFactory::GetInstance(); |
86 display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); | 82 display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); |
87 if (!gl_helper) | 83 if (!gl_helper) { |
84 callback.Run(SkBitmap(), content::READBACK_FAILED); | |
88 return; | 85 return; |
86 } | |
89 | 87 |
90 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 88 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
91 new SkAutoLockPixels(*bitmap)); | 89 new SkAutoLockPixels(*bitmap)); |
92 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); | 90 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); |
93 | 91 |
94 cc::TextureMailbox texture_mailbox; | 92 cc::TextureMailbox texture_mailbox; |
95 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 93 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
96 result->TakeTexture(&texture_mailbox, &release_callback); | 94 result->TakeTexture(&texture_mailbox, &release_callback); |
97 DCHECK(texture_mailbox.IsTexture()); | 95 DCHECK(texture_mailbox.IsTexture()); |
98 | 96 |
99 ignore_result(scoped_callback_runner.Release()); | |
100 | |
101 gl_helper->CropScaleReadbackAndCleanMailbox( | 97 gl_helper->CropScaleReadbackAndCleanMailbox( |
102 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 98 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
103 gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type, | 99 gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type, |
104 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 100 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
105 base::Passed(&release_callback), base::Passed(&bitmap), | 101 base::Passed(&release_callback), base::Passed(&bitmap), |
106 base::Passed(&bitmap_pixels_lock)), | 102 base::Passed(&bitmap_pixels_lock)), |
107 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 103 display_compositor::GLHelper::SCALER_QUALITY_GOOD); |
108 #endif | 104 #endif |
109 } | 105 } |
110 | 106 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 return; | 195 return; |
200 } | 196 } |
201 | 197 |
202 DCHECK(result->HasBitmap()); | 198 DCHECK(result->HasBitmap()); |
203 // Software path | 199 // Software path |
204 PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback, | 200 PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback, |
205 std::move(result)); | 201 std::move(result)); |
206 } | 202 } |
207 | 203 |
208 } // namespace content | 204 } // namespace content |
OLD | NEW |