Mercurial > MadButterfly
diff src/graph_engine_skia.cpp @ 822:586e50f82c1f
Unify coding style tag for emacs and vim.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 01:08:39 +0800 |
parents | 663d361eb3b8 |
children | 7b4e80ab671a |
line wrap: on
line diff
--- a/src/graph_engine_skia.cpp Tue Sep 14 00:25:44 2010 +0800 +++ b/src/graph_engine_skia.cpp Tue Sep 14 01:08:39 2010 +0800 @@ -1,3 +1,5 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 /*! \page ge_layer Graphic Engine Layer * * Graphic Engine Layer is an abstract of graphic engine; likes Cairo @@ -81,7 +83,7 @@ SkPath *path, *subpath; SkPaint *paint; SkRegion *saved_region; - + struct _mbe_states_t *states; }; @@ -135,9 +137,9 @@ SkPath path; co_aix x, y; co_aix reverse[6]; - + *mbe->saved_region = canvas->getTotalClip(); - + compute_reverse(ptn->matrix, reverse); x = 0; y = 0; matrix_trans_pos(reverse, &x, &y); @@ -149,14 +151,14 @@ matrix_trans_pos(reverse, &x, &y); path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); path.close(); - + canvas->clipPath(path, SkRegion::kIntersect_Op); } static void _finish_sized_pattern(mbe_t *mbe) { SkCanvas *canvas = mbe->canvas; - + canvas->setClipRegion(*mbe->saved_region); } @@ -180,7 +182,7 @@ MB_MATRIX_2_SKMATRIX(canvas_matrix, mbe->states->matrix); path->addPath(*subpath, canvas_matrix); - + subpath->getLastPt(&point); subpath->rewind(); subpath->moveTo(point); @@ -200,7 +202,7 @@ SkMatrix skmatrix; paint->setStyle(style); - + if(ptn != NULL) { /* Local matrix of SkShader is a mapping from source pattern to * user space. Unlikely, for Cairo is a mapping from user space @@ -223,7 +225,7 @@ static void _finish_paint(mbe_t *mbe) { mbe_pattern_t *ptn = mbe->states->ptn; - + mbe->paint->reset(); if(ptn != NULL && ptn->has_size) _finish_sized_pattern(mbe); @@ -241,13 +243,13 @@ free(ptn); return NULL; } - + ptn->has_size = 1; ptn->w = bitmap->width(); ptn->h = bitmap->height(); memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); - + return ptn; } @@ -269,7 +271,7 @@ goto fail; center.set(CO_AIX_2_SKSCALAR(cx1), CO_AIX_2_SKSCALAR(cy1)); - + stop = stops; for(i = 0; i < stop_cnt; i++) { colors[i] = MBSTOP_2_SKCOLOR(stop); @@ -289,11 +291,11 @@ goto fail; memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); - + delete colors; delete poses; return ptn; - + fail: if(ptn) free(ptn); if(colors) delete colors; @@ -320,7 +322,7 @@ points[0].set(CO_AIX_2_SKSCALAR(x0), CO_AIX_2_SKSCALAR(y0)); points[1].set(CO_AIX_2_SKSCALAR(x1), CO_AIX_2_SKSCALAR(y1)); - + stop = stops; for(i = 0; i < stop_cnt; i++) { colors[i] = MBSTOP_2_SKCOLOR(stop); @@ -339,11 +341,11 @@ goto fail; memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); - + delete colors; delete poses; return ptn; - + fail: if(ptn) free(ptn); if(colors) delete colors; @@ -394,25 +396,25 @@ switch(fmt) { case MB_IFMT_ARGB32: cfg = SkBitmap::kARGB_8888_Config; break; - + case MB_IFMT_A8: cfg = SkBitmap::kA8_Config; break; - + case MB_IFMT_A1: cfg = SkBitmap::kA1_Config; break; - + case MB_IFMT_RGB16_565: cfg = SkBitmap::kRGB_565_Config; break; - + case MB_IFMT_RGB24: default: return NULL; } - + bitmap = new SkBitmap(); if(bitmap == NULL) return NULL; - + bitmap->setConfig(cfg, width, height, stride); bitmap->setPixels(data); @@ -423,7 +425,7 @@ SkBitmap *bitmap = (SkBitmap *)surface; mb_img_fmt_t fmt; SkBitmap::Config cfg; - + cfg = bitmap->getConfig(); switch(cfg) { case SkBitmap::kARGB_8888_Config: @@ -453,25 +455,25 @@ switch(fmt) { case MB_IFMT_ARGB32: cfg = SkBitmap::kARGB_8888_Config; break; - + case MB_IFMT_A8: cfg = SkBitmap::kA8_Config; break; - + case MB_IFMT_A1: cfg = SkBitmap::kA1_Config; break; - + case MB_IFMT_RGB16_565: cfg = SkBitmap::kRGB_565_Config; break; - + case MB_IFMT_RGB24: default: return NULL; } - + bitmap = new SkBitmap(); if(bitmap == NULL) return NULL; - + bitmap->setConfig(cfg, width, height); bitmap->allocPixels(); @@ -503,12 +505,12 @@ SkColorFilter::CreatePorterDuffFilter(color, SkPorterDuff::kSrcOver_Mode); mbe_paint(canvas); - + } void mbe_surface_destroy(mbe_surface_t *surface) { SkBitmap *bmap = (SkBitmap *)surface; - + delete bmap; } @@ -544,7 +546,7 @@ if(!canvas->subpath->isEmpty()) _update_path(canvas); - + _prepare_paint(canvas, SkPaint::kFill_Style); canvas->canvas->drawPath(*path, *paint); @@ -576,7 +578,7 @@ void mbe_rectangle(mbe_t *canvas, co_aix x, co_aix y, co_aix width, co_aix height) { SkPath *subpath = canvas->subpath; - + subpath->addRect(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y), CO_AIX_2_SKSCALAR(x + width), CO_AIX_2_SKSCALAR(y + height)); @@ -605,7 +607,7 @@ struct _mbe_states_t *states; _update_path(canvas); - + states = canvas->states; ASSERT(states->next); canvas->states = states->next; @@ -628,10 +630,10 @@ if(!canvas->subpath->isEmpty()) _update_path(canvas); - + _canvas_device_region(canvas->canvas, &dev_region); region.setPath(*canvas->path, dev_region); - + in_fill = region.contains(x, y); return in_fill; @@ -670,7 +672,7 @@ mbe = (mbe_t *)malloc(sizeof(mbe_t)); if(mbe == NULL) return NULL; - + mbe->states = (struct _mbe_states_t *) malloc(sizeof(struct _mbe_states_t)); states = mbe->states; @@ -678,7 +680,7 @@ free(mbe); return NULL; } - + canvas->ref(); mbe->canvas = canvas; mbe->path = new SkPath(); @@ -696,7 +698,7 @@ goto fail; memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6); - + return mbe; fail: @@ -707,7 +709,7 @@ if(mbe->saved_region) delete mbe->saved_region; free(states); free(mbe); - + return NULL; } @@ -721,20 +723,20 @@ delete bitmap; return NULL; } - + mbe = skia_mbe_create_by_canvas(canvas); canvas->unref(); - + if(mbe == NULL) { delete bitmap; } - + return mbe; } void mbe_destroy(mbe_t *canvas) { struct _mbe_states_t *states; - + canvas->canvas->unref(); delete canvas->path; delete canvas->subpath; @@ -743,7 +745,7 @@ while(canvas->states) { states = canvas->states; canvas->states = states->next; - + if(states->ptn && states->ptn_owned) mbe_pattern_destroy(states->ptn); free(states); @@ -755,9 +757,9 @@ SkPaint *paint = canvas->paint; ASSERT(paint); - + _prepare_paint(canvas, SkPaint::kFill_Style); - + canvas->canvas->drawPaint(*paint); _finish_paint(canvas); @@ -768,7 +770,7 @@ states = (struct _mbe_states_t *)malloc(sizeof(struct _mbe_states_t)); ASSERT(states); - + memcpy(states, canvas->states, sizeof(struct _mbe_states_t)); states->next = canvas->states; canvas->states = states; @@ -783,7 +785,7 @@ void mbe_clip(mbe_t *canvas) { if(!canvas->subpath->isEmpty()) _update_path(canvas); - + canvas->canvas->clipPath(*canvas->path, SkRegion::kIntersect_Op); canvas->path->rewind(); canvas->subpath->rewind(); @@ -810,7 +812,7 @@ bmap = &src->canvas->getDevice()->accessBitmap(false); dst->canvas->drawBitmap(*bmap, 0, 0, paint); - + paint->reset(); mode->unref(); /* _finish_paint(dst); */ @@ -818,7 +820,7 @@ void mbe_transform(mbe_t *mbe, co_aix matrix[6]) { _update_path(mbe); - + matrix_mul(matrix, mbe->states->matrix, mbe->states->matrix); } @@ -838,7 +840,7 @@ r = CO_AIX_2_SKSCALAR(radius); ang_start = CO_AIX_2_SKSCALAR(angle_start * 180 / PI); ang_stop = CO_AIX_2_SKSCALAR(angle_stop * 180 / PI); - + /* Skia can only draw an arc in clockwise directly. We negative * start and stop point to draw the arc in the mirror along x-axis * in a sub-path. Then, the sub-path are reflected along x-axis, @@ -849,7 +851,7 @@ SkMatrix matrix; co_aix reflect[6] = { 1, 0, 0, 0, -1, 0}; - + rect.set(-r, -r, r, r); sweep = ang_start - ang_stop; tmppath.arcTo(rect, -ang_start, sweep, false);