OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "linux_util.h" | 5 #include "base/linux_util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/command_line.h" |
| 12 #include "base/process_util.h" |
| 13 |
9 namespace base { | 14 namespace base { |
10 | 15 |
11 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { | 16 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { |
12 if (stride == 0) | 17 if (stride == 0) |
13 stride = width * 4; | 18 stride = width * 4; |
14 | 19 |
15 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); | 20 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); |
16 | 21 |
17 // We have to copy the pixels and swap from BGRA to RGBA. | 22 // We have to copy the pixels and swap from BGRA to RGBA. |
18 for (int i = 0; i < height; ++i) { | 23 for (int i = 0; i < height; ++i) { |
19 for (int j = 0; j < width; ++j) { | 24 for (int j = 0; j < width; ++j) { |
20 int idx = i * stride + j * 4; | 25 int idx = i * stride + j * 4; |
21 new_pixels[idx] = pixels[idx + 2]; | 26 new_pixels[idx] = pixels[idx + 2]; |
22 new_pixels[idx + 1] = pixels[idx + 1]; | 27 new_pixels[idx + 1] = pixels[idx + 1]; |
23 new_pixels[idx + 2] = pixels[idx]; | 28 new_pixels[idx + 2] = pixels[idx]; |
24 new_pixels[idx + 3] = pixels[idx + 3]; | 29 new_pixels[idx + 3] = pixels[idx + 3]; |
25 } | 30 } |
26 } | 31 } |
27 | 32 |
28 return new_pixels; | 33 return new_pixels; |
29 } | 34 } |
30 | 35 |
| 36 // We use this static string to hold the Linux distro info. If we |
| 37 // crash, the crash handler code will send this in the crash dump. |
| 38 std::string linux_distro = "Unknown"; |
| 39 |
| 40 std::string GetLinuxDistro() { |
| 41 static bool checked_distro = false; |
| 42 if (!checked_distro) { |
| 43 std::vector<std::string> argv; |
| 44 argv.push_back("lsb_release"); |
| 45 argv.push_back("-d"); |
| 46 std::string output; |
| 47 base::GetAppOutput(CommandLine(argv), &output); |
| 48 if (output.length() > 0) { |
| 49 // lsb_release -d should return: Description:<tab>Distro Info |
| 50 static const std::string field = "Description:\t"; |
| 51 if (output.compare(0, field.length(), field) == 0) |
| 52 linux_distro = output.substr(field.length()); |
| 53 } |
| 54 // We do this check only once per process. If it fails, there's |
| 55 // little reason to believe it will work if we attempt to run |
| 56 // lsb_release again. |
| 57 checked_distro = true; |
| 58 } |
| 59 return linux_distro; |
| 60 } |
| 61 |
31 } // namespace base | 62 } // namespace base |
OLD | NEW |