// Tests scale mode with an additional copy for transparency. This will happen // if we have a scaled textbox, for example. WebKit will create a new // transparency layer, draw the text field, then draw the text into it, then // composite this down with an opacity. TEST(TransparencyWin, ScaleTransparency) { // Create an opaque white buffer. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); FloatRect fullBuffer(0, 0, 16, 16); src->context()->fillRect(fullBuffer, Color::white); // Make another layer (which duplicates how WebKit will make this). We fill // the top half with red, and have the layer be 50% opaque. src->context()->beginTransparencyLayer(0.5); FloatRect topHalf(0, 0, 16, 8); src->context()->fillRect(topHalf, Color(0xFFFF0000)); // Scale by 2x. src->context()->save(); AffineTransform scale; scale.scale(2.0); src->context()->concatCTM(scale); // Make a layer inset two pixels (because of scaling, this is 2->14). And // will it with 50% black. { TransparencyWin helper; helper.init(src->context(), TransparencyWin::OpaqueCompositeLayer, TransparencyWin::ScaleTransform, IntRect(1, 1, 6, 6)); helper.context()->fillRect(helper.drawRect(), Color(0x7f000000)); clearTopLayerAlphaChannel(helper.context()); helper.composite(); } // Finish the layer. src->context()->restore(); src->context()->endLayer(); Color redBackground(0xFFFF8080); // 50% red composited on white. EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); EXPECT_EQ(redBackground, getPixelAt(src->context(), 1, 1)); // Top half (minus two pixel border) should be 50% gray atop opaque // red = 0xFF804141. Then that's composited with 50% transparency on solid // white = 0xFFC0A1A1. Color darkRed(0xFFBF8080); EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); EXPECT_EQ(darkRed, getPixelAt(src->context(), 7, 7)); // Bottom half (minus a two pixel border) should be a layer with 5% gray // with another 50% opacity composited atop white. Color darkWhite(0xFFBFBFBF); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); Color white(0xFFFFFFFF); // Background in the lower-right. EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); }
// Tests scale mode with no additional copy. TEST(TransparencyWin, Scale) { // Create an opaque white buffer. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); FloatRect fullBuffer(0, 0, 16, 16); src->context()->fillRect(fullBuffer, Color::white); // Scale by 2x. src->context()->save(); AffineTransform scale; scale.scale(2.0); src->context()->concatCTM(scale); // Start drawing a rectangle from 1->4. This should get scaled to 2->8. { TransparencyWin helper; helper.init(src->context(), TransparencyWin::NoLayer, TransparencyWin::ScaleTransform, IntRect(1, 1, 3, 3)); // The context should now have the identity transform and the returned // rect should be scaled. EXPECT_TRUE(helper.context()->getCTM().isIdentity()); EXPECT_EQ(2, helper.drawRect().x()); EXPECT_EQ(2, helper.drawRect().y()); EXPECT_EQ(8, helper.drawRect().maxX()); EXPECT_EQ(8, helper.drawRect().maxY()); // Set the pixel at (2, 2) to be transparent. This should be fixed when // the helper goes out of scope. We don't want to call // clearTopLayerAlphaChannel because that will actually clear the whole // canvas (since we have no extra layer!). SkBitmap& bitmap = const_cast<SkBitmap&>(helper.context()->layerBitmap()); *bitmap.getAddr32(2, 2) &= 0x00FFFFFF; helper.composite(); } src->context()->restore(); // Check the pixel we previously made transparent, it should have gotten // fixed back up to white. // The current version doesn't fixup transparency when there is no layer. // This seems not to be necessary, so we don't bother, but if it becomes // necessary, this line should be uncommented. // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); }
void *oompa(void* info) { for (int i = 1; i < ((candy_struct *)info)->num + 1; ++i) { // printf("On loop %d\n", i); pthread_mutex_lock(&mutex); if (!fullBuffer()) { candy_struct *oompaInfo = malloc(sizeof(candy_struct)); oompaInfo->color = ((candy_struct *)info)->color; oompaInfo->num = i; // printf("inserting candy:\n\tColor: %s\n\tNumber: %d\n", oompaInfo->color, oompaInfo->num); insertCandy(oompaInfo); } else { --i; } pthread_mutex_unlock(&mutex); } pthread_exit(NULL); }