bool MediaLayer::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix) { TilesManager::instance()->shader()->clip(drawClip()); // when the plugin gains focus webkit applies an outline to the // widget, which causes the layer to expand to accommodate the // outline. Therefore, we shrink the rect by the outline's dimensions // to ensure the plugin does not draw outside of its bounds. SkRect mediaBounds; mediaBounds.set(0, 0, getSize().width(), getSize().height()); mediaBounds.inset(m_outlineSize, m_outlineSize); // check to see if we need to create a content or video texture m_mediaTexture->initNativeWindowIfNeeded(); // the layer's shader draws the content inverted so we must undo // that change in the transformation matrix TransformationMatrix m = m_drawTransform; if (!m_mediaTexture->isContentInverted()) { m.flipY(); m.translate(0, -getSize().height()); } // draw any content or video if present m_mediaTexture->draw(m, m_drawTransform, mediaBounds); return drawChildrenGL(glWebViewState, matrix); }
void drawBackground(int xStart,int yStart,SDL_Rect *clip) { int x, y; for(y=yStart;y<SCREENH;y+=TILEH) { for(x=xStart;x<SCREENW;x+=TILEW) { drawClip(x, y, background, &clip[45]); } } }
virtual void onDrawContent(SkCanvas* canvas) { #if 1 SkAAClip aaclip; SkPath path; SkRect bounds; bounds.set(0, 0, 20, 20); bounds.inset(SK_ScalarHalf, SK_ScalarHalf); // path.addRect(bounds); // path.addOval(bounds); path.addRoundRect(bounds, 4, 4); aaclip.setPath(path); canvas->translate(30, 30); drawClip(canvas, aaclip); SkAAClip aaclip2; path.offset(10, 10); aaclip2.setPath(path); canvas->translate(30, 0); drawClip(canvas, aaclip2); SkAAClip aaclip3; aaclip3.op(aaclip, aaclip2, SkRegion::kIntersect_Op); canvas->translate(30, 0); drawClip(canvas, aaclip3); #endif #if 0 SkRect r; r.set(0, 0, this->width(), this->height()); r.inset(20, 20); canvas->clipRect(r); SkPath path; path.addRect(r); SkPaint paint; paint.setAntiAlias(true); paint.setColor(SK_ColorRED); canvas->drawPath(path, paint); #endif }
void writeText(int x,int y,char *string) { int i, ltr; for(i=0;string[i]!='\0';i++) { switch (string[i]) { case ' ': ltr=0; break; case '0': ltr=1; break; case '1': ltr=2; break; case '2': ltr=3; break; case '3': ltr=4; break; case '4': ltr=5; break; case '5': ltr=6; break; case '6': ltr=7; break; case '7': ltr=8; break; case '8': ltr=9; break; case '9': ltr=10; break; case 'a': ltr=11; break; case 'b': ltr=12; break; case 'c': ltr=13; break; case 'd': ltr=14; break; case 'e': ltr=15; break; case 'f': ltr=16; break; case 'g': ltr=17; break; case 'h': ltr=18; break; case 'i': ltr=19; break; case 'j': ltr=20; break; case 'k': ltr=21; break; case 'l': ltr=22; break; case 'm': ltr=23; break; case 'n': ltr=24; break; case 'o': ltr=25; break; case 'p': ltr=26; break; case 'q': ltr=27; break; case 'r': ltr=28; break; case 's': ltr=29; break; case 't': ltr=30; break; case 'u': ltr=31; break; case 'v': ltr=32; break; case 'w': ltr=33; break; case 'x': ltr=34; break; case 'y': ltr=35; break; case 'z': ltr=36; break; case '.': ltr=37; break; case '!': ltr=38; break; case '?': ltr=39; break; } drawClip(x, y, background, &bgClip[ltr]); x += TILEW; } }
void LayerAndroid::updateGLPositionsAndScale(const TransformationMatrix& parentMatrix, const FloatRect& clipping, float opacity, float scale, bool forceCalculation, bool disableFixedElemUpdate) { m_scale = scale; opacity *= getOpacity(); setDrawOpacity(opacity); // constantly recalculate the draw transform of layers that may require it (and their children) forceCalculation |= hasDynamicTransform(); forceCalculation &= !(disableFixedElemUpdate && isPositionFixed()); if (forceCalculation) updateLocalTransformAndClip(parentMatrix, clipping); if (!countChildren() || !m_visible) return; TransformationMatrix localMatrix = m_drawTransformUnfudged; // Flatten to 2D if the layer doesn't preserve 3D. if (!preserves3D()) { localMatrix.setM13(0); localMatrix.setM23(0); localMatrix.setM31(0); localMatrix.setM32(0); localMatrix.setM33(1); localMatrix.setM34(0); localMatrix.setM43(0); } // now apply it to our children TransformationMatrix childMatrix; childMatrix = localMatrix; childMatrix.translate3d(getScrollOffset().x(), getScrollOffset().y(), 0); if (!m_childrenTransform.isIdentity()) { childMatrix.translate(getSize().width() * 0.5f, getSize().height() * 0.5f); childMatrix.multiply(m_childrenTransform); childMatrix.translate(-getSize().width() * 0.5f, -getSize().height() * 0.5f); } for (int i = 0; i < countChildren(); i++) this->getChild(i)->updateGLPositionsAndScale(childMatrix, drawClip(), opacity, scale, forceCalculation, disableFixedElemUpdate); }
void drawModel (pScene sc) { pMesh mesh; pTransform view; pClip clip; ubyte sstatic; /* default */ mesh = cv.mesh[sc->idmesh]; view = sc->view; clip = sc->clip; if (ddebug) printf("\n-- redraw scene %d, mesh %d\n", sc->idwin, sc->idmesh); glDisable(GL_LIGHTING); /* draw clipping plane */ if (clip->active & C_ON) { drawClip(sc, clip, mesh, 0); glClipPlane(GL_CLIP_PLANE0, clip->eqn); glEnable(GL_CLIP_PLANE0); } else { glDisable(GL_CLIP_PLANE0); } /* draw object if static scene */ sstatic = view->mstate > 0 && clip->cliptr->mstate > 0; if (sstatic || sc->type & S_FOLLOW) { displayScene(sc, sc->mode, 0); if (sc->item & S_NUMP || sc->item & S_NUMF) listNum(sc, mesh); /* draw normals */ if (sc->type & S_NORMAL) { if (!sc->nlist) sc->nlist = drawNormals(mesh, sc); glCallList(sc->nlist); } /* draw data */ if (sstatic) displayData(sc, mesh); } else if (!(sc->item & S_BOX)) { drawBox(sc, mesh, 0); } /* draw ridges, corners, etc. */ if ((sc->item & S_GEOM) && sc->glist) { glDisable(GL_LIGHTING); if (!mesh->ne) glPointSize(1); else glPointSize(5); glDisable(GL_COLOR_MATERIAL); glCallList(sc->glist); } glDisable(GL_CLIP_PLANE0); if (clip->active & C_EDIT || sc->item & S_BOX) drawBox(sc, mesh, 0); if (sc->item & S_AXIS) drawAxis(sc, mesh->dim); if ((mesh->dim == 3 || sc->mode & S_ALTITUDE) && sc->item & S_GRID) drawBase(sc, mesh); if (sc->cube->active & C_ON) drawCube(sc, mesh); sstatic |= tiling; if (sstatic && clip->active & C_ON && clip->active & C_VOL) displayScene(sc, sc->mode, 1); if (sc->picklist && !(sc->isotyp & S_PARTICLE)) { glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_POLYGON_OFFSET_FILL); glCallList(sc->picklist); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); } /* show path, if any */ if (sc->type & S_PATH && sc->path.tlist) glCallList(sc->path.tlist); }
int process(char *fname, int components, int z_lookup, unsigned char *startbuf, unsigned char *endbuf, int z_draw, int x_draw, int y_draw, struct graphics *gc, int mapbits, int metabits, int dump, int gps, struct color_range *colors, int xoff, int yoff) { int bytes = bytesfor(mapbits, metabits, components, z_lookup); int ret = 0; char fn[strlen(fname) + 1 + 5 + 1 + 5 + 1]; struct tilecontext tc; tc.z = z_draw; tc.x = x_draw; tc.y = y_draw; tc.xoff = xoff; tc.yoff = yoff; if (components == 1) { sprintf(fn, "%s/1,0", fname); } else { sprintf(fn, "%s/%d,%d", fname, components, z_lookup); } int fd = open(fn, O_RDONLY); if (fd < 0) { // perror(fn); return ret; } struct stat st; if (fstat(fd, &st) < 0) { perror("stat"); exit(EXIT_FAILURE); } unsigned char *map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); } gSortBytes = bytes; unsigned char *start = search(startbuf, map, st.st_size / bytes, bytes, bufcmp); unsigned char *end = search(endbuf, map, st.st_size / bytes, bytes, bufcmp); end += bytes; // points to the last value in range; need the one after that if (memcmp(start, startbuf, bytes) < 0) { start += bytes; // if not exact match, points to element before match } int step = 1; double brush = 1; double thick = line_thick; double bright1; if (components == 1) { bright1 = dot_bright; if (z_draw > dot_base) { step = 1; brush = exp(log(2.0) * (z_draw - dot_base)); bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } else { step = floor(exp(log(exponent) * (dot_base - z_draw)) + .5); bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); bright1 = bright1 * step / (1 << (dot_base - z_draw)); } bright1 /= point_size; brush *= point_size; } else { bright1 = dot_bright * line_per_dot / line_thick; if (line_ramp >= 1) { thick *= exp(log(line_ramp) * (z_draw - dot_base)); bright1 *= exp(log(dot_ramp / line_ramp) * (z_draw - dot_base)); } else { bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } } if (mercator >= 0) { double lat, lon; tile2latlon((x_draw + .5) * (1LL << (32 - z_draw)), (y_draw + .5) * (1LL << (32 - z_draw)), 32, &lat, &lon); double rat = cos(lat * M_PI / 180); double base = cos(mercator * M_PI / 180); brush /= rat * rat / (base * base); } if (dump) { step = 1; } else { // Align to step size so each zoom is a superset of the previous start = (start - map + (step * bytes - 1)) / (step * bytes) * (step * bytes) + map; } double size = cloudsize(z_draw, x_draw, y_draw); int innerstep = 1; long long todo = 0; size *= tilesize; // convert to pixels if (circle > 0) { // An additional 4 zoom levels without skipping // XXX Why 4? if (step > 1 && size > .0625) { innerstep = step; step = 1; } } const double b = brush * (tilesize / 256.0) * (tilesize / 256.0); for (; start < end; start += step * bytes) { unsigned int x[components], y[components]; double xd[components], yd[components]; int k; unsigned long long meta = 0; buf2xys(start, mapbits, metabits, z_lookup, components, x, y, &meta); if (meta > maxmeta) { continue; } if (!dump && z_draw >= mapbits / 2 - 8) { // Add noise below the bottom of the file resolution // so that it looks less gridded when overzoomed int j; for (j = 0; j < components; j++) { int noisebits = 32 - mapbits / 2; int i; for (i = 0; i < noisebits; i++) { x[j] |= ((y[j] >> (2 * noisebits - 1 - i)) & 1) << i; y[j] |= ((x[j] >> (2 * noisebits - 1 - i)) & 1) << i; } } } double hue = -1; if (metabits > 0 && colors->active) { hue = (((double) meta - colors->meta1) / (colors->meta2 - colors->meta1) * (colors->hue2 - colors->hue1) + colors->hue1) / 360; if (hue < -2) { hue = -1; } else { while (hue < 0) { hue++; } while (hue > 1) { hue--; } } } double bright = bright1; double bb = b; if (metabright) { bright *= meta; } if (metabrush) { bb = bb * meta; } for (k = 0; k < components; k++) { wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } if (dump) { int should = 0; if (components == 1) { should = 1; } else { for (k = 1; k < components; k++) { double x1 = xd[k - 1]; double y1 = yd[k - 1]; double x2 = xd[k]; double y2 = yd[k]; if (clip(&x1, &y1, &x2, &y2, 0, 0, 1, 1)) { should = 1; break; } } } if (should) { dump_out(dump, x, y, components, metabits, meta); } } else if (components == 1) { if (!antialias) { xd[0] = ((int) (xd[0] * tilesize) + .5) / tilesize; yd[0] = ((int) (yd[0] * tilesize) + .5) / tilesize; } if (circle > 0) { if (size < .5) { if (bb <= 1) { drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb * meta / innerstep, hue, meta, &tc); } else { drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright * meta / innerstep, bb, hue, meta, gaussian, &tc); ret = 1; } } else { double xc = (xd[0] * tilesize) + xoff; double yc = (yd[0] * tilesize) + yoff; if (xc + size >= 0 && yc + size >= 0 && xc - size <= tilesize && yc - size <= tilesize) { srand(x[0] * 37 + y[0]); for (todo += meta; todo > 0; todo -= innerstep) { double r = sqrt(((double) (rand() & (INT_MAX - 1))) / (INT_MAX)); double ang = ((double) (rand() & (INT_MAX - 1))) / (INT_MAX) * 2 * M_PI; double xp = xc + size * r * cos(ang); double yp = yc + size * r * sin(ang); if (bb <= 1) { drawPixel(xp - .5, yp - .5, gc, bright * bb, hue, meta, &tc); } else { drawBrush(xp, yp, gc, bright, bb, hue, meta, gaussian, &tc); ret = 1; } } } } } else { if (bb <= 1) { drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb, hue, meta, &tc); } else { drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright, bb, hue, meta, gaussian, &tc); ret = 1; } } } else { for (k = 1; k < components; k++) { double bright1 = bright; long long xk1 = x[k - 1]; long long xk = x[k]; if (gps) { double xdist = (long long) x[k] - (long long) x[k - 1]; double ydist = (long long) y[k] - (long long) y[k - 1]; double dist = sqrt(xdist * xdist + ydist * ydist); double min = gps_dist; min = min * exp(log(gps_ramp) * (gps_base - z_draw)); if (dist > min) { bright1 /= (dist / min); } if (bright1 < .0025) { continue; } } double thick1 = thick * tilesize / 256.0; if (xk - xk1 >= (1LL << 31)) { wxy2fxy(xk - (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); wxy2fxy(xk1 + (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); } else if (xk1 - xk >= (1LL << 31)) { wxy2fxy(xk1 - (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); wxy2fxy(xk + (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } else { drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); } } } }
int process(char *fname, int components, int z_lookup, unsigned char *startbuf, unsigned char *endbuf, int z_draw, int x_draw, int y_draw, double *image, double *cx, double *cy, int mapbits, int metabits, int dump, int gps, int colors) { int bytes = bytesfor(mapbits, metabits, components, z_lookup); int ret = 0; char fn[strlen(fname) + 1 + 5 + 1 + 5 + 1]; if (components == 1) { sprintf(fn, "%s/1,0", fname); } else { sprintf(fn, "%s/%d,%d", fname, components, z_lookup); } int fd = open(fn, O_RDONLY); if (fd < 0) { perror(fn); return ret; } struct stat st; if (fstat(fd, &st) < 0) { perror("stat"); exit(EXIT_FAILURE); } unsigned char *map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); } gSortBytes = bytes; unsigned char *start = search(startbuf, map, st.st_size / bytes, bytes, bufcmp); unsigned char *end = search(endbuf, map, st.st_size / bytes, bytes, bufcmp); end += bytes; // points to the last value in range; need the one after that if (memcmp(start, startbuf, bytes) < 0) { start += bytes; // if not exact match, points to element before match } int step = 1; double brush = 1; double bright1; if (components == 1) { bright1 = dot_bright; if (z_draw > dot_base) { step = 1; brush = 1 << (multiplier * (z_draw - dot_base)); } else { step = 1 << (multiplier * (dot_base - z_draw)); } bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } else { bright1 = dot_bright * line_per_dot; bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } if (dump) { step = 1; } else { // Align to step size so each zoom is a superset of the previous start = (start - map) / (step * bytes) * (step * bytes) + map; } for (; start < end; start += step * bytes) { unsigned int x[components], y[components]; double xd[components], yd[components]; int k; unsigned int meta = 0; buf2xys(start, mapbits, metabits, z_lookup, components, x, y, &meta); if (!dump && z_draw >= mapbits / 2 - 8) { // Add noise below the bottom of the file resolution // so that it looks less gridded when overzoomed int j; for (j = 0; j < components; j++) { int noisebits = 32 - mapbits / 2; int i; for (i = 0; i < noisebits; i++) { x[j] |= ((y[j] >> (2 * noisebits - 1 - i)) & 1) << i; y[j] |= ((x[j] >> (2 * noisebits - 1 - i)) & 1) << i; } } } double hue = -1; if (metabits > 0 && colors > 0) { hue = (double) meta / colors; } double bright = bright1; if (mercator >= 0) { double lat, lon; tile2latlon(x[0], y[0], 32, &lat, &lon); double rat = cos(lat * M_PI / 180); double base = cos(mercator * M_PI / 180); bright /= rat * rat / (base * base); } for (k = 0; k < components; k++) { wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } if (dump) { int should = 0; if (components == 1) { should = 1; } else { for (k = 1; k < components; k++) { if (drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], NULL, NULL, NULL, 0, 0, 0)) { should = 1; break; } } } if (should) { for (k = 0; k < components; k++) { double lat, lon; tile2latlon(x[k], y[k], 32, &lat, &lon); printf("%lf,%lf ", lat, lon); } if (metabits != 0) { printf("%d:%d ", metabits, meta); } printf("// "); for (k = 0; k < components; k++) { printf("%08x %08x ", x[k], y[k]); } printf("\n"); } } else if (components == 1) { if (!antialias) { xd[0] = (int) xd[0] + .5; yd[0] = (int) yd[0] + .5; } if (brush <= 1) { drawPixel(xd[0] - .5, yd[0] - .5, image, cx, cy, bright * brush, hue); } else { drawBrush(xd[0], yd[0], image, cx, cy, bright, brush, hue); ret = 1; } } else { for (k = 1; k < components; k++) { double bright1 = bright; long long xk1 = x[k - 1]; long long xk = x[k]; if (gps) { double xdist = (long long) x[k] - (long long) x[k - 1]; double ydist = (long long) y[k] - (long long) y[k - 1]; double dist = sqrt(xdist * xdist + ydist * ydist); double min = gps_dist; min = min * exp(log(gps_ramp) * (gps_base - z_draw)); if (dist > min) { bright1 /= (dist / min); } if (bright1 < .0025) { continue; } } if (xk - xk1 >= (1LL << 31)) { wxy2fxy(xk - (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); wxy2fxy(xk1 + (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); } else if (xk1 - xk >= (1LL << 31)) { wxy2fxy(xk1 - (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); wxy2fxy(xk + (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } else { drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias); } } } }