OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/gfx/blit.h" | 11 #include "ui/gfx/blit.h" |
12 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Fills the given canvas with the values by duplicating the values into each | 17 // Fills the given canvas with the values by duplicating the values into each |
18 // color channel for the corresponding pixel. | 18 // color channel for the corresponding pixel. |
19 // | 19 // |
20 // Example values = {{0x0, 0x01}, {0x12, 0xFF}} would give a canvas with: | 20 // Example values = {{0x0, 0x01}, {0x12, 0xFF}} would give a canvas with: |
21 // 0x00000000 0x01010101 | 21 // 0x00000000 0x01010101 |
22 // 0x12121212 0xFFFFFFFF | 22 // 0x12121212 0xFFFFFFFF |
23 template <int w, int h> | 23 template <int w, int h> |
24 void SetToCanvas(skia::PlatformCanvas* canvas, uint8_t values[h][w]) { | 24 void SetToCanvas(SkCanvas* canvas, uint8_t values[h][w]) { |
25 ASSERT_EQ(w, canvas->imageInfo().width()); | 25 ASSERT_EQ(w, canvas->imageInfo().width()); |
26 ASSERT_EQ(h, canvas->imageInfo().height()); | 26 ASSERT_EQ(h, canvas->imageInfo().height()); |
27 | 27 |
28 // This wouldn't be necessary if we extended the values in the inputs, but | 28 // This wouldn't be necessary if we extended the values in the inputs, but |
29 // the uint8_t values are a little bit easier to read and maintain. | 29 // the uint8_t values are a little bit easier to read and maintain. |
30 uint32_t extendedValues[w*h]; | 30 uint32_t extendedValues[w*h]; |
31 for (int y = 0; y < h; y++) { | 31 for (int y = 0; y < h; y++) { |
32 for (int x = 0; x < w; x++) { | 32 for (int x = 0; x < w; x++) { |
33 uint8_t value = values[y][x]; | 33 uint8_t value = values[y][x]; |
34 extendedValues[y*w+x] = | 34 extendedValues[y*w+x] = |
35 (value << 24) | (value << 16) | (value << 8) | value; | 35 (value << 24) | (value << 16) | (value << 8) | value; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); | 39 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); |
40 canvas->writePixels(info, extendedValues, w*4, 0, 0); | 40 canvas->writePixels(info, extendedValues, w*4, 0, 0); |
41 } | 41 } |
42 | 42 |
43 // Checks each pixel in the given canvas and see if it is made up of the given | 43 // Checks each pixel in the given canvas and see if it is made up of the given |
44 // values, where each value has been duplicated into each channel of the given | 44 // values, where each value has been duplicated into each channel of the given |
45 // bitmap (see SetToCanvas above). | 45 // bitmap (see SetToCanvas above). |
46 template <int w, int h> | 46 template <int w, int h> |
47 void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8_t values[h][w]) { | 47 void VerifyCanvasValues(SkCanvas* canvas, uint8_t values[h][w]) { |
48 SkBitmap bitmap = skia::ReadPixels(canvas); | 48 SkBitmap bitmap = skia::ReadPixels(canvas); |
49 SkAutoLockPixels lock(bitmap); | 49 SkAutoLockPixels lock(bitmap); |
50 ASSERT_EQ(w, bitmap.width()); | 50 ASSERT_EQ(w, bitmap.width()); |
51 ASSERT_EQ(h, bitmap.height()); | 51 ASSERT_EQ(h, bitmap.height()); |
52 | 52 |
53 for (int y = 0; y < h; y++) { | 53 for (int y = 0; y < h; y++) { |
54 for (int x = 0; x < w; x++) { | 54 for (int x = 0; x < w; x++) { |
55 uint8_t value = values[y][x]; | 55 uint8_t value = values[y][x]; |
56 uint32_t expected = (value << 24) | (value << 16) | (value << 8) | value; | 56 uint32_t expected = (value << 24) | (value << 16) | (value << 8) | value; |
57 ASSERT_EQ(expected, *bitmap.getAddr32(x, y)); | 57 ASSERT_EQ(expected, *bitmap.getAddr32(x, y)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 {0x30, 0x31, 0x32, 0x33, 0x34}, | 165 {0x30, 0x31, 0x32, 0x33, 0x34}, |
166 {0x40, 0x41, 0x42, 0x43, 0x44}}; | 166 {0x40, 0x41, 0x42, 0x43, 0x44}}; |
167 SetToCanvas<5, 5>(canvas.get(), initial_values); | 167 SetToCanvas<5, 5>(canvas.get(), initial_values); |
168 | 168 |
169 // Sanity check on input. | 169 // Sanity check on input. |
170 VerifyCanvasValues<5, 5>(canvas.get(), initial_values); | 170 VerifyCanvasValues<5, 5>(canvas.get(), initial_values); |
171 } | 171 } |
172 | 172 |
173 #endif | 173 #endif |
174 | 174 |
OLD | NEW |