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/gfx/gtk_util.h" | 5 #include "ui/gfx/gtk_util.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 void GtkInitFromCommandLine(const CommandLine& command_line) { | 82 void GtkInitFromCommandLine(const CommandLine& command_line) { |
83 CommonInitFromCommandLine(command_line, gtk_init); | 83 CommonInitFromCommandLine(command_line, gtk_init); |
84 } | 84 } |
85 | 85 |
86 void GdkInitFromCommandLine(const CommandLine& command_line) { | 86 void GdkInitFromCommandLine(const CommandLine& command_line) { |
87 CommonInitFromCommandLine(command_line, gdk_init); | 87 CommonInitFromCommandLine(command_line, gdk_init); |
88 } | 88 } |
89 | 89 |
90 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { | 90 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap) { |
91 if (bitmap->isNull()) | 91 if (bitmap.isNull()) |
92 return NULL; | 92 return NULL; |
93 | 93 |
94 SkAutoLockPixels lock_pixels(*bitmap); | 94 SkAutoLockPixels lock_pixels(bitmap); |
95 | 95 |
96 int width = bitmap->width(); | 96 int width = bitmap.width(); |
97 int height = bitmap->height(); | 97 int height = bitmap.height(); |
98 int stride = bitmap->rowBytes(); | 98 int stride = bitmap.rowBytes(); |
99 | 99 |
100 // SkBitmaps are premultiplied, we need to unpremultiply them. | 100 // SkBitmaps are premultiplied, we need to unpremultiply them. |
101 const int kBytesPerPixel = 4; | 101 const int kBytesPerPixel = 4; |
102 uint8* divided = static_cast<uint8*>(malloc(height * stride)); | 102 uint8* divided = static_cast<uint8*>(malloc(height * stride)); |
103 | 103 |
104 for (int y = 0, i = 0; y < height; y++) { | 104 for (int y = 0, i = 0; y < height; y++) { |
105 for (int x = 0; x < width; x++) { | 105 for (int x = 0; x < width; x++) { |
106 uint32 pixel = bitmap->getAddr32(0, y)[x]; | 106 uint32 pixel = bitmap.getAddr32(0, y)[x]; |
107 | 107 |
108 int alpha = SkColorGetA(pixel); | 108 int alpha = SkColorGetA(pixel); |
109 if (alpha != 0 && alpha != 255) { | 109 if (alpha != 0 && alpha != 255) { |
110 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); | 110 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel); |
111 divided[i + 0] = SkColorGetR(unmultiplied); | 111 divided[i + 0] = SkColorGetR(unmultiplied); |
112 divided[i + 1] = SkColorGetG(unmultiplied); | 112 divided[i + 1] = SkColorGetG(unmultiplied); |
113 divided[i + 2] = SkColorGetB(unmultiplied); | 113 divided[i + 2] = SkColorGetB(unmultiplied); |
114 divided[i + 3] = alpha; | 114 divided[i + 3] = alpha; |
115 } else { | 115 } else { |
116 divided[i + 0] = SkColorGetR(pixel); | 116 divided[i + 0] = SkColorGetR(pixel); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 " GtkDialog::button-spacing = 6\n" | 173 " GtkDialog::button-spacing = 6\n" |
174 " GtkDialog::content-area-spacing = 18\n" | 174 " GtkDialog::content-area-spacing = 18\n" |
175 " GtkDialog::content-area-border = 0\n" | 175 " GtkDialog::content-area-border = 0\n" |
176 "}\n" | 176 "}\n" |
177 "widget \"about-dialog\" style : application \"about-dialog\"\n"; | 177 "widget \"about-dialog\" style : application \"about-dialog\"\n"; |
178 | 178 |
179 gtk_rc_parse_string(kRCText); | 179 gtk_rc_parse_string(kRCText); |
180 } | 180 } |
181 | 181 |
182 } // namespace gfx | 182 } // namespace gfx |
OLD | NEW |