Exemplo n.º 1
0
 public override void Draw(global::Android.Graphics.Canvas canvas)
 {
     base.Draw(canvas);
 }
 public abstract void Draw(global::Android.Graphics.Canvas canvas, global::Android.Graphics.Paint paint) /* MethodBuilder.Create */;
Exemplo n.º 3
0
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_canvas)
 {
     global::Com.Facebook.Drawee.Drawable.ForwardingDrawable __this = global::Java.Lang.Object.GetObject <global::Com.Facebook.Drawee.Drawable.ForwardingDrawable> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas canvas = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_canvas, JniHandleOwnership.DoNotTransfer);
     __this.Draw(canvas);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Renders the current complete scene.
        /// </summary>
        void Render()
        {
            if (_cacheRenderer.IsRunning) {
                _cacheRenderer.CancelAndWait ();
            }

            // make sure only on thread at the same time is using the renderer.
            lock (_cacheRenderer) {
                double extra = 1.25;

                // build the layers list.
                var layers = new List<ILayer> ();
                for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++) {
                    // get the layer.
                    layers.Add (this.Map[layerIdx]);
                }

                // add the internal layers.
                layers.Add (_makerLayer);

                // create a new cache if size has changed.
                if (_canvasBitmap == null ||
                    _canvasBitmap.Width != (int)(this.Width * extra) ||
                    _canvasBitmap.Height != (int)(this.Height * extra)) {
                    // create a bitmap and render there.
                    _canvasBitmap = global::Android.Graphics.Bitmap.CreateBitmap ((int)(this.Width * extra),
                                                                                  (int)(this.Height * extra),
                                                                                 global::Android.Graphics.Bitmap.Config.Argb8888);
                } else {
                    // clear the cache???
                }

                // create and reset the canvas.
                global::Android.Graphics.Canvas canvas = new global::Android.Graphics.Canvas (_canvasBitmap);
                canvas.DrawColor (new global::Android.Graphics.Color(
                    SimpleColor.FromKnownColor(KnownColor.Transparent).Value));

                // create the view.
                double[] sceneCenter = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                // create the view for this control.
                View2D view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                         this.Width * extra, this.Height * extra, sceneZoomFactor,
                                         _invertX, _invertY, this.MapTilt);

                long before = DateTime.Now.Ticks;

                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,
                                                "Rendering Start");

                // notify the map that the view has changed.
                this.Map.ViewChanged ((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                      view);
                long afterViewChanged = DateTime.Now.Ticks;
                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,
                                                "View change took: {0}ms @ zoom level {1}",
                                                (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                // add the current canvas to the scene.
                _scene.AddImage (-1, float.MaxValue, float.MinValue, view.Rectangle,
                                                 new byte[0], _canvasBitmap);

                // does the rendering.
                bool complete = _cacheRenderer.Render (canvas, layers, view);

                long afterRendering = DateTime.Now.Ticks;
                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,
                                                "Rendering took: {0}ms @ zoom level {1}",
                                                (new TimeSpan(afterRendering - afterViewChanged).TotalMilliseconds), this.MapZoom);
                if(complete)
                { // there was no cancellation, the rendering completely finished.
                    // add the result to the scene cache.
                    lock (_scene) {
                        // add the newly rendered image again.
                        _scene.Clear ();
                        _scene.AddImage (0, float.MinValue, float.MaxValue, view.Rectangle, new byte[0], _canvasBitmap);

                        // switch cache and canvas to prevent re-allocation of bitmaps.
                        global::Android.Graphics.Bitmap newCanvas = _cache;
                        _cache = _canvasBitmap;
                        _canvasBitmap = newCanvas;
                    }
                }

                this.PostInvalidate ();

                long after = DateTime.Now.Ticks;
            }
        }
Exemplo n.º 5
0
 static void n_OnDraw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
 {
     global::Com.Huawei.Android.Pushselfshow.Richpush.Html.PageProgressView __this = global::Java.Lang.Object.GetObject <global::Com.Huawei.Android.Pushselfshow.Richpush.Html.PageProgressView> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas p0 = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.OnDraw(p0);
 }
Exemplo n.º 6
0
 protected internal override bool DrawChild(global::Android.Graphics.Canvas canvas, global::Android.View.View child, long drawingTime)                         /* MethodBuilder.Create */
 {
     return(default(bool));
 }
Exemplo n.º 7
0
 public abstract void DrawLegendShape(global::Android.Graphics.Canvas p0, global::Org.Achartengine.Renderer.SimpleSeriesRenderer p1, float p2, float p3, int p4, global::Android.Graphics.Paint p5);
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
 {
     global::Com.Nostra13.Universalimageloader.Core.Display.RoundedBitmapDisplayer.RoundedDrawable __this = global::Java.Lang.Object.GetObject <global::Com.Nostra13.Universalimageloader.Core.Display.RoundedBitmapDisplayer.RoundedDrawable> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas p0 = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.Draw(p0);
 }
        public override void Draw(global::Android.Graphics.Canvas canvas)
        {
            //
            // Start drawing
            //
            var del = Content;

            if (del == null)
            {
                return;
            }

            var startT = DateTime.Now;

            var _graphics = new AndroidGraphics(canvas);

            _graphics.SaveState();
            _graphics.Scale(Zoom, Zoom);


            //
            // Draw
            //
            del.Frame = new RectangleF(0, 0, Width / Zoom, Height / Zoom);
            try {
                del.Draw(_graphics);
            }
            catch (Exception) {
            }

            _graphics.RestoreState();

            var endT = DateTime.Now;

            _drawTime += (endT - startT).TotalSeconds;
            _drawCount++;

            //
            // Throttle
            //
            if (_running && _drawCount > 2 && (DateTime.Now - _lastThrottleTime) >= ThrottleInterval)
            {
                _lastThrottleTime = DateTime.Now;

                var maxfps = 1.0 / (_drawTime / _drawCount);
                _drawTime  = 0;
                _drawCount = 0;

                var fps = ClampUpdateFreq((int)(maxfps * CpuUtilization));

                if (Math.Abs(fps - _fps) > 1)
                {
                    _fps = fps;
                    Start();
                }
            }

            //
            // Notify
            //
            var df = DrewFrame;

            if (df != null)
            {
                df(this, EventArgs.Empty);
            }

            if (_running)
            {
                _handler.PostDelayed(HandleDrawTimerElapsed, 1000 / _fps);
            }
        }
Exemplo n.º 10
0
 static void n_DrawSel_Landroid_graphics_Canvas_FFII(IntPtr jnienv, IntPtr native__this, IntPtr native_p0, float p1, float p2, int p3, int p4)
 {
     global::Com.Radaee.View.VSel    __this = global::Java.Lang.Object.GetObject <global::Com.Radaee.View.VSel> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas p0     = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.DrawSel(p0, p1, p2, p3, p4);
 }
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
 {
     global::Com.Android.Camera.HighlightView __this = global::Java.Lang.Object.GetObject <global::Com.Android.Camera.HighlightView> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas          p0     = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.Draw(p0);
 }
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
 {
     global::Com.Bumptech.Glide.Load.Resource.Bitmap.GlideBitmapDrawable __this = global::Java.Lang.Object.GetObject <global::Com.Bumptech.Glide.Load.Resource.Bitmap.GlideBitmapDrawable> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas p0 = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.Draw(p0);
 }
Exemplo n.º 13
0
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0)
 {
     global::Org.Adw.Library.Widgets.Discreteseekbar.Internal.Drawable.StateDrawable __this = global::Java.Lang.Object.GetObject <global::Org.Adw.Library.Widgets.Discreteseekbar.Internal.Drawable.StateDrawable> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas p0 = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_p0, JniHandleOwnership.DoNotTransfer);
     __this.Draw(p0);
 }
Exemplo n.º 14
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            Android.Graphics.LinearGradient gradient;
            Colors = new List <Color>();
            Colors.Add(FirstColor);
            Colors.Add(SecoundColor);
            Colors.Add(ThirdColor);

            int[] colors = new int[3];

            for (int i = 0, l = 3; i < l; i++)
            {
                colors[i] = Colors[i].ToAndroid().ToArgb();
            }

            switch (Mode)
            {
            default:
            case GradientColorStackMode.ToRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTop:
                gradient = new Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottom:
                gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopLeft:
                gradient = new Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopRight:
                gradient = new Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
Exemplo n.º 15
0
 static void n_DrawBar_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_barCanvas)
 {
     global::Com.Flask.Colorpicker.Slider.AlphaSlider __this = global::Java.Lang.Object.GetObject <global::Com.Flask.Colorpicker.Slider.AlphaSlider> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas barCanvas = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_barCanvas, JniHandleOwnership.DoNotTransfer);
     __this.DrawBar(barCanvas);
 }
 protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
 {
     base.DispatchDraw(canvas);
     SetTabIcons();
 }
Exemplo n.º 17
0
 static void n_DrawHandle_Landroid_graphics_Canvas_FF(IntPtr jnienv, IntPtr native__this, IntPtr native_canvas, float x, float y)
 {
     global::Com.Flask.Colorpicker.Slider.AlphaSlider __this = global::Java.Lang.Object.GetObject <global::Com.Flask.Colorpicker.Slider.AlphaSlider> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas canvas = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_canvas, JniHandleOwnership.DoNotTransfer);
     __this.DrawHandle(canvas, x, y);
 }
 static void n_Draw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_c)
 {
     global::Com.Lsjwzh.Widget.Materialloadingprogressbar.MaterialProgressDrawable __this = global::Java.Lang.Object.GetObject <global::Com.Lsjwzh.Widget.Materialloadingprogressbar.MaterialProgressDrawable> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
     global::Android.Graphics.Canvas c = global::Java.Lang.Object.GetObject <global::Android.Graphics.Canvas> (native_c, JniHandleOwnership.DoNotTransfer);
     __this.Draw(c);
 }
Exemplo n.º 19
0
        protected virtual void DrawBackground(global::Org.Achartengine.Renderer.DefaultRenderer p0, global::Android.Graphics.Canvas p1, int p2, int p3, int p4, int p5, global::Android.Graphics.Paint p6, bool p7, int p8)
        {
            if (id_drawBackground_Lorg_achartengine_renderer_DefaultRenderer_Landroid_graphics_Canvas_IIIILandroid_graphics_Paint_ZI == IntPtr.Zero)
            {
                id_drawBackground_Lorg_achartengine_renderer_DefaultRenderer_Landroid_graphics_Canvas_IIIILandroid_graphics_Paint_ZI = JNIEnv.GetMethodID(class_ref, "drawBackground", "(Lorg/achartengine/renderer/DefaultRenderer;Landroid/graphics/Canvas;IIIILandroid/graphics/Paint;ZI)V");
            }

            if (GetType() == ThresholdType)
            {
                JNIEnv.CallVoidMethod(Handle, id_drawBackground_Lorg_achartengine_renderer_DefaultRenderer_Landroid_graphics_Canvas_IIIILandroid_graphics_Paint_ZI, new JValue(p0), new JValue(p1), new JValue(p2), new JValue(p3), new JValue(p4), new JValue(p5), new JValue(p6), new JValue(p7), new JValue(p8));
            }
            else
            {
                JNIEnv.CallNonvirtualVoidMethod(Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "drawBackground", "(Lorg/achartengine/renderer/DefaultRenderer;Landroid/graphics/Canvas;IIIILandroid/graphics/Paint;ZI)V"), new JValue(p0), new JValue(p1), new JValue(p2), new JValue(p3), new JValue(p4), new JValue(p5), new JValue(p6), new JValue(p7), new JValue(p8));
            }
        }
        public virtual unsafe void DrawHeader(global::Android.Support.V7.Widget.RecyclerView p0, global::Android.Graphics.Canvas p1, global::Android.Views.View p2, global::Android.Graphics.Rect p3)
        {
            if (id_drawHeader_Landroid_support_v7_widget_RecyclerView_Landroid_graphics_Canvas_Landroid_view_View_Landroid_graphics_Rect_ == IntPtr.Zero)
            {
                id_drawHeader_Landroid_support_v7_widget_RecyclerView_Landroid_graphics_Canvas_Landroid_view_View_Landroid_graphics_Rect_ = JNIEnv.GetMethodID(class_ref, "drawHeader", "(Landroid/support/v7/widget/RecyclerView;Landroid/graphics/Canvas;Landroid/view/View;Landroid/graphics/Rect;)V");
            }
            try {
                JValue *__args = stackalloc JValue [4];
                __args [0] = new JValue(p0);
                __args [1] = new JValue(p1);
                __args [2] = new JValue(p2);
                __args [3] = new JValue(p3);

                if (((object)this).GetType() == ThresholdType)
                {
                    JNIEnv.CallVoidMethod(((global::Java.Lang.Object) this).Handle, id_drawHeader_Landroid_support_v7_widget_RecyclerView_Landroid_graphics_Canvas_Landroid_view_View_Landroid_graphics_Rect_, __args);
                }
                else
                {
                    JNIEnv.CallNonvirtualVoidMethod(((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "drawHeader", "(Landroid/support/v7/widget/RecyclerView;Landroid/graphics/Canvas;Landroid/view/View;Landroid/graphics/Rect;)V"), __args);
                }
            } finally {
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Renders the current complete scene.
        /// </summary>
        private void Render()
        {
            if (_cacheRenderer.IsRunning) {
                _cacheRenderer.CancelAndWait ();
            }

            // make sure only on thread at the same time is using the renderer.
            lock (_cacheRenderer)
            {
                this.Map.ViewChangedCancel();

                // build the layers list.
                var layers = new List<Layer> ();
                for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++) {
                    // get the layer.
                    layers.Add (this.Map[layerIdx]);
                }

                // add the internal layers.
                layers.Add (_makerLayer);

                // get old image if available.
                global::Android.Graphics.Bitmap image = null;
                if (_offScreenBuffer != null)
                {
                    image = _offScreenBuffer.Tag as global::Android.Graphics.Bitmap;
                }

                if (this.SurfaceHeight == 0)
                {
                    return;
                }

                // resize image if needed.
                float size = System.Math.Max(this.SurfaceHeight, this.SurfaceWidth);
                if (image == null ||
                    image.Width != (int)(size * _extra) ||
                    image.Height != (int)(size * _extra))
                { // create a bitmap and render there.
                    image = global::Android.Graphics.Bitmap.CreateBitmap((int)(size * _extra),
                        (int)(size * _extra),
                        global::Android.Graphics.Bitmap.Config.Argb8888);
                }

                // create and reset the canvas.
                global::Android.Graphics.Canvas canvas = new global::Android.Graphics.Canvas (image);
                canvas.DrawColor (new global::Android.Graphics.Color(
                    SimpleColor.FromKnownColor(KnownColor.White).Value));

                // create the view.
                double[] sceneCenter = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                float mapZoom = this.MapZoom;
                float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                // create the view for this control.
                View2D view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                         size * _extra, size * _extra, sceneZoomFactor,
                                         _invertX, _invertY, this.MapTilt);

                long before = DateTime.Now.Ticks;

                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                "Rendering Start");

                // notify the map that the view has changed.
                this.Map.ViewChanged ((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                      view);
                long afterViewChanged = DateTime.Now.Ticks;
                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                "View change took: {0}ms @ zoom level {1}",
                                                (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                // does the rendering.
                bool complete = _cacheRenderer.Render(canvas, layers, view, (float)this.Map.Projection.ToZoomFactor(this.MapZoom));

                long afterRendering = DateTime.Now.Ticks;
                OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                "Rendering took: {0}ms @ zoom level {1}",
                                                (new TimeSpan(afterRendering - afterViewChanged).TotalMilliseconds), this.MapZoom);
                if(complete)
                { // there was no cancellation, the rendering completely finished.
                    // add the result to the scene cache.

                    // add the newly rendered image again.
                    _offScreenBuffer = new ImageTilted2D(view.Rectangle, new byte[0], float.MinValue, float.MaxValue);
                    _offScreenBuffer.Tag = image;

                    var temp = _onScreenBuffer;
                    _onScreenBuffer = _offScreenBuffer;
                    _offScreenBuffer = temp;
                }

                // notify the the current surface of the new rendering.
                this.PostInvalidate();

                long after = DateTime.Now.Ticks;

                if (complete)
                { // report a successfull render to listener.
                    _listener.NotifyRenderSuccess(view, mapZoom, (int)new TimeSpan(after - before).TotalMilliseconds);
                }
            }
        }
 public override void Draw(global::Android.Graphics.Canvas canvas, global::Android.Graphics.Paint paint)                         /* MethodBuilder.Create */
 {
 }
Exemplo n.º 23
0
        /// <summary>
        /// Renders the current complete scene.
        /// </summary>
        private void Render()
        {
            try
            {
                if (_renderingSuspended)
                { // no rendering when rendering is suspended.
                    return;
                }

                if (_cacheRenderer.IsRunning)
                { // cancel previous render.
                    _cacheRenderer.CancelAndWait();
                }

                // make sure only on thread at the same time is using the renderer.
                lock (_cacheRenderer)
                {
                    this.Map.ViewChangedCancel();

                    // build the layers list.
                    var layers = new List<Layer>();
                    for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                    { // get the layer.
                        if (this.Map[layerIdx].IsVisible)
                        {
                            layers.Add(this.Map[layerIdx]);
                        }
                    }

                    // add the internal layers.
                    layers.Add(_makerLayer);

                    if (this.SurfaceHeight == 0)
                    { // the surface has no height yet. Impossible to render like this.
                        return;
                    }

                    // get old image if available.
                    NativeImage image = null;
                    if (_offScreenBuffer != null)
                    { // get the native image from the off-screen buffer.
                        image = _offScreenBuffer.NativeImage as NativeImage;
                    }

                    // resize image if needed.
                    float sizeX = this.SurfaceWidth;
                    float sizeY = this.SurfaceHeight;
                    //if(this.MapAllowTilt)
                    //{ // when rotation is allowed make sure a square is rendered.
                    //    sizeX = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //    sizeY = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //}
                    // float size = System.Math.Max(this.SurfaceHeight, this.SurfaceWidth);
                    if (image == null ||
                        image.Image.Width != (int)(sizeX * _extra) ||
                        image.Image.Height != (int)(sizeY * _extra))
                    { // create a bitmap and render there.
                        if (image != null)
                        { // make sure to dispose the old image.
                            image.Dispose();
                        }
                        image = new NativeImage(global::Android.Graphics.Bitmap.CreateBitmap((int)(sizeX * _extra),
                            (int)(sizeY * _extra),
                            global::Android.Graphics.Bitmap.Config.Argb8888));
                    }

                    // create and reset the canvas.
                    using (var canvas = new global::Android.Graphics.Canvas(image.Image))
                    {
                        canvas.DrawColor(new global::Android.Graphics.Color(
                            SimpleColor.FromKnownColor(KnownColor.White).Value));

                        // create the view.
                        double[] sceneCenter = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                        float mapZoom = this.MapZoom;
                        float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                        // create the view for this control.
                        float scaledNormalWidth = image.Image.Width / _bufferFactor;
                        float scaledNormalHeight = image.Image.Height / _bufferFactor;
                        var view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                                 scaledNormalWidth * _extra, scaledNormalHeight * _extra, sceneZoomFactor,
                                                 _invertX, _invertY, this.MapTilt);

                        long before = DateTime.Now.Ticks;

                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering Start");

                        // notify the map that the view has changed.
                        if (_previouslyChangedView == null ||
                            !_previouslyChangedView.Equals(view))
                        { // report change once!
                            var normalView = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                scaledNormalWidth, scaledNormalHeight, sceneZoomFactor,
                                _invertX, _invertY, this.MapTilt);
                            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                                  normalView, view);
                            _previouslyChangedView = view;
                            long afterViewChanged = DateTime.Now.Ticks;
                            OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                            "View change took: {0}ms @ zoom level {1}",
                                                            (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);
                        }

                        // does the rendering.
                        _cacheRenderer.Density = this.MapScaleFactor;
                        bool complete = _cacheRenderer.Render(canvas, _map.Projection, layers, view, (float)this.Map.Projection.ToZoomFactor(this.MapZoom));

                        long afterRendering = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering took: {0}ms @ zoom level {1} and {2}",
                                                        (new TimeSpan(afterRendering - before).TotalMilliseconds), this.MapZoom, this.MapCenter);
                        if (complete)
                        { // there was no cancellation, the rendering completely finished.
                            // add the result to the scene cache.
                            // add the newly rendered image again.
                            if (_offScreenBuffer == null)
                            { // create the offscreen buffer first.
                                _offScreenBuffer = new ImageTilted2D(view.Rectangle, image, float.MinValue, float.MaxValue);
                            }
                            else
                            { // augment the previous buffer.
                                _offScreenBuffer.Bounds = view.Rectangle;
                                _offScreenBuffer.NativeImage = image;
                            }

                            var temp = _onScreenBuffer;
                            _onScreenBuffer = _offScreenBuffer;
                            _offScreenBuffer = temp;
                        }

                        long after = DateTime.Now.Ticks;

                        if (complete)
                        { // report a successful render to listener.
                            _listener.NotifyRenderSuccess(view, mapZoom, (int)new TimeSpan(after - before).TotalMilliseconds);
                        }
                    }
                }

                // notify the the current surface of the new rendering.
                this.PostInvalidate();
            }
            catch (Exception ex)
            { // exceptions can be thrown when the mapview is disposed while rendering.
                // don't worry too much about these, the mapview is garbage anyway.
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical,
                    string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Renders the current complete scene.
        /// </summary>
        private void Render()
        {
            try
            {
                if (_renderingSuspended)
                { // no rendering when rendering is suspended.
                    return;
                }

                if (_cacheRenderer.IsRunning)
                { // cancel previous render.
                    _cacheRenderer.CancelAndWait();
                }

                // make sure only on thread at the same time is using the renderer.
                lock (_cacheRenderer)
                {
                    this.Map.ViewChangedCancel();

                    // build the layers list.
                    var layers = new List <Layer>();
                    for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                    { // get the layer.
                        if (this.Map[layerIdx].IsVisible)
                        {
                            layers.Add(this.Map[layerIdx]);
                        }
                    }

                    // add the internal layers.
                    layers.Add(_makerLayer);

                    if (this.SurfaceHeight == 0)
                    { // the surface has no height yet. Impossible to render like this.
                        return;
                    }

                    // get old image if available.
                    NativeImage image = null;
                    if (_offScreenBuffer != null)
                    { // get the native image from the off-screen buffer.
                        image = _offScreenBuffer.NativeImage as NativeImage;
                    }

                    // resize image if needed.
                    float sizeX = this.SurfaceWidth;
                    float sizeY = this.SurfaceHeight;
                    //if(this.MapAllowTilt)
                    //{ // when rotation is allowed make sure a square is rendered.
                    //    sizeX = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //    sizeY = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //}
                    // float size = System.Math.Max(this.SurfaceHeight, this.SurfaceWidth);
                    if (image == null ||
                        image.Image.Width != (int)(sizeX * _extra) ||
                        image.Image.Height != (int)(sizeY * _extra))
                    {     // create a bitmap and render there.
                        if (image != null)
                        { // make sure to dispose the old image.
                            image.Dispose();
                        }
                        image = new NativeImage(global::Android.Graphics.Bitmap.CreateBitmap((int)(sizeX * _extra),
                                                                                             (int)(sizeY * _extra),
                                                                                             global::Android.Graphics.Bitmap.Config.Argb8888));
                    }

                    // create and reset the canvas.
                    using (var canvas = new global::Android.Graphics.Canvas(image.Image))
                    {
                        canvas.DrawColor(new global::Android.Graphics.Color(
                                             SimpleColor.FromKnownColor(KnownColor.White).Value));

                        // create the view.
                        double[] sceneCenter     = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                        float    mapZoom         = this.MapZoom;
                        float    sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                        // create the view for this control.
                        float scaledNormalWidth  = image.Image.Width / _bufferFactor;
                        float scaledNormalHeight = image.Image.Height / _bufferFactor;
                        var   view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                                       scaledNormalWidth * _extra, scaledNormalHeight * _extra, sceneZoomFactor,
                                                       _invertX, _invertY, this.MapTilt);

                        long before = DateTime.Now.Ticks;

                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering Start");

                        // notify the map that the view has changed.
                        if (_previouslyChangedView == null ||
                            !_previouslyChangedView.Equals(view))
                        { // report change once!
                            var normalView = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                                               scaledNormalWidth, scaledNormalHeight, sceneZoomFactor,
                                                               _invertX, _invertY, this.MapTilt);
                            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                                 normalView, view);
                            _previouslyChangedView = view;
                            long afterViewChanged = DateTime.Now.Ticks;
                            OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                            "View change took: {0}ms @ zoom level {1}",
                                                            (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);
                        }

                        // does the rendering.
                        _cacheRenderer.Density = this.MapScaleFactor;
                        bool complete = _cacheRenderer.Render(canvas, _map.Projection, layers, view, (float)this.Map.Projection.ToZoomFactor(this.MapZoom));

                        long afterRendering = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering took: {0}ms @ zoom level {1} and {2}",
                                                        (new TimeSpan(afterRendering - before).TotalMilliseconds), this.MapZoom, this.MapCenter);
                        if (complete)
                        { // there was no cancellation, the rendering completely finished.
                            // add the result to the scene cache.
                            // add the newly rendered image again.
                            if (_offScreenBuffer == null)
                            { // create the offscreen buffer first.
                                _offScreenBuffer = new ImageTilted2D(view.Rectangle, image, float.MinValue, float.MaxValue);
                            }
                            else
                            { // augment the previous buffer.
                                _offScreenBuffer.Bounds      = view.Rectangle;
                                _offScreenBuffer.NativeImage = image;
                            }

                            var temp = _onScreenBuffer;
                            _onScreenBuffer  = _offScreenBuffer;
                            _offScreenBuffer = temp;
                        }

                        long after = DateTime.Now.Ticks;

                        if (complete)
                        { // report a successful render to listener.
                            _listener.NotifyRenderSuccess(view, mapZoom, (int)new TimeSpan(after - before).TotalMilliseconds);
                        }
                    }
                }

                // notify the the current surface of the new rendering.
                this.PostInvalidate();
            }
            catch (Exception ex)
            { // exceptions can be thrown when the mapview is disposed while rendering.
                // don't worry too much about these, the mapview is garbage anyway.
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
        }