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

Side by Side Diff: tests/FlatDataTest.cpp

Issue 723593002: Start stripping out complicated parts of SkPicture{Record,Data}. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« tests/BitmapHeapTest.cpp ('K') | « tests/BitmapHeapTest.cpp ('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 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmap.h"
9 #include "SkCanvas.h"
10 #include "SkColor.h"
11 #include "SkColorFilter.h"
12 #include "SkGradientShader.h"
13 #include "SkPaint.h"
14 #include "SkPictureFlat.h"
15 #include "SkShader.h"
16 #include "SkXfermode.h"
17 #include "Test.h"
18
19 struct SkFlattenableTraits {
20 static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) {
21 buffer.writeFlattenable(&flattenable);
22 }
23 };
24
25 class Controller : public SkChunkFlatController {
26 public:
27 Controller() : INHERITED(1024) {
28 this->INHERITED::setNamedFactorySet(SkNEW(SkNamedFactorySet))->unref();
29 }
30 private:
31 typedef SkChunkFlatController INHERITED;
32 };
33
34 /**
35 * Verify that two SkFlatData objects that created from the same object are
36 * identical when using an SkNamedFactorySet.
37 * @param reporter Object to report failures.
38 * @param obj Flattenable object to be flattened.
39 * @param flattenProc Function that flattens objects with the same type as obj.
40 */
41 template <typename Traits, typename T>
42 static void testCreate(skiatest::Reporter* reporter, const T& obj) {
43 Controller controller;
44 // No need to delete data because that will be taken care of by the controll er.
45 SkFlatData* data1 = SkFlatData::Create<Traits>(&controller, obj, 0);
46 SkFlatData* data2 = SkFlatData::Create<Traits>(&controller, obj, 1);
47 REPORTER_ASSERT(reporter, *data1 == *data2);
48 }
49
50 DEF_TEST(FlatData, reporter) {
51 // Test flattening SkShader
52 SkPoint points[2];
53 points[0].set(0, 0);
54 points[1].set(SkIntToScalar(20), SkIntToScalar(20));
55 SkColor colors[2];
56 colors[0] = SK_ColorRED;
57 colors[1] = SK_ColorBLUE;
58
59 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, NULL, 2,
60 SkShader::kRepe at_TileMode));
61 testCreate<SkFlattenableTraits>(reporter, *shader);
62
63 // Test SkColorFilter
64 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateLightingFilter(SK_ColorB LUE, SK_ColorRED));
65 testCreate<SkFlattenableTraits>(reporter, *cf);
66
67 // Test SkXfermode
68 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode)) ;
69 testCreate<SkFlattenableTraits>(reporter, *xfer);
70 }
OLDNEW
« tests/BitmapHeapTest.cpp ('K') | « tests/BitmapHeapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698