| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/rect_f.h" | 28 #include "ui/gfx/rect_f.h" |
| 29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 30 #include "ui/gfx/skbitmap_operations.h" | 30 #include "ui/gfx/skbitmap_operations.h" |
| 31 #include "ui/gfx/transform.h" | 31 #include "ui/gfx/transform.h" |
| 32 | 32 |
| 33 namespace ui { | 33 namespace ui { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 void OnFrameScalingFinished( | 37 void OnFrameScalingFinished( |
| 38 const GrapWindowSnapshotAsyncCallback& callback, | 38 const GrabWindowSnapshotAsyncCallback& callback, |
| 39 const SkBitmap& scaled_bitmap) { | 39 const SkBitmap& scaled_bitmap) { |
| 40 callback.Run(gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(scaled_bitmap))); | 40 callback.Run(gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(scaled_bitmap))); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ScaleCopyOutputResult( | 43 void ScaleCopyOutputResult( |
| 44 const GrapWindowSnapshotAsyncCallback& callback, | 44 const GrabWindowSnapshotAsyncCallback& callback, |
| 45 const gfx::Size& target_size, | 45 const gfx::Size& target_size, |
| 46 scoped_refptr<base::TaskRunner> background_task_runner, | 46 scoped_refptr<base::TaskRunner> background_task_runner, |
| 47 scoped_ptr<cc::CopyOutputResult> result) { | 47 scoped_ptr<cc::CopyOutputResult> result) { |
| 48 if (result->IsEmpty()) { | 48 if (result->IsEmpty()) { |
| 49 callback.Run(gfx::Image()); | 49 callback.Run(gfx::Image()); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // There are two overrides for skia::ImageOperations::Resize(), so we need get | 53 // There are two overrides for skia::ImageOperations::Resize(), so we need get |
| 54 // pointer to the right override explicitly (otherwise the base::Bind() call | 54 // pointer to the right override explicitly (otherwise the base::Bind() call |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 unsigned char* pixels = reinterpret_cast<unsigned char*>( | 129 unsigned char* pixels = reinterpret_cast<unsigned char*>( |
| 130 bitmap.pixelRef()->pixels()); | 130 bitmap.pixelRef()->pixels()); |
| 131 return gfx::PNGCodec::Encode( | 131 return gfx::PNGCodec::Encode( |
| 132 pixels, gfx::PNGCodec::FORMAT_BGRA, | 132 pixels, gfx::PNGCodec::FORMAT_BGRA, |
| 133 gfx::Size(bitmap.width(), bitmap.height()), | 133 gfx::Size(bitmap.width(), bitmap.height()), |
| 134 base::checked_numeric_cast<int>(bitmap.rowBytes()), | 134 base::checked_numeric_cast<int>(bitmap.rowBytes()), |
| 135 true, std::vector<gfx::PNGCodec::Comment>(), | 135 true, std::vector<gfx::PNGCodec::Comment>(), |
| 136 png_representation); | 136 png_representation); |
| 137 } | 137 } |
| 138 | 138 |
| 139 SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( | 139 SNAPSHOT_EXPORT void GrabWindowSnapshotAsync( |
| 140 gfx::NativeWindow window, | 140 gfx::NativeWindow window, |
| 141 const gfx::Rect& source_rect, | 141 const gfx::Rect& source_rect, |
| 142 const gfx::Size& target_size, | 142 const gfx::Size& target_size, |
| 143 scoped_refptr<base::TaskRunner> background_task_runner, | 143 scoped_refptr<base::TaskRunner> background_task_runner, |
| 144 const GrapWindowSnapshotAsyncCallback& callback) { | 144 const GrabWindowSnapshotAsyncCallback& callback) { |
| 145 scoped_ptr<cc::CopyOutputRequest> request = | 145 scoped_ptr<cc::CopyOutputRequest> request = |
| 146 cc::CopyOutputRequest::CreateBitmapRequest( | 146 cc::CopyOutputRequest::CreateBitmapRequest( |
| 147 base::Bind(&ScaleCopyOutputResult, callback, target_size, | 147 base::Bind(&ScaleCopyOutputResult, callback, target_size, |
| 148 background_task_runner)); | 148 background_task_runner)); |
| 149 request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect)); | 149 request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect)); |
| 150 window->layer()->RequestCopyOfOutput(request.Pass()); | 150 window->layer()->RequestCopyOfOutput(request.Pass()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace ui | 153 } // namespace ui |
| OLD | NEW |