| 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 // TODO(awalker): clean up the const/non-const reference handling in this test |    5 // TODO(awalker): clean up the const/non-const reference handling in this test | 
|    6  |    6  | 
 |    7 #include "skia/ext/platform_canvas.h" | 
 |    8  | 
 |    9 #include "base/logging.h" | 
 |   10 #include "base/memory/scoped_ptr.h" | 
|    7 #include "build/build_config.h" |   11 #include "build/build_config.h" | 
 |   12 #include "skia/ext/platform_device.h" | 
 |   13 #include "testing/gtest/include/gtest/gtest.h" | 
 |   14 #include "third_party/skia/include/core/SkBitmap.h" | 
 |   15 #include "third_party/skia/include/core/SkColor.h" | 
 |   16 #include "third_party/skia/include/core/SkColorPriv.h" | 
 |   17 #include "third_party/skia/include/core/SkPixelRef.h" | 
|    8  |   18  | 
|    9 #if defined(OS_MACOSX) |   19 #if defined(OS_MACOSX) | 
|   10 #import <ApplicationServices/ApplicationServices.h> |   20 #import <ApplicationServices/ApplicationServices.h> | 
|   11 #endif |   21 #endif | 
|   12  |   22  | 
|   13 #if !defined(OS_WIN) |   23 #if !defined(OS_WIN) | 
|   14 #include <unistd.h> |   24 #include <unistd.h> | 
|   15 #endif |   25 #endif | 
|   16  |   26  | 
|   17 #include "base/memory/scoped_ptr.h" |  | 
|   18 #include "skia/ext/platform_canvas.h" |  | 
|   19 #include "skia/ext/platform_device.h" |  | 
|   20 #include "testing/gtest/include/gtest/gtest.h" |  | 
|   21 #include "third_party/skia/include/core/SkBitmap.h" |  | 
|   22 #include "third_party/skia/include/core/SkColor.h" |  | 
|   23 #include "third_party/skia/include/core/SkColorPriv.h" |  | 
|   24 #include "third_party/skia/include/core/SkPixelRef.h" |  | 
|   25  |  | 
|   26 namespace skia { |   27 namespace skia { | 
|   27  |   28  | 
|   28 namespace { |   29 namespace { | 
|   29  |   30  | 
|   30 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { |   31 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { | 
|   31   // For masking out the alpha values. |   32   // For masking out the alpha values. | 
|   32   static uint32_t alpha_mask = |   33   static uint32_t alpha_mask = | 
|   33       static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; |   34       static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; | 
|   34   return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); |   35   return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); | 
|   35 } |   36 } | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   60     } |   61     } | 
|   61   } |   62   } | 
|   62   return true; |   63   return true; | 
|   63 } |   64 } | 
|   64  |   65  | 
|   65 #if !defined(OS_MACOSX) |   66 #if !defined(OS_MACOSX) | 
|   66 // Return true if canvas has something that passes for a rounded-corner |   67 // Return true if canvas has something that passes for a rounded-corner | 
|   67 // rectangle. Basically, we're just checking to make sure that the pixels in the |   68 // rectangle. Basically, we're just checking to make sure that the pixels in the | 
|   68 // middle are of rect_color and pixels in the corners are of canvas_color. |   69 // middle are of rect_color and pixels in the corners are of canvas_color. | 
|   69 bool VerifyRoundedRect(const PlatformCanvas& canvas, |   70 bool VerifyRoundedRect(const PlatformCanvas& canvas, | 
|   70                        uint32_t canvas_color, uint32_t rect_color, |   71                        uint32_t canvas_color, | 
|   71                        int x, int y, int w, int h) { |   72                        uint32_t rect_color, | 
 |   73                        int x, | 
 |   74                        int y, | 
 |   75                        int w, | 
 |   76                        int h) { | 
|   72   SkBaseDevice* device = skia::GetTopDevice(canvas); |   77   SkBaseDevice* device = skia::GetTopDevice(canvas); | 
|   73   const SkBitmap& bitmap = device->accessBitmap(false); |   78   const SkBitmap& bitmap = device->accessBitmap(false); | 
|   74   SkAutoLockPixels lock(bitmap); |   79   SkAutoLockPixels lock(bitmap); | 
|   75  |   80  | 
|   76   // Check corner points first. They should be of canvas_color. |   81   // Check corner points first. They should be of canvas_color. | 
|   77   if (!IsOfColor(bitmap, x, y, canvas_color)) return false; |   82   if (!IsOfColor(bitmap, x, y, canvas_color)) return false; | 
|   78   if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |   83   if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 
|   79   if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; |   84   if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; | 
|   80   if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |   85   if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 
|   81  |   86  | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  119  |  124  | 
|  120   CGRect inner_rc = CGRectMake(x, y, w, h); |  125   CGRect inner_rc = CGRectMake(x, y, w, h); | 
|  121   // RGBA opaque black |  126   // RGBA opaque black | 
|  122   CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); |  127   CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); | 
|  123   CGContextSetFillColorWithColor(context, black); |  128   CGContextSetFillColorWithColor(context, black); | 
|  124   CGColorRelease(black); |  129   CGColorRelease(black); | 
|  125   CGContextFillRect(context, inner_rc); |  130   CGContextFillRect(context, inner_rc); | 
|  126 } |  131 } | 
|  127 #else |  132 #else | 
|  128 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { |  133 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { | 
|  129   notImplemented(); |  134   NOTIMPLEMENTED(); | 
|  130 } |  135 } | 
|  131 #endif |  136 #endif | 
|  132  |  137  | 
|  133 // Clips the contents of the canvas to the given rectangle. This will be |  138 // Clips the contents of the canvas to the given rectangle. This will be | 
|  134 // intersected with any existing clip. |  139 // intersected with any existing clip. | 
|  135 void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) { |  140 void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) { | 
|  136   SkRect rect; |  141   SkRect rect; | 
|  137   rect.set(SkIntToScalar(x), SkIntToScalar(y), |  142   rect.set(SkIntToScalar(x), SkIntToScalar(y), | 
|  138            SkIntToScalar(x + w), SkIntToScalar(y + h)); |  143            SkIntToScalar(x + w), SkIntToScalar(y + h)); | 
|  139   canvas.clipRect(rect); |  144   canvas.clipRect(rect); | 
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  445  |  450  | 
|  446   sk_bitmap.lockPixels(); |  451   sk_bitmap.lockPixels(); | 
|  447   EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); |  452   EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); | 
|  448   EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); |  453   EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); | 
|  449   EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); |  454   EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); | 
|  450   sk_bitmap.unlockPixels(); |  455   sk_bitmap.unlockPixels(); | 
|  451 } |  456 } | 
|  452  |  457  | 
|  453  |  458  | 
|  454 }  // namespace skia |  459 }  // namespace skia | 
| OLD | NEW |