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

Side by Side Diff: skia/ext/bitmap_platform_device_mac.cc

Issue 3227007: Move BitmapPlatformDevice::makeOpaque into a shared file (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 3 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
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.h ('k') | skia/ext/bitmap_platform_device_win.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "skia/ext/bitmap_platform_device_mac.h" 5 #include "skia/ext/bitmap_platform_device_mac.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "base/mac_util.h" 9 #include "base/mac_util.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "skia/ext/bitmap_platform_device_data.h" 11 #include "skia/ext/bitmap_platform_device_data.h"
12 #include "skia/ext/skia_utils_mac.h" 12 #include "skia/ext/skia_utils_mac.h"
13 #include "third_party/skia/include/core/SkMatrix.h" 13 #include "third_party/skia/include/core/SkMatrix.h"
14 #include "third_party/skia/include/core/SkRegion.h" 14 #include "third_party/skia/include/core/SkRegion.h"
15 #include "third_party/skia/include/core/SkTypes.h" 15 #include "third_party/skia/include/core/SkTypes.h"
16 #include "third_party/skia/include/core/SkUtils.h" 16 #include "third_party/skia/include/core/SkUtils.h"
17 17
18 namespace skia { 18 namespace skia {
19 19
20 namespace { 20 namespace {
21 21
22 // Constrains position and size to fit within available_size. If |size| is -1,
23 // all the |available_size| is used. Returns false if the position is out of
24 // |available_size|.
25 bool Constrain(int available_size, int* position, int *size) {
26 if (*size < -2)
27 return false;
28
29 if (*position < 0) {
30 if (*size != -1)
31 *size += *position;
32 *position = 0;
33 }
34 if (*size == 0 || *position >= available_size)
35 return false;
36
37 if (*size > 0) {
38 int overflow = (*position + *size) - available_size;
39 if (overflow > 0) {
40 *size -= overflow;
41 }
42 } else {
43 // Fill up available size.
44 *size = available_size - *position;
45 }
46 return true;
47 }
48
49 static CGContextRef CGContextForData(void* data, int width, int height) { 22 static CGContextRef CGContextForData(void* data, int width, int height) {
50 #define HAS_ARGB_SHIFTS(a, r, g, b) \ 23 #define HAS_ARGB_SHIFTS(a, r, g, b) \
51 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ 24 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
52 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) 25 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b))
53 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) 26 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
54 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple 27 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple
55 // recommends these flags for improved CG performance. 28 // recommends these flags for improved CG performance.
56 CGContextRef context = 29 CGContextRef context =
57 CGBitmapContextCreate(data, width, height, 8, width * 4, 30 CGBitmapContextCreate(data, width, height, 8, width * 4,
58 mac_util::GetSystemColorSpace(), 31 mac_util::GetSystemColorSpace(),
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const SkBitmap& bitmap = accessBitmap(true); 245 const SkBitmap& bitmap = accessBitmap(true);
273 SkAutoLockPixels lock(bitmap); 246 SkAutoLockPixels lock(bitmap);
274 uint32_t* data = bitmap.getAddr32(0, 0); 247 uint32_t* data = bitmap.getAddr32(0, 0);
275 return static_cast<SkColor>(data[x + y * width()]); 248 return static_cast<SkColor>(data[x + y * width()]);
276 } 249 }
277 250
278 void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) { 251 void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) {
279 // Not needed in CoreGraphics 252 // Not needed in CoreGraphics
280 } 253 }
281 254
282 void BitmapPlatformDevice::processPixels(int x, int y,
283 int width, int height,
284 adjustAlpha adjustor) {
285 const SkBitmap& bitmap = accessBitmap(true);
286 const SkMatrix& matrix = data_->transform();
287 int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
288 int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y;
289
290 SkAutoLockPixels lock(bitmap);
291 if (Constrain(bitmap.width(), &bitmap_start_x, &width) &&
292 Constrain(bitmap.height(), &bitmap_start_y, &height)) {
293 uint32_t* data = bitmap.getAddr32(0, 0);
294 size_t row_words = bitmap.rowBytes() / 4;
295 for (int i = 0; i < height; i++) {
296 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x;
297 for (int j = 0; j < width; j++) {
298 adjustor(data + offset + j);
299 }
300 }
301 }
302 }
303
304 } // namespace skia 255 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.h ('k') | skia/ext/bitmap_platform_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698