зеркало из https://github.com/mozilla/moz-skia.git
Split Star into Star (stores nothing) and List (stores matches).
Just noticed that the cull noop pattern (PushCull, Star<NoOp>, PopCull) would trigger the Star that stores matches. We certainly don't need those matches here, so instead of magically determining which Star you need, we'll make you tell us which one you want. No one but List's unit test needs List. I'll leave it for now, but we might find it's not useful. BUG=skia:2378 R=fmalita@chromium.org, mtklein@google.com, bungeman@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/275623002 git-svn-id: http://skia.googlecode.com/svn/trunk@14655 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
3d41c4add8
Коммит
888e4687d9
|
@ -85,44 +85,13 @@ struct Or {
|
|||
template <typename A, typename B, typename C>
|
||||
struct Or3 : Or<A, Or<B, C> > {};
|
||||
|
||||
// We'll use this to choose which implementation of Star suits each Matcher.
|
||||
SK_CREATE_TYPE_DETECTOR(type);
|
||||
|
||||
// Star is a special matcher that matches Matcher 0 or more times _greedily_ in the SkRecord.
|
||||
// This version stores nothing. It's enabled when Matcher stores nothing.
|
||||
template <typename Matcher, typename = void>
|
||||
class Star {
|
||||
public:
|
||||
void reset() {}
|
||||
|
||||
// Star is a special matcher that greedily matches Matcher 0 or more times. Stores nothing.
|
||||
template <typename Matcher>
|
||||
struct Star {
|
||||
template <typename T>
|
||||
bool operator()(T* ptr) { return Matcher()(ptr); }
|
||||
};
|
||||
|
||||
// This version stores a list of matches. It's enabled if Matcher stores something.
|
||||
template <typename Matcher>
|
||||
class Star<Matcher, SK_WHEN(HasType_type<Matcher>, void)> {
|
||||
public:
|
||||
typedef SkTDArray<typename Matcher::type*> type;
|
||||
type* get() { return &fMatches; }
|
||||
|
||||
void reset() { fMatches.rewind(); }
|
||||
|
||||
template <typename T>
|
||||
bool operator()(T* ptr) {
|
||||
Matcher matcher;
|
||||
if (matcher(ptr)) {
|
||||
fMatches.push(matcher.get());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
type fMatches;
|
||||
};
|
||||
|
||||
|
||||
// Cons builds a list of Matchers.
|
||||
// It first matches Matcher (something from above), then Pattern (another Cons or Nil).
|
||||
//
|
||||
|
@ -175,7 +144,6 @@ private:
|
|||
// If head is a Star, walk i until it doesn't match.
|
||||
template <typename T>
|
||||
unsigned matchHead(Star<T>*, SkRecord* record, unsigned i) {
|
||||
fHead.reset();
|
||||
while (i < record->count()) {
|
||||
if (!record->mutate<bool>(i, fHead)) {
|
||||
return i;
|
||||
|
|
|
@ -79,20 +79,17 @@ DEF_TEST(RecordPattern_Star, r) {
|
|||
recorder.save();
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, pattern.match(&record, 0));
|
||||
REPORTER_ASSERT(r, pattern.second<SkTDArray<ClipRect*> >()->count() == 0);
|
||||
|
||||
recorder.save();
|
||||
recorder.clipRect(SkRect::MakeWH(300, 200));
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, pattern.match(&record, 2));
|
||||
REPORTER_ASSERT(r, pattern.second<SkTDArray<ClipRect*> >()->count() == 1);
|
||||
|
||||
recorder.save();
|
||||
recorder.clipRect(SkRect::MakeWH(300, 200));
|
||||
recorder.clipRect(SkRect::MakeWH(100, 100));
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, pattern.match(&record, 5));
|
||||
REPORTER_ASSERT(r, pattern.second<SkTDArray<ClipRect*> >()->count() == 2);
|
||||
}
|
||||
|
||||
DEF_TEST(RecordPattern_IsDraw, r) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче