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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 gtk_init(&argc, &argv_pointer); | 75 gtk_init(&argc, &argv_pointer); |
76 for (size_t i = 0; i < args.size(); ++i) { | 76 for (size_t i = 0; i < args.size(); ++i) { |
77 free(argv[i]); | 77 free(argv[i]); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { | 81 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { |
82 if (bitmap->isNull()) | 82 if (bitmap->isNull()) |
83 return NULL; | 83 return NULL; |
84 | 84 |
85 bitmap->lockPixels(); | 85 SkAutoLockPixels lock_pixels(*bitmap); |
86 | 86 |
87 int width = bitmap->width(); | 87 int width = bitmap->width(); |
88 int height = bitmap->height(); | 88 int height = bitmap->height(); |
89 int stride = bitmap->rowBytes(); | 89 int stride = bitmap->rowBytes(); |
90 | 90 |
91 // SkBitmaps are premultiplied, we need to unpremultiply them. | 91 // SkBitmaps are premultiplied, we need to unpremultiply them. |
92 const int kBytesPerPixel = 4; | 92 const int kBytesPerPixel = 4; |
93 uint8* divided = static_cast<uint8*>(malloc(height * stride)); | 93 uint8* divided = static_cast<uint8*>(malloc(height * stride)); |
94 | 94 |
95 for (int y = 0, i = 0; y < height; y++) { | 95 for (int y = 0, i = 0; y < height; y++) { |
(...skipping 19 matching lines...) Expand all Loading... |
115 | 115 |
116 // This pixbuf takes ownership of our malloc()ed data and will | 116 // This pixbuf takes ownership of our malloc()ed data and will |
117 // free it for us when it is destroyed. | 117 // free it for us when it is destroyed. |
118 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data( | 118 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data( |
119 divided, | 119 divided, |
120 GDK_COLORSPACE_RGB, // The only colorspace gtk supports. | 120 GDK_COLORSPACE_RGB, // The only colorspace gtk supports. |
121 true, // There is an alpha channel. | 121 true, // There is an alpha channel. |
122 8, | 122 8, |
123 width, height, stride, &FreePixels, divided); | 123 width, height, stride, &FreePixels, divided); |
124 | 124 |
125 bitmap->unlockPixels(); | |
126 return pixbuf; | 125 return pixbuf; |
127 } | 126 } |
128 | 127 |
129 void SubtractRectanglesFromRegion(GdkRegion* region, | 128 void SubtractRectanglesFromRegion(GdkRegion* region, |
130 const std::vector<Rect>& cutouts) { | 129 const std::vector<Rect>& cutouts) { |
131 for (size_t i = 0; i < cutouts.size(); ++i) { | 130 for (size_t i = 0; i < cutouts.size(); ++i) { |
132 GdkRectangle rect = cutouts[i].ToGdkRectangle(); | 131 GdkRectangle rect = cutouts[i].ToGdkRectangle(); |
133 GdkRegion* rect_region = gdk_region_rectangle(&rect); | 132 GdkRegion* rect_region = gdk_region_rectangle(&rect); |
134 gdk_region_subtract(region, rect_region); | 133 gdk_region_subtract(region, rect_region); |
135 // TODO(deanm): It would be nice to be able to reuse the GdkRegion here. | 134 // TODO(deanm): It would be nice to be able to reuse the GdkRegion here. |
(...skipping 29 matching lines...) Expand all Loading... |
165 " GtkDialog::button-spacing = 6\n" | 164 " GtkDialog::button-spacing = 6\n" |
166 " GtkDialog::content-area-spacing = 18\n" | 165 " GtkDialog::content-area-spacing = 18\n" |
167 " GtkDialog::content-area-border = 0\n" | 166 " GtkDialog::content-area-border = 0\n" |
168 "}\n" | 167 "}\n" |
169 "widget \"about-dialog\" style : application \"about-dialog\"\n"; | 168 "widget \"about-dialog\" style : application \"about-dialog\"\n"; |
170 | 169 |
171 gtk_rc_parse_string(kRCText); | 170 gtk_rc_parse_string(kRCText); |
172 } | 171 } |
173 | 172 |
174 } // namespace gfx | 173 } // namespace gfx |
OLD | NEW |