From 2a2c5567a08af4057fc6ca7ec7f04eb9e2953732 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 22 Mar 2012 23:50:43 +0100 Subject: [PATCH] Fix highres rendering --- .../src/net/osmand/render/default.render.xml | 2 +- OsmAnd/jni/osmand/rendering.cpp | 71 ++++++++++--------- OsmAnd/jni/osmand/textdraw.cpp | 13 ++-- .../osmand/plus/render/OsmandRenderer.java | 11 ++- .../net/osmand/plus/render/TextRenderer.java | 17 ++++- 5 files changed, 73 insertions(+), 41 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/render/default.render.xml b/DataExtractionOSM/src/net/osmand/render/default.render.xml index df3263a6b5..da73316586 100644 --- a/DataExtractionOSM/src/net/osmand/render/default.render.xml +++ b/DataExtractionOSM/src/net/osmand/render/default.render.xml @@ -738,7 +738,7 @@ - + diff --git a/OsmAnd/jni/osmand/rendering.cpp b/OsmAnd/jni/osmand/rendering.cpp index 6833b66b5a..b1ba09b92a 100644 --- a/OsmAnd/jni/osmand/rendering.cpp +++ b/OsmAnd/jni/osmand/rendering.cpp @@ -560,38 +560,45 @@ void drawObject(RenderingContext* rc, BaseMapDataObject* mapObject, SkCanvas* cv void drawIconsOverCanvas(RenderingContext* rc, SkCanvas* canvas) { - int skewConstant = (int) getDensityValue(rc, 16); - int iconsW = rc -> width / skewConstant; - int iconsH = rc -> height / skewConstant; - int len = (iconsW * iconsH) / 32; - int alreadyDrawnIcons[len]; - memset(alreadyDrawnIcons, 0, sizeof(int)*len); - size_t ji = 0; - SkPaint p; - p.setStyle(SkPaint::kStroke_Style); - for(;ji< rc->iconsToDraw.size(); ji++) - { - IconDrawInfo icon = rc->iconsToDraw.at(ji); - if (icon.y >= 0 && icon.y < rc -> height && icon.x >= 0 && icon.x < rc -> width && - icon.bmp != NULL) { - int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW); - int i = z / 32; - if (i >= len) { - continue; - } - int ind = alreadyDrawnIcons[i]; - int b = z % 32; - // check bit b if it is set - if (((ind >> b) & 1) == 0) { - alreadyDrawnIcons[i] = ind | (1 << b); - SkBitmap* ico = icon.bmp; - PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p)); - } - } - if(rc->interrupted()){ - return; - } - } + int skewConstant = (int) getDensityValue(rc, 16); + int iconsW = rc -> width / skewConstant; + int iconsH = rc -> height / skewConstant; + int len = (iconsW * iconsH) / 32; + int alreadyDrawnIcons[len]; + memset(alreadyDrawnIcons, 0, sizeof(int)*len); + size_t ji = 0; + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + for(;ji< rc->iconsToDraw.size(); ji++) + { + IconDrawInfo icon = rc->iconsToDraw.at(ji); + if (icon.y >= 0 && icon.y < rc -> height && icon.x >= 0 && icon.x < rc -> width && + icon.bmp != NULL) { + int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW); + int i = z / 32; + if (i >= len) { + continue; + } + int ind = alreadyDrawnIcons[i]; + int b = z % 32; + // check bit b if it is set + if (((ind >> b) & 1) == 0) { + alreadyDrawnIcons[i] = ind | (1 << b); + SkBitmap* ico = icon.bmp; + if(rc->highResMode) { + float left = icon.x - getDensityValue(rc, ico->width() / 2); + float top = icon.y - getDensityValue(rc, ico->height() / 2); + SkRect r = SkRect::MakeXYWH(left, top, getDensityValue(rc, ico->width()), getDensityValue(rc, ico->height())); + PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmapRect(*ico, (SkIRect*) NULL, r, &p)); + } else { + PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p)); + } + } + } + if(rc->interrupted()){ + return; + } + } } std::hash_map > sortObjectsByProperOrder(std::vector mapDataObjects, diff --git a/OsmAnd/jni/osmand/textdraw.cpp b/OsmAnd/jni/osmand/textdraw.cpp index 603a89763f..6f7b3d73ae 100644 --- a/OsmAnd/jni/osmand/textdraw.cpp +++ b/OsmAnd/jni/osmand/textdraw.cpp @@ -534,10 +534,15 @@ void drawTextOverCanvas(RenderingContext* rc, SkCanvas* cv) { if (text->shieldRes.length() > 0) { SkBitmap* ico = getCachedBitmap(rc, text->shieldRes); if (ico != NULL) { - rc->nativeOperations.pause(); - cv->drawBitmap(*ico, text->centerX - ico->width() / 2 - 0.5f, - text->centerY - ico->height() / 2 - getDensityValue(rc, 4.5f), &paintIcon); - rc->nativeOperations.start(); + if(rc->highResMode) { + float left = text->centerX - getDensityValue(rc, ico->width() / 2) - 0.5f; + float top =text->centerY - getDensityValue(rc, ico->height() / 2) - getDensityValue(rc, 4.5f); + SkRect r = SkRect::MakeXYWH(left, top, getDensityValue(rc, ico->width()), getDensityValue(rc, ico->height())); + PROFILE_NATIVE_OPERATION(rc, cv->drawBitmapRect(*ico, (SkIRect*) NULL, r, &paintIcon)); + } else { + PROFILE_NATIVE_OPERATION(rc, cv->drawBitmap(*ico, text->centerX - ico->width() / 2 - 0.5f, + text->centerY - ico->height() / 2 - getDensityValue(rc, 4.5f), &paintIcon)); + } } } drawWrappedText(rc, cv, text, textSize, paintText); diff --git a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java index c11cc4c952..500accfc9a 100644 --- a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java @@ -36,6 +36,8 @@ import android.graphics.Paint.Style; import android.graphics.Path; import android.graphics.PathEffect; import android.graphics.PointF; +import android.graphics.Rect; +import android.graphics.RectF; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; import android.graphics.Shader; @@ -358,7 +360,14 @@ public class OsmandRenderer { // check bit b if it is set if (((ind >> b) & 1) == 0) { alreadyDrawnIcons[i] = ind | (1 << b); - cv.drawBitmap(ico, icon.x - ico.getWidth() / 2, icon.y - ico.getHeight() / 2, paintIcon); + if(rc.highResMode) { + float left = icon.x - rc.getDensityValue(ico.getWidth() / 2); + float top = icon.y - rc.getDensityValue(ico.getHeight() / 2); + cv.drawBitmap(ico, null, new RectF(left, top, left + rc.getDensityValue(ico.getWidth()), top + + rc.getDensityValue(ico.getHeight())), paintIcon); + } else { + cv.drawBitmap(ico, icon.x - ico.getWidth() / 2, icon.y - ico.getHeight() / 2, paintIcon); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java index 554e587fa8..17af0b10d5 100644 --- a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java @@ -237,8 +237,19 @@ public class TextRenderer { if (text.shieldRes != null) { Bitmap ico = RenderingIcons.getIcon(context, text.shieldRes); if (ico != null) { - cv.drawBitmap(ico, text.centerX - ico.getWidth() / 2 - 0.5f, - text.centerY - ico.getHeight() / 2 - rc.getDensityValue(4.5f), paintIcon); + + if (rc.highResMode) { + float left = text.centerX - rc.getDensityValue(ico.getWidth() / 2) - 0.5f; + float top = text.centerY - rc.getDensityValue(ico.getHeight() / 2) - rc.getDensityValue(4.5f); + Rect rec = new Rect(0, 0, ico.getWidth(), ico.getHeight()); + cv.drawBitmap(ico, rec, + new RectF(left, top, left + rc.getDensityValue(ico.getWidth()), top + + rc.getDensityValue(ico.getHeight())), paintIcon); + } else { + float left = text.centerX - ico.getWidth() / 2 - 0.5f; + float top = text.centerY - ico.getHeight() / 2 - rc.getDensityValue(4.5f); + cv.drawBitmap(ico, left, top, paintIcon); + } } } @@ -298,7 +309,7 @@ public class TextRenderer { if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){ TextDrawInfo text = new TextDrawInfo(name); text.fillProperties(render, xMid, yMid); - paintText.setTextSize(text.textSize); + paintText.setTextSize(rc.getDensityValue(text.textSize)); Rect bs = new Rect(); paintText.getTextBounds(name, 0, name.length(), bs); text.bounds = new RectF(bs);