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

Side by Side Diff: tests/RecordReplaceDrawTest.cpp

Issue 535953002: Replace SkPictureReplacementPlayback with GrRecordReplaceDraw (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix memory leak Created 6 years, 3 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
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/SkGpuDevice.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 2014 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 #if SK_SUPPORT_GPU
9
10 #include "Test.h"
11 #include "RecordTestUtils.h"
12
13 #include "SkBBHFactory.h"
14 #include "SkRecordDraw.h"
15 #include "SkRecorder.h"
16 #include "GrRecordReplaceDraw.h"
17
18 static const int kWidth = 100;
19 static const int kHeight = 100;
20
21 class JustOneDraw : public SkDrawPictureCallback {
22 public:
23 JustOneDraw() : fCalls(0) {}
24
25 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; }
26 private:
27 int fCalls;
28 };
29
30 // Make sure the abort callback works
31 DEF_TEST(RecordReplaceDraw_Abort, r) {
32 // Record two commands.
33 SkRecord record;
34 SkRecorder recorder(&record, kWidth, kHeight);
35 recorder.drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeigh t)), SkPaint());
36 recorder.clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeigh t)));
37
38 SkRecord rerecord;
39 SkRecorder canvas(&rerecord, kWidth, kHeight);
40
41 GrReplacements replacements;
42 JustOneDraw callback;
43 GrRecordReplaceDraw(record, &canvas, NULL/*bbh*/, &replacements, &callback);
44
45 REPORTER_ASSERT(r, 3 == rerecord.count());
46 assert_type<SkRecords::Save>(r, rerecord, 0);
47 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
48 assert_type<SkRecords::Restore>(r, rerecord, 2);
49 }
50
51 // Make sure GrRecordReplaceDraw balances unbalanced saves
52 DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
53 SkRecord record;
54 SkRecorder recorder(&record, kWidth, kHeight);
55 recorder.save(); // We won't balance this, but GrRecordReplaceDraw will for us.
56
57 SkRecord rerecord;
58 SkRecorder canvas(&rerecord, kWidth, kHeight);
59
60 GrReplacements replacements;
61 GrRecordReplaceDraw(record, &canvas, NULL/*bbh*/, &replacements, NULL/*callb ack*/);
62
63 REPORTER_ASSERT(r, 4 == rerecord.count());
64 assert_type<SkRecords::Save>(r, rerecord, 0);
65 assert_type<SkRecords::Save>(r, rerecord, 1);
66 assert_type<SkRecords::Restore>(r, rerecord, 2);
67 assert_type<SkRecords::Restore>(r, rerecord, 3);
68 }
69
70 // Test out the layer replacement functionality with and w/o a BBH
71 void test_replacements(skiatest::Reporter* r, bool useBBH) {
72 SkRecord record;
73 SkRecorder recorder(&record, kWidth, kHeight);
74 recorder.saveLayer(NULL, NULL);
75 recorder.drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeigh t)), SkPaint());
76 recorder.restore();
77 recorder.clear(SK_ColorRED);
78
79 GrReplacements replacements;
80 GrReplacements::ReplacementInfo* ri = replacements.push();
81 ri->fStart = 0;
82 ri->fStop = 2;
83 ri->fPos.set(0, 0);
84 ri->fBM = SkNEW(SkBitmap);
85 ri->fPaint = NULL;
86 ri->fSrcRect = SkIRect::MakeWH(kWidth, kHeight);
87
88 SkAutoTUnref<SkBBoxHierarchy> bbh;
89
90 if (useBBH) {
91 SkRTreeFactory factory;
92 bbh.reset((factory)(kWidth, kHeight));
93 SkRecordFillBounds(record, bbh);
94 }
95
96 SkRecord rerecord;
97 SkRecorder canvas(&rerecord, kWidth, kHeight);
98 GrRecordReplaceDraw(record, &canvas, bbh, &replacements, NULL/*callback*/);
99
100 REPORTER_ASSERT(r, 4 == rerecord.count());
101 assert_type<SkRecords::Save>(r, rerecord, 0);
102 assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, 1);
103 assert_type<SkRecords::Clear>(r, rerecord, 2);
104 assert_type<SkRecords::Restore>(r, rerecord, 3);
105 }
106
107 DEF_TEST(RecordReplaceDraw_Replace, r) { test_replacements(r, false); }
108 DEF_TEST(RecordReplaceDraw_ReplaceWithBBH, r) { test_replacements(r, true); }
109
110 #endif
OLDNEW
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698