static void test_asColorMode(skiatest::Reporter* reporter) {
    SkRandom rand;

    for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
        SkColor color = rand.nextU();

        // ensure we always get a filter, by avoiding the possibility of a
        // special case that would return NULL (if color's alpha is 0 or 0xFF)
        color = SkColorSetA(color, 0x7F);

        SkColorFilter* cf = SkColorFilter::CreateModeFilter(color,
                                                        (SkXfermode::Mode)mode);

        // allow for no filter if we're in Dst mode (its a no op)
        if (SkXfermode::kDst_Mode == mode && NULL == cf) {
            continue;
        }

        SkAutoUnref aur(cf);
        REPORTER_ASSERT(reporter, cf);

        SkColor c = ~color;
        SkXfermode::Mode m = ILLEGAL_MODE;

        SkColor expectedColor = color;
        SkXfermode::Mode expectedMode = (SkXfermode::Mode)mode;

//        SkDebugf("--- mc [%d %x] ", mode, color);

        REPORTER_ASSERT(reporter, cf->asColorMode(&c, &m));
        // handle special-case folding by the factory
        if (SkXfermode::kClear_Mode == mode) {
            if (c != expectedColor) {
                expectedColor = 0;
            }
            if (m != expectedMode) {
                expectedMode = SkXfermode::kSrc_Mode;
            }
        } 

//        SkDebugf("--- got [%d %x] expected [%d %x]\n", m, c, expectedMode, expectedColor);

        REPORTER_ASSERT(reporter, c == expectedColor);
        REPORTER_ASSERT(reporter, m == expectedMode);
        
        {
            SkColorFilter* cf2 = reincarnate(cf);
            SkAutoUnref aur2(cf2);
            REPORTER_ASSERT(reporter, cf2);

            SkColor c2 = ~color;
            SkXfermode::Mode m2 = ILLEGAL_MODE;
            REPORTER_ASSERT(reporter, cf2->asColorMode(&c2, &m2));
            REPORTER_ASSERT(reporter, c2 == expectedColor);
            REPORTER_ASSERT(reporter, m2 == expectedMode);
        }
    }
}
Example #2
0
void *
glusterfs_sigwaiter (void *arg)
{
    sigset_t  set;
    int       ret = 0;
    int       sig = 0;


    sigaddset (&set, SIGINT);   /* cleanup_and_exit */
    sigaddset (&set, SIGTERM);  /* cleanup_and_exit */
    sigaddset (&set, SIGHUP);   /* reincarnate */
    sigaddset (&set, SIGUSR1);  /* gf_proc_dump_info */
    sigaddset (&set, SIGUSR2);  /* gf_latency_toggle */

    for (;;) {
        ret = sigwait (&set, &sig);
        if (ret)
            continue;


        switch (sig) {
        case SIGINT:
        case SIGTERM:
            cleanup_and_exit (sig);
            break;
        case SIGHUP:
            reincarnate (sig);
            break;
        case SIGUSR1:
            gf_proc_dump_info (sig);
            break;
        case SIGUSR2:
            gf_latency_toggle (sig);
            break;
        default:

            break;
        }
    }

    return NULL;
}