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