OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/debug/picture_debug_util.h" | 5 #include "cc/debug/picture_debug_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 23 matching lines...) Expand all Loading... |
34 const int kJpegQuality = 80; | 34 const int kJpegQuality = 80; |
35 std::vector<unsigned char> data; | 35 std::vector<unsigned char> data; |
36 | 36 |
37 // If bitmap is opaque, encode as JPEG. | 37 // If bitmap is opaque, encode as JPEG. |
38 // Otherwise encode as PNG. | 38 // Otherwise encode as PNG. |
39 bool encoding_succeeded = false; | 39 bool encoding_succeeded = false; |
40 if (info.isOpaque()) { | 40 if (info.isOpaque()) { |
41 DCHECK_LE(row_bytes, | 41 DCHECK_LE(row_bytes, |
42 static_cast<size_t>(std::numeric_limits<int>::max())); | 42 static_cast<size_t>(std::numeric_limits<int>::max())); |
43 encoding_succeeded = gfx::JPEGCodec::Encode( | 43 encoding_succeeded = gfx::JPEGCodec::Encode( |
44 reinterpret_cast<const unsigned char*>(pixels), | 44 reinterpret_cast<const unsigned char*>(pixels), kN32_SkColorType, |
45 gfx::JPEGCodec::FORMAT_SkBitmap, info.width(), info.height(), | 45 info.width(), info.height(), static_cast<int>(row_bytes), |
46 static_cast<int>(row_bytes), kJpegQuality, &data); | 46 kJpegQuality, &data); |
47 } else { | 47 } else { |
48 SkBitmap bm; | 48 SkBitmap bm; |
49 // The cast is ok, since we only read the bm. | 49 // The cast is ok, since we only read the bm. |
50 if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) { | 50 if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) { |
51 return nullptr; | 51 return nullptr; |
52 } | 52 } |
53 encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data); | 53 encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data); |
54 } | 54 } |
55 | 55 |
56 if (encoding_succeeded) { | 56 if (encoding_succeeded) { |
(...skipping 14 matching lines...) Expand all Loading... |
71 picture->serialize(&stream, &serializer); | 71 picture->serialize(&stream, &serializer); |
72 | 72 |
73 size_t serialized_size = stream.bytesWritten(); | 73 size_t serialized_size = stream.bytesWritten(); |
74 std::unique_ptr<char[]> serialized_picture(new char[serialized_size]); | 74 std::unique_ptr<char[]> serialized_picture(new char[serialized_size]); |
75 stream.copyTo(serialized_picture.get()); | 75 stream.copyTo(serialized_picture.get()); |
76 base::Base64Encode( | 76 base::Base64Encode( |
77 base::StringPiece(serialized_picture.get(), serialized_size), output); | 77 base::StringPiece(serialized_picture.get(), serialized_size), output); |
78 } | 78 } |
79 | 79 |
80 } // namespace cc | 80 } // namespace cc |
OLD | NEW |