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

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

Issue 259047: Move classes depending on Skia out of base/gfx and into app/gfx. Rename... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « printing/image.cc ('k') | skia/ext/vector_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "webkit/tools/test_shell/image_decoder_unittest.h" 7 #include "webkit/tools/test_shell/image_decoder_unittest.h"
8 8
9 #if !defined(OS_WIN) 9 #if !defined(OS_WIN)
10 #include <unistd.h> 10 #include <unistd.h>
11 #endif 11 #endif
12 12
13 #include "PNGImageDecoder.h" 13 #include "PNGImageDecoder.h"
14 14
15 #include "app/gfx/codec/png_codec.h" 15 #include "app/gfx/codec/png_codec.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/gfx/gdi_util.h"
19 #include "base/path_service.h" 18 #include "base/path_service.h"
20 #include "base/string_util.h" 19 #include "base/string_util.h"
21 #include "skia/ext/vector_canvas.h" 20 #include "skia/ext/vector_canvas.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/skia/include/effects/SkDashPathEffect.h" 22 #include "third_party/skia/include/effects/SkDashPathEffect.h"
24 23
25 namespace skia { 24 namespace skia {
26 25
27 namespace { 26 namespace {
28 27
29 const wchar_t* const kGenerateSwitch = L"vector-canvas-generate"; 28 const wchar_t* const kGenerateSwitch = L"vector-canvas-generate";
30 29
31 // Lightweight HDC management. 30 // Lightweight HDC management.
32 class Context { 31 class Context {
33 public: 32 public:
34 Context() : context_(CreateCompatibleDC(NULL)) { 33 Context() : context_(CreateCompatibleDC(NULL)) {
35 EXPECT_TRUE(context_); 34 EXPECT_TRUE(context_);
36 } 35 }
37 ~Context() { 36 ~Context() {
38 DeleteDC(context_); 37 DeleteDC(context_);
39 } 38 }
40 39
41 HDC context() const { return context_; } 40 HDC context() const { return context_; }
42 41
43 private: 42 private:
44 HDC context_; 43 HDC context_;
45 44
46 DISALLOW_EVIL_CONSTRUCTORS(Context); 45 DISALLOW_COPY_AND_ASSIGN(Context);
47 }; 46 };
48 47
49 // Lightweight HBITMAP management. 48 // Lightweight HBITMAP management.
50 class Bitmap { 49 class Bitmap {
51 public: 50 public:
52 Bitmap(const Context& context, int x, int y) { 51 Bitmap(const Context& context, int x, int y) {
53 BITMAPINFOHEADER hdr; 52 BITMAPINFOHEADER hdr;
54 gfx::CreateBitmapHeader(x, y, &hdr); 53 hdr.biSize = sizeof(BITMAPINFOHEADER);
54 hdr.biWidth = x;
55 hdr.biHeight = -y; // Minus means top-down bitmap.
56 hdr.biPlanes = 1;
57 hdr.biBitCount = 32;
58 hdr.biCompression = BI_RGB; // No compression.
59 hdr.biSizeImage = 0;
60 hdr.biXPelsPerMeter = 1;
61 hdr.biYPelsPerMeter = 1;
62 hdr.biClrUsed = 0;
63 hdr.biClrImportant = 0;
55 bitmap_ = CreateDIBSection(context.context(), 64 bitmap_ = CreateDIBSection(context.context(),
56 reinterpret_cast<BITMAPINFO*>(&hdr), 0, 65 reinterpret_cast<BITMAPINFO*>(&hdr), 0,
57 &data_, NULL, 0); 66 &data_, NULL, 0);
58 EXPECT_TRUE(bitmap_); 67 EXPECT_TRUE(bitmap_);
59 EXPECT_TRUE(SelectObject(context.context(), bitmap_)); 68 EXPECT_TRUE(SelectObject(context.context(), bitmap_));
60 } 69 }
61 ~Bitmap() { 70 ~Bitmap() {
62 EXPECT_TRUE(DeleteObject(bitmap_)); 71 EXPECT_TRUE(DeleteObject(bitmap_));
63 } 72 }
64 73
65 private: 74 private:
66 HBITMAP bitmap_; 75 HBITMAP bitmap_;
67 76
68 void* data_; 77 void* data_;
69 78
70 DISALLOW_EVIL_CONSTRUCTORS(Bitmap); 79 DISALLOW_COPY_AND_ASSIGN(Bitmap);
71 }; 80 };
72 81
73 // Lightweight raw-bitmap management. The image, once initialized, is immuable. 82 // Lightweight raw-bitmap management. The image, once initialized, is immuable.
74 // It is mainly used for comparison. 83 // It is mainly used for comparison.
75 class Image { 84 class Image {
76 public: 85 public:
77 // Creates the image from the given filename on disk. 86 // Creates the image from the given filename on disk.
78 Image(const std::wstring& filename) : ignore_alpha_(true) { 87 Image(const std::wstring& filename) : ignore_alpha_(true) {
79 Vector<char> compressed; 88 Vector<char> compressed;
80 ReadFileToVector(filename, &compressed); 89 ReadFileToVector(filename, &compressed);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Length of a line in bytes. 200 // Length of a line in bytes.
192 int row_length_; 201 int row_length_;
193 202
194 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's 203 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's
195 // 0xABGR). 204 // 0xABGR).
196 std::vector<unsigned char> data_; 205 std::vector<unsigned char> data_;
197 206
198 // Flag to signal if the comparison functions should ignore the alpha channel. 207 // Flag to signal if the comparison functions should ignore the alpha channel.
199 const bool ignore_alpha_; 208 const bool ignore_alpha_;
200 209
201 DISALLOW_EVIL_CONSTRUCTORS(Image); 210 DISALLOW_COPY_AND_ASSIGN(Image);
202 }; 211 };
203 212
204 // Base for tests. Capability to process an image. 213 // Base for tests. Capability to process an image.
205 class ImageTest : public testing::Test { 214 class ImageTest : public testing::Test {
206 public: 215 public:
207 // In what state is the test running. 216 // In what state is the test running.
208 enum ProcessAction { 217 enum ProcessAction {
209 GENERATE, 218 GENERATE,
210 COMPARE, 219 COMPARE,
211 NOOP, 220 NOOP,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 void SaveImage(const skia::PlatformCanvas& canvas, 296 void SaveImage(const skia::PlatformCanvas& canvas,
288 const std::wstring& filename) const { 297 const std::wstring& filename) const {
289 Image(canvas).SaveToFile(test_file(filename)); 298 Image(canvas).SaveToFile(test_file(filename));
290 } 299 }
291 300
292 ProcessAction action_; 301 ProcessAction action_;
293 302
294 // Path to directory used to contain the test data. 303 // Path to directory used to contain the test data.
295 std::wstring test_dir_; 304 std::wstring test_dir_;
296 305
297 DISALLOW_EVIL_CONSTRUCTORS(ImageTest); 306 DISALLOW_COPY_AND_ASSIGN(ImageTest);
298 }; 307 };
299 308
300 // Premultiply the Alpha channel on the R, B and G channels. 309 // Premultiply the Alpha channel on the R, B and G channels.
301 void Premultiply(SkBitmap bitmap) { 310 void Premultiply(SkBitmap bitmap) {
302 SkAutoLockPixels lock(bitmap); 311 SkAutoLockPixels lock(bitmap);
303 for (int x = 0; x < bitmap.width(); ++x) { 312 for (int x = 0; x < bitmap.width(); ++x) {
304 for (int y = 0; y < bitmap.height(); ++y) { 313 for (int y = 0; y < bitmap.height(); ++y) {
305 uint32_t* pixel_addr = bitmap.getAddr32(x, y); 314 uint32_t* pixel_addr = bitmap.getAddr32(x, y);
306 uint32_t color = *pixel_addr; 315 uint32_t color = *pixel_addr;
307 BYTE alpha = SkColorGetA(color); 316 BYTE alpha = SkColorGetA(color);
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 { 965 {
957 vcanvas_->rotate(67); 966 vcanvas_->rotate(67);
958 pcanvas_->rotate(67); 967 pcanvas_->rotate(67);
959 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); 968 vcanvas_->drawBitmap(bitmap, 20, -50, NULL);
960 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); 969 pcanvas_->drawBitmap(bitmap, 20, -50, NULL);
961 EXPECT_EQ(0., ProcessImage(L"rotate")); 970 EXPECT_EQ(0., ProcessImage(L"rotate"));
962 } 971 }
963 } 972 }
964 973
965 } // namespace skia 974 } // namespace skia
OLDNEW
« no previous file with comments | « printing/image.cc ('k') | skia/ext/vector_platform_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698