 Chromium Code Reviews
 Chromium Code Reviews Issue 2001653002:
  Remove SkDevice, obsolete constructor  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2001653002:
  Remove SkDevice, obsolete constructor  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 "skia/ext/skia_utils_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" | 
| 6 | 6 | 
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> | 
| 8 | 8 | 
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" | 
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 void TestImageRep(NSBitmapImageRep* imageRep, bool isred); | 26 void TestImageRep(NSBitmapImageRep* imageRep, bool isred); | 
| 27 | 27 | 
| 28 // Checks that the given bitmap is red. | 28 // Checks that the given bitmap is red. | 
| 29 void TestSkBitmap(const SkBitmap& bitmap); | 29 void TestSkBitmap(const SkBitmap& bitmap); | 
| 30 | 30 | 
| 31 enum BitLockerTest { | 31 enum BitLockerTest { | 
| 32 TestIdentity = 0, | 32 TestIdentity = 0, | 
| 33 TestTranslate = 1, | 33 TestTranslate = 1, | 
| 34 TestClip = 2, | 34 TestClip = 2, | 
| 35 TestXClip = TestTranslate | TestClip, | 35 TestXClip = TestTranslate | TestClip, | 
| 36 TestNoBits = 4, | |
| 37 TestTranslateNoBits = TestTranslate | TestNoBits, | |
| 38 TestClipNoBits = TestClip | TestNoBits, | |
| 39 TestXClipNoBits = TestXClip | TestNoBits, | |
| 40 }; | 36 }; | 
| 41 void RunBitLockerTest(BitLockerTest test); | 37 void RunBitLockerTest(BitLockerTest test); | 
| 42 | 38 | 
| 43 // If not red, is blue. | 39 // If not red, is blue. | 
| 44 // If not tfbit (twenty-four-bit), is 444. | 40 // If not tfbit (twenty-four-bit), is 444. | 
| 45 void ShapeHelper(int width, int height, bool isred, bool tfbit); | 41 void ShapeHelper(int width, int height, bool isred, bool tfbit); | 
| 46 }; | 42 }; | 
| 47 | 43 | 
| 48 SkBitmap SkiaUtilsMacTest::CreateSkBitmap(int width, int height, | 44 SkBitmap SkiaUtilsMacTest::CreateSkBitmap(int width, int height, | 
| 49 bool isred, bool tfbit) { | 45 bool isred, bool tfbit) { | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 int x = bitmap.width() > 17 ? 17 : 0; | 123 int x = bitmap.width() > 17 ? 17 : 0; | 
| 128 int y = bitmap.height() > 17 ? 17 : 0; | 124 int y = bitmap.height() > 17 ? 17 : 0; | 
| 129 SkColor color = bitmap.getColor(x, y); | 125 SkColor color = bitmap.getColor(x, y); | 
| 130 | 126 | 
| 131 EXPECT_EQ(255u, SkColorGetR(color)); | 127 EXPECT_EQ(255u, SkColorGetR(color)); | 
| 132 EXPECT_EQ(0u, SkColorGetB(color)); | 128 EXPECT_EQ(0u, SkColorGetB(color)); | 
| 133 EXPECT_EQ(0u, SkColorGetG(color)); | 129 EXPECT_EQ(0u, SkColorGetG(color)); | 
| 134 EXPECT_EQ(255u, SkColorGetA(color)); | 130 EXPECT_EQ(255u, SkColorGetA(color)); | 
| 135 } | 131 } | 
| 136 | 132 | 
| 137 // setBitmapDevice has been deprecated/removed. Is this test still useful? | |
| 138 void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { | 133 void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { | 
| 139 const unsigned width = 2; | 134 const unsigned width = 2; | 
| 140 const unsigned height = 2; | 135 const unsigned height = 2; | 
| 141 const unsigned storageSize = width * height; | 136 const unsigned storageSize = width * height; | 
| 142 const unsigned original[] = {0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC}; | 137 const unsigned original[] = {0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC}; | 
| 143 EXPECT_EQ(storageSize, sizeof(original) / sizeof(original[0])); | 138 EXPECT_EQ(storageSize, sizeof(original) / sizeof(original[0])); | 
| 144 unsigned bits[storageSize]; | 139 unsigned bits[storageSize]; | 
| 145 memcpy(bits, original, sizeof(original)); | 140 memcpy(bits, original, sizeof(original)); | 
| 146 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 141 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 
| 147 SkBitmap bitmap; | 142 SkBitmap bitmap; | 
| 148 bitmap.installPixels(info, bits, info.minRowBytes()); | 143 bitmap.installPixels(info, bits, info.minRowBytes()); | 
| 149 | 144 | 
| 150 SkCanvas canvas(bitmap); | 145 SkCanvas canvas(bitmap); | 
| 151 if (test & TestTranslate) | 146 if (test & TestTranslate) | 
| 152 canvas.translate(width / 2, 0); | 147 canvas.translate(width / 2, 0); | 
| 153 if (test & TestClip) { | 148 if (test & TestClip) { | 
| 154 SkRect clipRect = {0, height / 2, width, height}; | 149 SkRect clipRect = {0, height / 2, width, height}; | 
| 155 canvas.clipRect(clipRect); | 150 canvas.clipRect(clipRect); | 
| 156 } | 151 } | 
| 157 { | 152 { | 
| 158 skia::SkiaBitLocker bitLocker(&canvas); | 153 SkIRect clip = SkIRect::MakeSize(canvas.getBaseLayerSize()). | 
| 154 makeOffset((test & TestTranslate) ? -width / 2 : 0, 0); | |
| 155 skia::SkiaBitLocker bitLocker(&canvas, SkIRect::MakeSize(canvas.getBaseLayer Size())); | |
| 
f(malita)
2016/06/08 14:24:36
You meant to pass clip here :)
 | |
| 159 CGContextRef cgContext = bitLocker.cgContext(); | 156 CGContextRef cgContext = bitLocker.cgContext(); | 
| 160 CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); | 157 CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); | 
| 161 CGContextSetFillColorWithColor(cgContext, testColor); | 158 CGContextSetFillColorWithColor(cgContext, testColor); | 
| 162 CGRect cgRect = {{0, 0}, {width, height}}; | 159 CGRect cgRect = {{0, 0}, {width, height}}; | 
| 163 CGContextFillRect(cgContext, cgRect); | 160 CGContextFillRect(cgContext, cgRect); | 
| 164 if (test & TestNoBits) { | |
| 165 if (test & TestClip) { | |
| 166 SkRect clipRect = {0, height / 2, width, height}; | |
| 167 canvas.clipRect(clipRect); | |
| 168 } | |
| 169 } | |
| 170 } | 161 } | 
| 171 const unsigned results[][storageSize] = { | 162 const unsigned results[][storageSize] = { | 
| 172 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity | 163 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity | 
| 173 {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate | 164 {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate | 
| 174 {0xFF333333, 0xFF666666, 0xFFFFFFFF, 0xFFFFFFFF}, // clip | 165 {0xFF333333, 0xFF666666, 0xFFFFFFFF, 0xFFFFFFFF}, // clip | 
| 175 {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip | 166 {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip | 
| 176 }; | 167 }; | 
| 177 for (unsigned index = 0; index < storageSize; index++) | 168 for (unsigned index = 0; index < storageSize; index++) | 
| 178 EXPECT_EQ(results[test & ~TestNoBits][index], bits[index]); | 169 EXPECT_EQ(results[test][index], bits[index]); | 
| 179 } | 170 } | 
| 180 | 171 | 
| 181 void SkiaUtilsMacTest::ShapeHelper(int width, int height, | 172 void SkiaUtilsMacTest::ShapeHelper(int width, int height, | 
| 182 bool isred, bool tfbit) { | 173 bool isred, bool tfbit) { | 
| 183 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); | 174 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); | 
| 184 | 175 | 
| 185 // Confirm size | 176 // Confirm size | 
| 186 NSImage* image = skia::SkBitmapToNSImage(thing); | 177 NSImage* image = skia::SkBitmapToNSImage(thing); | 
| 187 EXPECT_DOUBLE_EQ([image size].width, (double)width); | 178 EXPECT_DOUBLE_EQ([image size].width, (double)width); | 
| 188 EXPECT_DOUBLE_EQ([image size].height, (double)height); | 179 EXPECT_DOUBLE_EQ([image size].height, (double)height); | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 233 } | 
| 243 | 234 | 
| 244 TEST_F(SkiaUtilsMacTest, BitLocker_Clip) { | 235 TEST_F(SkiaUtilsMacTest, BitLocker_Clip) { | 
| 245 RunBitLockerTest(SkiaUtilsMacTest::TestClip); | 236 RunBitLockerTest(SkiaUtilsMacTest::TestClip); | 
| 246 } | 237 } | 
| 247 | 238 | 
| 248 TEST_F(SkiaUtilsMacTest, BitLocker_XClip) { | 239 TEST_F(SkiaUtilsMacTest, BitLocker_XClip) { | 
| 249 RunBitLockerTest(SkiaUtilsMacTest::TestXClip); | 240 RunBitLockerTest(SkiaUtilsMacTest::TestXClip); | 
| 250 } | 241 } | 
| 251 | 242 | 
| 252 TEST_F(SkiaUtilsMacTest, BitLocker_NoBits) { | |
| 253 RunBitLockerTest(SkiaUtilsMacTest::TestNoBits); | |
| 254 } | |
| 255 | |
| 256 TEST_F(SkiaUtilsMacTest, BitLocker_TranslateNoBits) { | |
| 257 RunBitLockerTest(SkiaUtilsMacTest::TestTranslateNoBits); | |
| 258 } | |
| 259 | |
| 260 TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { | |
| 261 RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); | |
| 262 } | |
| 263 | |
| 264 TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { | |
| 265 RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); | |
| 266 } | |
| 267 | |
| 268 } // namespace | 243 } // namespace | 
| 269 | 244 | 
| OLD | NEW |