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

Side by Side Diff: cc/resources/picture_unittest.cc

Issue 13884018: cc: Add base64 encoding to picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 1.0 -> 1.0f Created 7 years, 8 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
« cc/resources/picture.h ('K') | « cc/resources/picture.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/picture.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "cc/test/fake_content_layer_client.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkDevice.h"
12 #include "third_party/skia/include/core/SkTileGridPicture.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/skia_util.h"
15
16 namespace cc {
17 namespace {
18
19 void DrawPicture(unsigned char* buffer,
20 gfx::Rect layer_rect,
21 scoped_refptr<Picture> picture) {
22 SkBitmap bitmap;
23 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
24 layer_rect.width(),
25 layer_rect.height());
26 bitmap.setPixels(buffer);
27 SkDevice device(bitmap);
28 SkCanvas canvas(&device);
29 canvas.clipRect(gfx::RectToSkRect(layer_rect));
30 picture->Raster(&canvas, layer_rect, 1.0f, false);
31 }
32
33 TEST(PictureTest, AsBase64String) {
34 gfx::Rect layer_rect(100, 100);
35
36 SkTileGridPicture::TileGridInfo tile_grid_info;
37 tile_grid_info.fTileInterval = SkISize::Make(100, 100);
38 tile_grid_info.fMargin.setEmpty();
39 tile_grid_info.fOffset.setZero();
40
41 FakeContentLayerClient content_layer_client;
42
43 // Construct pictures.
44 // Single full-size rect picture.
45 content_layer_client.add_draw_rect(layer_rect);
46 scoped_refptr<Picture> one_rect_picture = Picture::Create(layer_rect);
47 one_rect_picture->Record(&content_layer_client, NULL, tile_grid_info);
48 std::string serialized_one_rect;
49 one_rect_picture->AsBase64String(&serialized_one_rect);
50
51 // Reconstruct the picture.
52 scoped_refptr<Picture> one_rect_picture_check = Picture::Create(layer_rect);
53 one_rect_picture_check->SetPictureFromBase64String(serialized_one_rect);
54
55 // Check for equivalence.
56 unsigned char one_rect_buffer[4 * 100 * 100] = {0};
57 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture);
58 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0};
59 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check);
60
61 EXPECT_TRUE(
62 memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100) == 0);
63
64 // Two rect picture.
65 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50));
66 scoped_refptr<Picture> two_rect_picture = Picture::Create(layer_rect);
67 two_rect_picture->Record(&content_layer_client, NULL, tile_grid_info);
68 std::string serialized_two_rect;
69 two_rect_picture->AsBase64String(&serialized_two_rect);
70
71 // Reconstruct the picture.
72 scoped_refptr<Picture> two_rect_picture_check = Picture::Create(layer_rect);
73 two_rect_picture_check->SetPictureFromBase64String(serialized_two_rect);
74
75 // Check for equivalence.
76 unsigned char two_rect_buffer[4 * 100 * 100] = {0};
77 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture);
78 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0};
79 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check);
80
81 EXPECT_TRUE(
82 memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0);
83 }
84
85 } // namespace
86 } // namespace cc
OLDNEW
« cc/resources/picture.h ('K') | « cc/resources/picture.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698