| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "skia/ext/platform_canvas.h" | 6 #include "skia/ext/platform_canvas.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/blit.h" | 8 #include "ui/gfx/blit.h" |
| 9 #include "ui/gfx/point.h" | 9 #include "ui/gfx/point.h" |
| 10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Fills the given canvas with the values by duplicating the values into each | 14 // Fills the given canvas with the values by duplicating the values into each |
| 15 // color channel for the corresponding pixel. | 15 // color channel for the corresponding pixel. |
| 16 // | 16 // |
| 17 // Example values = {{0x0, 0x01}, {0x12, 0xFF}} would give a canvas with: | 17 // Example values = {{0x0, 0x01}, {0x12, 0xFF}} would give a canvas with: |
| 18 // 0x00000000 0x01010101 | 18 // 0x00000000 0x01010101 |
| 19 // 0x12121212 0xFFFFFFFF | 19 // 0x12121212 0xFFFFFFFF |
| 20 template<int w, int h> | 20 template<int w, int h> |
| 21 void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) { | 21 void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) { |
| 22 SkBitmap& bitmap = const_cast<SkBitmap&>( | 22 SkBitmap& bitmap = const_cast<SkBitmap&>( |
| 23 canvas->getTopPlatformDevice().accessBitmap(true)); | 23 canvas->getTopDevice().accessBitmap(true)); |
| 24 SkAutoLockPixels lock(bitmap); | 24 SkAutoLockPixels lock(bitmap); |
| 25 ASSERT_EQ(w, bitmap.width()); | 25 ASSERT_EQ(w, bitmap.width()); |
| 26 ASSERT_EQ(h, bitmap.height()); | 26 ASSERT_EQ(h, bitmap.height()); |
| 27 | 27 |
| 28 for (int y = 0; y < h; y++) { | 28 for (int y = 0; y < h; y++) { |
| 29 for (int x = 0; x < w; x++) { | 29 for (int x = 0; x < w; x++) { |
| 30 uint8 value = values[y][x]; | 30 uint8 value = values[y][x]; |
| 31 *bitmap.getAddr32(x, y) = | 31 *bitmap.getAddr32(x, y) = |
| 32 (value << 24) | (value << 16) | (value << 8) | value; | 32 (value << 24) | (value << 16) | (value << 8) | value; |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Checks each pixel in the given canvas and see if it is made up of the given | 37 // Checks each pixel in the given canvas and see if it is made up of the given |
| 38 // values, where each value has been duplicated into each channel of the given | 38 // values, where each value has been duplicated into each channel of the given |
| 39 // bitmap (see SetToCanvas above). | 39 // bitmap (see SetToCanvas above). |
| 40 template<int w, int h> | 40 template<int w, int h> |
| 41 void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) { | 41 void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) { |
| 42 SkBitmap& bitmap = const_cast<SkBitmap&>( | 42 SkBitmap& bitmap = const_cast<SkBitmap&>( |
| 43 canvas->getTopPlatformDevice().accessBitmap(true)); | 43 canvas->getTopDevice().accessBitmap(true)); |
| 44 SkAutoLockPixels lock(bitmap); | 44 SkAutoLockPixels lock(bitmap); |
| 45 ASSERT_EQ(w, bitmap.width()); | 45 ASSERT_EQ(w, bitmap.width()); |
| 46 ASSERT_EQ(h, bitmap.height()); | 46 ASSERT_EQ(h, bitmap.height()); |
| 47 | 47 |
| 48 for (int y = 0; y < h; y++) { | 48 for (int y = 0; y < h; y++) { |
| 49 for (int x = 0; x < w; x++) { | 49 for (int x = 0; x < w; x++) { |
| 50 uint8 value = values[y][x]; | 50 uint8 value = values[y][x]; |
| 51 uint32 expected = | 51 uint32 expected = |
| 52 (value << 24) | (value << 16) | (value << 8) | value; | 52 (value << 24) | (value << 16) | (value << 8) | value; |
| 53 ASSERT_EQ(expected, *bitmap.getAddr32(x, y)); | 53 ASSERT_EQ(expected, *bitmap.getAddr32(x, y)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 SetToCanvas<5, 5>(&canvas, initial_values); | 126 SetToCanvas<5, 5>(&canvas, initial_values); |
| 127 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(2, 2)); | 127 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(2, 2)); |
| 128 uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = { | 128 uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = { |
| 129 { 0x00, 0x01, 0x02, 0x03, 0x04 }, | 129 { 0x00, 0x01, 0x02, 0x03, 0x04 }, |
| 130 { 0x10, 0x11, 0x12, 0x13, 0x14 }, | 130 { 0x10, 0x11, 0x12, 0x13, 0x14 }, |
| 131 { 0x20, 0x21, 0x22, 0x23, 0x24 }, | 131 { 0x20, 0x21, 0x22, 0x23, 0x24 }, |
| 132 { 0x30, 0x31, 0x32, 0x11, 0x34 }, | 132 { 0x30, 0x31, 0x32, 0x11, 0x34 }, |
| 133 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; | 133 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; |
| 134 VerifyCanvasValues<5, 5>(&canvas, scroll_diagonal_expected); | 134 VerifyCanvasValues<5, 5>(&canvas, scroll_diagonal_expected); |
| 135 } | 135 } |
| OLD | NEW |