Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: ui/gfx/gtk_util.cc

Issue 9858001: ui/gfx: Make use of SkAutoLockPixels to automatically lock and unlock bitmap pixels properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698