OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/options2/chromeos/simple_png_encoder.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/threading/worker_pool.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/common/url_constants.h" |
| 12 #include "ui/gfx/codec/png_codec.h" |
| 13 #include "ui/gfx/size.h" |
| 14 #include "ui/gfx/skia_util.h" |
| 15 |
| 16 extern "C" { |
| 17 #if defined(USE_SYSTEM_ZLIB) |
| 18 #include <zlib.h> |
| 19 #else |
| 20 #include "third_party/zlib/zlib.h" |
| 21 #endif |
| 22 } |
| 23 |
| 24 namespace chromeos { |
| 25 |
| 26 SimplePngEncoder::SimplePngEncoder( |
| 27 scoped_refptr<base::RefCountedBytes> data, |
| 28 SkBitmap image, |
| 29 base::Closure cancel_callback) |
| 30 : data_(data), |
| 31 image_(image), |
| 32 cancel_callback_(cancel_callback) { |
| 33 } |
| 34 |
| 35 void SimplePngEncoder::Run(EncoderCallback callback) { |
| 36 base::WorkerPool::PostTaskAndReply( |
| 37 FROM_HERE, |
| 38 base::Bind(&SimplePngEncoder::EncodeWallpaper, this), |
| 39 base::Bind(callback, data_), |
| 40 true /* task_is_slow */); |
| 41 } |
| 42 |
| 43 void SimplePngEncoder::EncodeWallpaper() { |
| 44 if (cancel_flag_.IsSet()) |
| 45 return; |
| 46 SkAutoLockPixels lock_input(image_); |
| 47 // Avoid compression to make things faster. |
| 48 gfx::PNGCodec::EncodeWithCompressionLevel( |
| 49 reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)), |
| 50 gfx::PNGCodec::FORMAT_SkBitmap, |
| 51 gfx::Size(image_.width(), image_.height()), |
| 52 image_.width() * image_.bytesPerPixel(), |
| 53 false, |
| 54 std::vector<gfx::PNGCodec::Comment>(), |
| 55 Z_NO_COMPRESSION, |
| 56 &data_->data()); |
| 57 } |
| 58 |
| 59 void SimplePngEncoder::Cancel() { |
| 60 cancel_flag_.Set(); |
| 61 cancel_callback_.Run(); |
| 62 } |
| 63 |
| 64 SimplePngEncoder::~SimplePngEncoder() {} |
| 65 |
| 66 } // namespace chromeos |
OLD | NEW |