#include #include #include #include using namespace cdroid; class CANVAS:public testing::Test{ public : virtual void SetUp(){ } virtual void TearDown(){ } }; TEST_F(CANVAS,clip1){ Canvas c(400,400); double x1,y1,x2,y2; c.reset_clip(); c.rectangle(10,5,200,100); c.clip(); c.get_clip_extents(x1,y1,x2,y2); printf("clip(%.f,%.f,%.f,%.f)\n",x1,y1,x2,y2); ASSERT_DOUBLE_EQ(x1,10); ASSERT_DOUBLE_EQ(y1,5); ASSERT_DOUBLE_EQ(x2,210); ASSERT_DOUBLE_EQ(y2,105); } TEST_F(CANVAS,clip2){ Canvas c(400,400); double x1,y1,x2,y2; c.reset_clip(); c.rectangle(10,5,200,100); c.rectangle(10,110,200,100); c.clip(); c.get_clip_extents(x1,y1,x2,y2); printf("clip(%.f,%.f,%.f,%.f)\n",x1,y1,x2,y2); ASSERT_DOUBLE_EQ(x1,10); ASSERT_DOUBLE_EQ(y1,5); ASSERT_DOUBLE_EQ(x2,210); ASSERT_DOUBLE_EQ(y2,210); std::vectorrects; c.copy_clip_rectangle_list(rects); for(int i=0;irects; c.copy_clip_rectangle_list(rects); for(int i=0;irects; c.copy_clip_rectangle_list(rects); for(int i=0;iimg=Cairo::ImageSurface::create(Cairo::Surface::Format::ARGB32,100,100); Cairo::RefPtrctx=Cairo::Context::create(img); ctx->set_source_rgb(0,0,1); ctx->arc(50,50,50,0,M_PI*2.f); ctx->fill(); auto start=SystemClock::uptimeMillis(); c.set_source(img,0,0); for(int i=0;i<1000;i++){ c.rectangle(0,0,100,100); c.fill(); } auto end=SystemClock::uptimeMillis(); c.restore(); c.dump2png("img0.png"); printf("used time=%lld\r\n",end-start); c.translate(640,640); c.set_source(img,0,0); c.rotate_degrees(90); c.set_font_size(32); c.set_source_rgb(0,1,0); start=SystemClock::uptimeMillis(); for(int i=0;i<1000;i++){ c.rectangle(0,0,100,100); c.fill(); } end=SystemClock::uptimeMillis(); c.dump2png("img90.png"); printf("used time=%lld\r\n",end-start); }