Chromium Code Reviews| 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/chromeos/login/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 #include <zlib.h> | |
|
Ivan Korotkov
2012/08/28 16:16:13
This shouldn't make a big difference since you onl
bshe
2012/08/29 14:30:07
Done. Looks like I need to add third_party/zlib/zl
| |
| 17 | |
| 18 namespace chromeos { | |
| 19 | |
| 20 SimplePngEncoder::SimplePngEncoder( | |
| 21 scoped_refptr<base::RefCountedBytes> data, | |
| 22 SkBitmap image) | |
| 23 : data_(data), | |
| 24 image_(image) { | |
| 25 } | |
| 26 | |
| 27 void SimplePngEncoder::Run(EncoderCallback callback) { | |
| 28 base::WorkerPool::PostTaskAndReply( | |
| 29 FROM_HERE, | |
| 30 base::Bind(&SimplePngEncoder::EncodeWallpaper, this), | |
| 31 base::Bind(callback, data_), | |
| 32 true /* task_is_slow */); | |
| 33 } | |
| 34 | |
| 35 void SimplePngEncoder::EncodeWallpaper() { | |
| 36 if (cancel_flag_.IsSet()) | |
| 37 return; | |
| 38 SkAutoLockPixels lock_input(image_); | |
| 39 // Avoid compression to make things faster. | |
| 40 gfx::PNGCodec::EncodeWithCompressionLevel( | |
| 41 reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)), | |
| 42 gfx::PNGCodec::FORMAT_SkBitmap, | |
| 43 gfx::Size(image_.width(), image_.height()), | |
| 44 image_.width() * image_.bytesPerPixel(), | |
| 45 false, | |
| 46 std::vector<gfx::PNGCodec::Comment>(), | |
| 47 Z_NO_COMPRESSION, | |
| 48 &data_->data()); | |
| 49 } | |
| 50 | |
| 51 void SimplePngEncoder::Cancel() { | |
| 52 cancel_flag_.Set(); | |
| 53 } | |
| 54 | |
| 55 SimplePngEncoder::~SimplePngEncoder() { | |
| 56 } | |
| 57 | |
| 58 } // namespace chromeos | |
| OLD | NEW |