Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/snapshot/snapshot.h" | 5 #include "ui/snapshot/snapshot.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 delegate_.reset(new TestPaintingWindowDelegate(window_bounds.size())); | 133 delegate_.reset(new TestPaintingWindowDelegate(window_bounds.size())); |
| 134 test_window_.reset(aura::test::CreateTestWindowWithDelegate( | 134 test_window_.reset(aura::test::CreateTestWindowWithDelegate( |
| 135 delegate_.get(), 0, window_bounds, root_window())); | 135 delegate_.get(), 0, window_bounds, root_window())); |
| 136 } | 136 } |
| 137 | 137 |
| 138 gfx::Image GrabSnapshotForTestWindow() { | 138 gfx::Image GrabSnapshotForTestWindow() { |
| 139 gfx::Rect source_rect(test_window_->bounds().size()); | 139 gfx::Rect source_rect(test_window_->bounds().size()); |
| 140 aura::Window::ConvertRectToTarget( | 140 aura::Window::ConvertRectToTarget( |
| 141 test_window(), root_window(), &source_rect); | 141 test_window(), root_window(), &source_rect); |
| 142 | 142 |
| 143 scoped_refptr<base::TestSimpleTaskRunner> task_runner( | |
| 144 new base::TestSimpleTaskRunner()); | |
| 145 scoped_refptr<SnapshotHolder> holder(new SnapshotHolder); | 143 scoped_refptr<SnapshotHolder> holder(new SnapshotHolder); |
| 146 ui::GrabWindowSnapshotAsync( | 144 ui::GrabWindowSnapshotAsync( |
| 147 root_window(), | 145 root_window(), |
| 148 source_rect, | 146 source_rect, |
| 149 task_runner, | |
| 150 base::Bind(&SnapshotHolder::SnapshotCallback, holder)); | 147 base::Bind(&SnapshotHolder::SnapshotCallback, holder)); |
| 151 | 148 |
| 152 // Wait for copy response. | 149 // Wait for copy response. |
| 150 // TODO(eseckler): This doesn't actually wait until the copy response is | |
|
Eric Seckler
2017/01/09 14:52:05
enne@/sadrul@: These tests are super flaky and don
sadrul
2017/01/10 05:12:50
Ugh, it does look like these tests are not actuall
enne (OOO)
2017/01/10 19:26:04
It sounds likely that this has been broken ever si
Eric Seckler
2017/01/11 15:58:44
OK, thanks!
Turns out, there's more failing than
sadrul
2017/01/11 17:16:53
I think the current expectations are correct. Soun
| |
| 151 // issued, because cc::Display::DrawAndSwap() executes surface draw | |
| 152 // callbacks before drawing the frame on the renderer. | |
| 153 WaitForDraw(); | 153 WaitForDraw(); |
| 154 // Run internal snapshot callback to scale/rotate response image. | |
| 155 task_runner->RunUntilIdle(); | |
| 156 // Run SnapshotHolder callback. | 154 // Run SnapshotHolder callback. |
| 157 helper_->RunAllPendingInMessageLoop(); | 155 helper_->RunAllPendingInMessageLoop(); |
| 158 | 156 |
| 159 if (holder->completed()) | 157 if (holder->completed()) |
| 160 return holder->image(); | 158 return holder->image(); |
| 161 | 159 |
| 162 // Callback never called. | 160 // Callback never called. |
| 163 NOTREACHED(); | 161 NOTREACHED(); |
| 164 return gfx::Image(); | 162 return gfx::Image(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 private: | 165 private: |
| 168 class SnapshotHolder : public base::RefCountedThreadSafe<SnapshotHolder> { | 166 class SnapshotHolder : public base::RefCountedThreadSafe<SnapshotHolder> { |
| 169 public: | 167 public: |
| 170 SnapshotHolder() : completed_(false) {} | 168 SnapshotHolder() : completed_(false) {} |
| 171 | 169 |
| 172 void SnapshotCallback(scoped_refptr<base::RefCountedBytes> png_data) { | 170 void SnapshotCallback(const gfx::Image& image) { |
| 173 DCHECK(!completed_); | 171 DCHECK(!completed_); |
| 174 image_ = gfx::Image::CreateFrom1xPNGBytes(&(png_data->data()[0]), | 172 image_ = image; |
| 175 png_data->size()); | |
| 176 completed_ = true; | 173 completed_ = true; |
| 177 } | 174 } |
| 178 bool completed() const { | 175 bool completed() const { |
| 179 return completed_; | 176 return completed_; |
| 180 }; | 177 }; |
| 181 const gfx::Image& image() const { return image_; } | 178 const gfx::Image& image() const { return image_; } |
| 182 | 179 |
| 183 private: | 180 private: |
| 184 friend class base::RefCountedThreadSafe<SnapshotHolder>; | 181 friend class base::RefCountedThreadSafe<SnapshotHolder>; |
| 185 | 182 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 gfx::SizeF snapshot_size(test_bounds.size()); | 292 gfx::SizeF snapshot_size(test_bounds.size()); |
| 296 snapshot_size.Scale(2.0f); | 293 snapshot_size.Scale(2.0f); |
| 297 | 294 |
| 298 gfx::Image snapshot = GrabSnapshotForTestWindow(); | 295 gfx::Image snapshot = GrabSnapshotForTestWindow(); |
| 299 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), | 296 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), |
| 300 snapshot.Size().ToString()); | 297 snapshot.Size().ToString()); |
| 301 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); | 298 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); |
| 302 } | 299 } |
| 303 | 300 |
| 304 } // namespace ui | 301 } // namespace ui |
| OLD | NEW |