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

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

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
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/numerics/safe_conversions.h"
11 #include "base/task_runner_util.h" 11 #include "base/task_runner_util.h"
12 #include "cc/output/copy_output_request.h" 12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/copy_output_result.h" 13 #include "cc/output/copy_output_result.h"
14 #include "skia/ext/image_operations.h" 14 #include "skia/ext/image_operations.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/core/SkPixelRef.h" 16 #include "third_party/skia/include/core/SkPixelRef.h"
17 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/compositor/compositor.h" 19 #include "ui/compositor/compositor.h"
20 #include "ui/compositor/dip_util.h" 20 #include "ui/compositor/dip_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 gfx::Size target_size_pre_rotation, 78 gfx::Size target_size_pre_rotation,
79 gfx::Display::Rotation rotation) { 79 gfx::Display::Rotation rotation) {
80 SkBitmap bitmap = 80 SkBitmap bitmap =
81 ScaleAndRotateBitmap(input_bitmap, target_size_pre_rotation, rotation); 81 ScaleAndRotateBitmap(input_bitmap, target_size_pre_rotation, rotation);
82 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); 82 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes);
83 unsigned char* pixels = 83 unsigned char* pixels =
84 reinterpret_cast<unsigned char*>(bitmap.pixelRef()->pixels()); 84 reinterpret_cast<unsigned char*>(bitmap.pixelRef()->pixels());
85 if (!gfx::PNGCodec::Encode(pixels, 85 if (!gfx::PNGCodec::Encode(pixels,
86 gfx::PNGCodec::FORMAT_BGRA, 86 gfx::PNGCodec::FORMAT_BGRA,
87 gfx::Size(bitmap.width(), bitmap.height()), 87 gfx::Size(bitmap.width(), bitmap.height()),
88 base::checked_numeric_cast<int>(bitmap.rowBytes()), 88 base::checked_cast<int>(bitmap.rowBytes()),
89 true, 89 true,
90 std::vector<gfx::PNGCodec::Comment>(), 90 std::vector<gfx::PNGCodec::Comment>(),
91 &png_data->data())) { 91 &png_data->data())) {
92 return scoped_refptr<base::RefCountedBytes>(); 92 return scoped_refptr<base::RefCountedBytes>();
93 } 93 }
94 return png_data; 94 return png_data;
95 } 95 }
96 96
97 void ScaleAndRotateCopyOutputResult( 97 void ScaleAndRotateCopyOutputResult(
98 const GrabWindowSnapshotAsyncCallback& callback, 98 const GrabWindowSnapshotAsyncCallback& callback,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 gfx::Display display = 188 gfx::Display display =
189 gfx::Screen::GetScreenFor(window)->GetDisplayNearestWindow(window); 189 gfx::Screen::GetScreenFor(window)->GetDisplayNearestWindow(window);
190 RotateBitmap(&bitmap, display.rotation()); 190 RotateBitmap(&bitmap, display.rotation());
191 191
192 unsigned char* pixels = reinterpret_cast<unsigned char*>( 192 unsigned char* pixels = reinterpret_cast<unsigned char*>(
193 bitmap.pixelRef()->pixels()); 193 bitmap.pixelRef()->pixels());
194 return gfx::PNGCodec::Encode( 194 return gfx::PNGCodec::Encode(
195 pixels, gfx::PNGCodec::FORMAT_BGRA, 195 pixels, gfx::PNGCodec::FORMAT_BGRA,
196 gfx::Size(bitmap.width(), bitmap.height()), 196 gfx::Size(bitmap.width(), bitmap.height()),
197 base::checked_numeric_cast<int>(bitmap.rowBytes()), 197 base::checked_cast<int>(bitmap.rowBytes()),
198 true, std::vector<gfx::PNGCodec::Comment>(), 198 true, std::vector<gfx::PNGCodec::Comment>(),
199 png_representation); 199 png_representation);
200 } 200 }
201 201
202 void MakeAsyncCopyRequest( 202 void MakeAsyncCopyRequest(
203 gfx::NativeWindow window, 203 gfx::NativeWindow window,
204 const gfx::Rect& source_rect, 204 const gfx::Rect& source_rect,
205 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { 205 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) {
206 scoped_ptr<cc::CopyOutputRequest> request = 206 scoped_ptr<cc::CopyOutputRequest> request =
207 cc::CopyOutputRequest::CreateBitmapRequest(callback); 207 cc::CopyOutputRequest::CreateBitmapRequest(callback);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 MakeAsyncCopyRequest(window, 255 MakeAsyncCopyRequest(window,
256 source_rect, 256 source_rect,
257 base::Bind(&ScaleRotateAndEncodeCopyOutputResult, 257 base::Bind(&ScaleRotateAndEncodeCopyOutputResult,
258 callback, 258 callback,
259 target_size, 259 target_size,
260 rotation, 260 rotation,
261 background_task_runner)); 261 background_task_runner));
262 } 262 }
263 263
264 } // namespace ui 264 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698