Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: ui/snapshot/snapshot_aura.cc

Issue 127103002: Make WindowReachedScreen support async readback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac /o\ Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/snapshot/snapshot_android.cc ('k') | ui/snapshot/snapshot_aura_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/safe_numerics.h" 10 #include "base/safe_numerics.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 bool GrabViewSnapshot(gfx::NativeView view, 171 bool GrabViewSnapshot(gfx::NativeView view,
172 std::vector<unsigned char>* png_representation, 172 std::vector<unsigned char>* png_representation,
173 const gfx::Rect& snapshot_bounds) { 173 const gfx::Rect& snapshot_bounds) {
174 return GrabWindowSnapshot(view, png_representation, snapshot_bounds); 174 return GrabWindowSnapshot(view, png_representation, snapshot_bounds);
175 } 175 }
176 176
177 bool GrabWindowSnapshot(gfx::NativeWindow window, 177 bool GrabWindowSnapshot(gfx::NativeWindow window,
178 std::vector<unsigned char>* png_representation, 178 std::vector<unsigned char>* png_representation,
179 const gfx::Rect& snapshot_bounds) { 179 const gfx::Rect& snapshot_bounds) {
180 gfx::Rect read_pixels_bounds_in_pixel = 180 // Not supported in Aura. Callers should fall back to the async version.
181 GetTargetBoundsFromWindow(window, snapshot_bounds); 181 return false;
182
183 ui::Compositor* compositor = window->layer()->GetCompositor();
184 SkBitmap bitmap;
185 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel))
186 return false;
187
188 gfx::Display display =
189 gfx::Screen::GetScreenFor(window)->GetDisplayNearestWindow(window);
190 RotateBitmap(&bitmap, display.rotation());
191
192 unsigned char* pixels = reinterpret_cast<unsigned char*>(
193 bitmap.pixelRef()->pixels());
194 return gfx::PNGCodec::Encode(
195 pixels, gfx::PNGCodec::FORMAT_BGRA,
196 gfx::Size(bitmap.width(), bitmap.height()),
197 base::checked_numeric_cast<int>(bitmap.rowBytes()),
198 true, std::vector<gfx::PNGCodec::Comment>(),
199 png_representation);
200 } 182 }
201 183
202 void MakeAsyncCopyRequest( 184 void MakeAsyncCopyRequest(
203 gfx::NativeWindow window, 185 gfx::NativeWindow window,
204 const gfx::Rect& source_rect, 186 const gfx::Rect& source_rect,
205 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { 187 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) {
206 scoped_ptr<cc::CopyOutputRequest> request = 188 scoped_ptr<cc::CopyOutputRequest> request =
207 cc::CopyOutputRequest::CreateBitmapRequest(callback); 189 cc::CopyOutputRequest::CreateBitmapRequest(callback);
208 request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect)); 190 request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect));
209 window->layer()->RequestCopyOfOutput(request.Pass()); 191 window->layer()->RequestCopyOfOutput(request.Pass());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 .rotation(); 236 .rotation();
255 MakeAsyncCopyRequest(window, 237 MakeAsyncCopyRequest(window,
256 source_rect, 238 source_rect,
257 base::Bind(&ScaleRotateAndEncodeCopyOutputResult, 239 base::Bind(&ScaleRotateAndEncodeCopyOutputResult,
258 callback, 240 callback,
259 target_size, 241 target_size,
260 rotation, 242 rotation,
261 background_task_runner)); 243 background_task_runner));
262 } 244 }
263 245
246 void GrabViewSnapshotAsync(
247 gfx::NativeView view,
248 const gfx::Rect& source_rect,
249 scoped_refptr<base::TaskRunner> background_task_runner,
250 const GrabWindowSnapshotAsyncPNGCallback& callback) {
251 GrabWindowSnapshotAsync(view, source_rect, background_task_runner, callback);
252 }
253
254
264 } // namespace ui 255 } // namespace ui
OLDNEW
« no previous file with comments | « ui/snapshot/snapshot_android.cc ('k') | ui/snapshot/snapshot_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698