add onSendClickToChildren to views, so a view can capture all clicks.

speedup some of the unittests that were too slow
minor cleanup in SkScan_Path, in prep for larger changes



git-svn-id: http://skia.googlecode.com/svn/trunk@426 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-11-16 14:52:01 +00:00
parent f0f4e9abba
commit e72fee513a
7 changed files with 86 additions and 71 deletions

View File

@ -314,7 +314,13 @@ protected:
/** Override this if you might handle the click
*/
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
/** Override this to decide if your children are targets for a click.
The default returns true, in which case your children views will be
candidates for onFindClickHandler. Returning false wil skip the children
and just call your onFindClickHandler.
*/
virtual bool onSendClickToChildren(SkScalar x, SkScalar y);
/** Override this to track clicks, returning true as long as you want to track
the pen/mouse.
*/

View File

@ -29,7 +29,11 @@ protected:
return this->INHERITED::onQuery(evt);
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
virtual bool onSendClickToChildren(SkScalar x, SkScalar y) {
return false;
}
virtual Click* onFindClickHandler(SkScalar x, SkScalar y) {
int ix = (int)(SkScalarDiv(x * N, W));
int iy = (int)(SkScalarDiv(y * N, H));
if (ix >= 0 && iy >= 0) {
@ -88,4 +92,3 @@ SkCanvas* OverView::beforeChildren(SkCanvas* canvas) {
return canvas;
}

View File

@ -119,9 +119,13 @@ protected:
SkIntToScalar(250), SkIntToScalar(400));
canvas->drawOval(oval, p);
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
fCenter.set(x, y);
return new Click(this);
}
virtual bool onClick(Click* click) {
fCenter.set(click->fCurr.fX, click->fCurr.fY);
this->inval(NULL);
return NULL;
}

View File

@ -369,43 +369,6 @@ static int build_edges(SkEdge edge[], const SkPath& path,
return (int)(list - start);
}
extern "C" {
static int edge_compare(const void* a, const void* b)
{
const SkEdge* edgea = *(const SkEdge**)a;
const SkEdge* edgeb = *(const SkEdge**)b;
int valuea = edgea->fFirstY;
int valueb = edgeb->fFirstY;
if (valuea == valueb)
{
valuea = edgea->fX;
valueb = edgeb->fX;
}
// this overflows if valuea >>> valueb or vice-versa
// return valuea - valueb;
// do perform the slower but safe compares
return (valuea < valueb) ? -1 : (valuea > valueb);
}
}
static SkEdge* sort_edges(SkEdge* list[], int count, SkEdge** last)
{
qsort(list, count, sizeof(SkEdge*), edge_compare);
// now make the edges linked in sorted order
for (int i = 1; i < count; i++)
{
list[i - 1]->fNext = list[i];
list[i]->fPrev = list[i - 1];
}
*last = list[count - 1];
return list[0];
}
#ifdef SK_DEBUG
/* 'quick' computation of the max sized needed to allocated for
our edgelist.
@ -466,6 +429,41 @@ static int cheap_worst_case_edge_count(const SkPath& path, size_t* storage) {
return edgeCount;
}
///////////////////////////////////////////////////////////////////////////////
extern "C" {
static int edge_compare(const void* a, const void* b) {
const SkEdge* edgea = *(const SkEdge**)a;
const SkEdge* edgeb = *(const SkEdge**)b;
int valuea = edgea->fFirstY;
int valueb = edgeb->fFirstY;
if (valuea == valueb) {
valuea = edgea->fX;
valueb = edgeb->fX;
}
// this overflows if valuea >>> valueb or vice-versa
// return valuea - valueb;
// do perform the slower but safe compares
return (valuea < valueb) ? -1 : (valuea > valueb);
}
}
static SkEdge* sort_edges(SkEdge* list[], int count, SkEdge** last) {
qsort(list, count, sizeof(SkEdge*), edge_compare);
// now make the edges linked in sorted order
for (int i = 1; i < count; i++) {
list[i - 1]->fNext = list[i];
list[i]->fPrev = list[i - 1];
}
*last = list[count - 1];
return list[0];
}
// clipRect may be null, even though we always have a clip. This indicates that
// the path is contained in the clip, and so we can ignore it during the blit
//

View File

@ -343,18 +343,23 @@ void SkView::Click::copyType(const char type[])
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y)
{
if (x < 0 || y < 0 || x >= fWidth || y >= fHeight)
if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) {
return false;
}
F2BIter iter(this);
SkView* child;
if (this->onSendClickToChildren(x, y)) {
F2BIter iter(this);
SkView* child;
while ((child = iter.next()) != NULL)
{
Click* click = child->findClickHandler(x - child->fLoc.fX, y - child->fLoc.fY);
if (click)
return click;
}
while ((child = iter.next()) != NULL)
{
Click* click = child->findClickHandler(x - child->fLoc.fX,
y - child->fLoc.fY);
if (click) {
return click;
}
}
}
return this->onFindClickHandler(x, y);
}
@ -417,38 +422,37 @@ void SkView::DoClickUp(Click* click, int x, int y)
//////////////////////////////////////////////////////////////////////
void SkView::invokeLayout()
{
void SkView::invokeLayout() {
SkView::Layout* layout = this->getLayout();
if (layout)
if (layout) {
layout->layoutChildren(this);
}
}
void SkView::onDraw(SkCanvas* canvas)
{
void SkView::onDraw(SkCanvas* canvas) {
Artist* artist = this->getArtist();
if (artist)
if (artist) {
artist->draw(this, canvas);
}
}
void SkView::onSizeChange()
{
void SkView::onSizeChange() {}
bool SkView::onSendClickToChildren(SkScalar x, SkScalar y) {
return true;
}
SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y)
{
SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y) {
return NULL;
}
bool SkView::onClick(Click*)
{
bool SkView::onClick(Click*) {
return false;
}
bool SkView::handleInval(const SkRect& r)
{
bool SkView::handleInval(const SkRect& r) {
return false;
}

View File

@ -235,7 +235,7 @@ static void TestMath(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, clamp == clamp2);
}
for (i = 0; i < 100000; i++) {
for (i = 0; i < 10000; i++) {
SkPoint p;
p.setLength(rand.nextS(), rand.nextS(), SK_Scalar1);
@ -256,7 +256,7 @@ static void TestMath(skiatest::Reporter* reporter) {
#endif
#ifdef SkLONGLONG
for (i = 0; i < 100000; i++) {
for (i = 0; i < 10000; i++) {
SkFixed numer = rand.nextS();
SkFixed denom = rand.nextS();
SkFixed result = SkFixedDiv(numer, denom);
@ -321,7 +321,7 @@ static void TestMath(skiatest::Reporter* reporter) {
#endif
#ifdef SK_CAN_USE_FLOAT
for (i = 0; i < 100000; i++) {
for (i = 0; i < 10000; i++) {
SkFract x = rand.nextU() >> 1;
double xx = (double)x / SK_Fract1;
SkFract xr = SkFractSqrt(x);
@ -351,7 +351,7 @@ static void TestMath(skiatest::Reporter* reporter) {
}
int maxDiff = 0;
for (i = 0; i < 10000; i++) {
for (i = 0; i < 1000; i++) {
SkFixed rads = rand.nextS() >> 10;
double frads = SkFixedToFloat(rads);

View File

@ -90,7 +90,7 @@ static void test_pack8(skiatest::Reporter* reporter) {
}
for (size_t size = 1; size <= 512; size += 1) {
for (int n = 200; n; n--) {
for (int n = 100; n; n--) {
uint8_t src[600], src2[600];
uint8_t dst[600];
rand_fill(src, size);
@ -104,7 +104,7 @@ static void test_pack8(skiatest::Reporter* reporter) {
bool match = memcmp(src, src2, size * sizeof(uint8_t)) == 0;
REPORTER_ASSERT(reporter, match);
for (int j = 0; j < 200; j++) {
for (int j = 0; j < 100; j++) {
size_t skip = gRand.nextU() % size;
size_t write = gRand.nextU() % size;
if (skip + write > size) {