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" | 7 #include "base/callback_helpers.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
11 #include "cc/resources/single_release_callback.h" | 11 #include "cc/resources/single_release_callback.h" |
12 #include "cc/surfaces/surface_id_allocator.h" | 12 #include "cc/surfaces/surface_id_allocator.h" |
13 #include "components/display_compositor/gl_helper.h" | 13 #include "content/browser/compositor/gl_helper.h" |
14 #include "skia/ext/image_operations.h" | 14 #include "skia/ext/image_operations.h" |
15 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "third_party/skia/include/core/SkColorFilter.h" | 16 #include "third_party/skia/include/core/SkColorFilter.h" |
17 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
18 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 18 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
19 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
20 | 20 |
21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
22 #include "content/browser/renderer_host/compositor_impl_android.h" | 22 #include "content/browser/renderer_host/compositor_impl_android.h" |
23 #else | 23 #else |
24 #include "content/browser/compositor/image_transport_factory.h" | 24 #include "content/browser/compositor/image_transport_factory.h" |
25 #include "ui/compositor/compositor.h" | 25 #include "ui/compositor/compositor.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 #if !defined(OS_ANDROID) || defined(USE_AURA) | 30 #if !defined(OS_ANDROID) || defined(USE_AURA) |
31 void CopyFromCompositingSurfaceFinished( | 31 void CopyFromCompositingSurfaceFinished( |
32 const content::ReadbackRequestCallback& callback, | 32 const content::ReadbackRequestCallback& callback, |
33 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 33 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
34 std::unique_ptr<SkBitmap> bitmap, | 34 std::unique_ptr<SkBitmap> bitmap, |
35 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 35 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
36 bool result) { | 36 bool result) { |
37 bitmap_pixels_lock.reset(); | 37 bitmap_pixels_lock.reset(); |
38 | 38 |
39 gpu::SyncToken sync_token; | 39 gpu::SyncToken sync_token; |
40 if (result) { | 40 if (result) { |
41 display_compositor::GLHelper* gl_helper = | 41 content::GLHelper* gl_helper = |
42 content::ImageTransportFactory::GetInstance()->GetGLHelper(); | 42 content::ImageTransportFactory::GetInstance()->GetGLHelper(); |
43 if (gl_helper) | 43 if (gl_helper) |
44 gl_helper->GenerateSyncToken(&sync_token); | 44 gl_helper->GenerateSyncToken(&sync_token); |
45 } | 45 } |
46 const bool lost_resource = !sync_token.HasData(); | 46 const bool lost_resource = !sync_token.HasData(); |
47 release_callback->Run(sync_token, lost_resource); | 47 release_callback->Run(sync_token, lost_resource); |
48 | 48 |
49 callback.Run(*bitmap, | 49 callback.Run(*bitmap, |
50 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); | 50 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); |
51 } | 51 } |
(...skipping 24 matching lines...) Expand all Loading... |
76 if (!bitmap->tryAllocPixels(SkImageInfo::Make( | 76 if (!bitmap->tryAllocPixels(SkImageInfo::Make( |
77 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, | 77 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, |
78 kOpaque_SkAlphaType))) { | 78 kOpaque_SkAlphaType))) { |
79 scoped_callback_runner.Reset(base::Bind( | 79 scoped_callback_runner.Reset(base::Bind( |
80 callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE)); | 80 callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE)); |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 content::ImageTransportFactory* factory = | 84 content::ImageTransportFactory* factory = |
85 content::ImageTransportFactory::GetInstance(); | 85 content::ImageTransportFactory::GetInstance(); |
86 display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); | 86 content::GLHelper* gl_helper = factory->GetGLHelper(); |
87 if (!gl_helper) | 87 if (!gl_helper) |
88 return; | 88 return; |
89 | 89 |
90 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 90 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
91 new SkAutoLockPixels(*bitmap)); | 91 new SkAutoLockPixels(*bitmap)); |
92 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); | 92 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); |
93 | 93 |
94 cc::TextureMailbox texture_mailbox; | 94 cc::TextureMailbox texture_mailbox; |
95 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 95 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
96 result->TakeTexture(&texture_mailbox, &release_callback); | 96 result->TakeTexture(&texture_mailbox, &release_callback); |
97 DCHECK(texture_mailbox.IsTexture()); | 97 DCHECK(texture_mailbox.IsTexture()); |
98 | 98 |
99 ignore_result(scoped_callback_runner.Release()); | 99 ignore_result(scoped_callback_runner.Release()); |
100 | 100 |
101 gl_helper->CropScaleReadbackAndCleanMailbox( | 101 gl_helper->CropScaleReadbackAndCleanMailbox( |
102 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 102 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
103 gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type, | 103 gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type, |
104 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 104 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
105 base::Passed(&release_callback), base::Passed(&bitmap), | 105 base::Passed(&release_callback), base::Passed(&bitmap), |
106 base::Passed(&bitmap_pixels_lock)), | 106 base::Passed(&bitmap_pixels_lock)), |
107 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 107 content::GLHelper::SCALER_QUALITY_GOOD); |
108 #endif | 108 #endif |
109 } | 109 } |
110 | 110 |
111 void PrepareBitmapCopyOutputResult( | 111 void PrepareBitmapCopyOutputResult( |
112 const gfx::Size& dst_size_in_pixel, | 112 const gfx::Size& dst_size_in_pixel, |
113 const SkColorType preferred_color_type, | 113 const SkColorType preferred_color_type, |
114 const content::ReadbackRequestCallback& callback, | 114 const content::ReadbackRequestCallback& callback, |
115 std::unique_ptr<cc::CopyOutputResult> result) { | 115 std::unique_ptr<cc::CopyOutputResult> result) { |
116 SkColorType color_type = preferred_color_type; | 116 SkColorType color_type = preferred_color_type; |
117 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { | 117 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return; | 199 return; |
200 } | 200 } |
201 | 201 |
202 DCHECK(result->HasBitmap()); | 202 DCHECK(result->HasBitmap()); |
203 // Software path | 203 // Software path |
204 PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback, | 204 PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback, |
205 std::move(result)); | 205 std::move(result)); |
206 } | 206 } |
207 | 207 |
208 } // namespace content | 208 } // namespace content |
OLD | NEW |