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

Side by Side Diff: tests/RecordTest.cpp

Issue 366443002: Implement SkRecord::willPlaybackBitmaps, cache in SkPicture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add header to gypi Created 6 years, 5 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
« include/record/SkRecording.h ('K') | « src/core/SkRecording.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
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 9
10 #include "SkBitmap.h"
11 #include "SkImageInfo.h"
12 #include "SkShader.h"
10 #include "SkRecord.h" 13 #include "SkRecord.h"
14 #include "SkRecordAnalysis.h"
11 #include "SkRecords.h" 15 #include "SkRecords.h"
12 16
13 // Sums the area of any DrawRect command it sees. 17 // Sums the area of any DrawRect command it sees.
14 class AreaSummer { 18 class AreaSummer {
15 public: 19 public:
16 AreaSummer() : fArea(0) {} 20 AreaSummer() : fArea(0) {}
17 21
18 template <typename T> void operator()(const T&) { } 22 template <typename T> void operator()(const T&) { }
19 23
20 void operator()(const SkRecords::DrawRect& draw) { 24 void operator()(const SkRecords::DrawRect& draw) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 REPORTER_ASSERT(r, summer.area() == 100); 67 REPORTER_ASSERT(r, summer.area() == 100);
64 68
65 // Scale 2x. 69 // Scale 2x.
66 Stretch stretch; 70 Stretch stretch;
67 stretch.apply(&record); 71 stretch.apply(&record);
68 72
69 // Now its area should be 100 + 400. 73 // Now its area should be 100 + 400.
70 summer.apply(record); 74 summer.apply(record);
71 REPORTER_ASSERT(r, summer.area() == 500); 75 REPORTER_ASSERT(r, summer.area() == 500);
72 } 76 }
77
78 DEF_TEST(RecordAnalysis, r) {
79 SkRecord record;
80
81 SkRect rect = SkRect::MakeWH(10, 10);
82 SkPaint paint;
83 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRe ct, (paint, rect));
mtklein 2014/07/01 18:58:01 I find a macro like this helps keep things straigh
tomhudson 2014/07/02 15:25:41 MMV - feels like a break-even in this instance. Do
84 REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record));
85
86 SkBitmap bitmap;
87 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawBitmap>(), SkRecords::Draw Bitmap,
88 (&paint, bitmap, 0.0f, 0.0f));
89 REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record));
90
91 SkNEW_PLACEMENT_ARGS(record.replace<SkRecords::DrawRect>(1),
92 SkRecords::DrawRect, (paint, rect));
93 REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record));
94
95 SkPaint paint2;
96 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader
97 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here.
98 SkBitmap bitmap2;
99 bitmap2.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
100 bitmap2.eraseColor(SK_ColorBLUE);
101 *(bitmap2.getAddr32(0, 0)) = SK_ColorGREEN;
102 SkShader* shader = SkShader::CreateBitmapShader(bitmap2, SkShader::kClamp_Ti leMode,
103 SkShader::kClamp_TileMode);
104 paint2.setShader(shader);
105 REPORTER_ASSERT(r, shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault _BitmapType);
106 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(),
107 SkRecords::DrawRect, (paint2, rect));
108 REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record));
109 }
110
OLDNEW
« include/record/SkRecording.h ('K') | « src/core/SkRecording.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698