Android in Rssurfaceview

Source: Internet
Author: User

Rssurfaceview directly inherits from Surfaceview, and implements the Surfaceholder.callback callback interface. The parsing is as follows:

1. Construction Method 1

Public Rssurfaceview (Context context) {        super (context);        Init ();        LOG.V (Renderscript.log_tag, "Rssurfaceview");    }

2. Construction Method 2

    Public Rssurfaceview (context context, AttributeSet Attrs) {        Super (context, attrs);        Init ();        LOG.V (Renderscript.log_tag, "Rssurfaceview");    }


3. Initialize: Increase the callback so that you can be notified when surface is created and destroyed.

    private void Init () {        //Install a surfaceholder.callback so we get notified if the        //underlying surface is CRE Ated and destroyed        surfaceholder holder = Getholder ();        Holder.addcallback (this);    }

4. Callback at creation time

public void surfacecreated (Surfaceholder holder) {        msurfaceholder = holder;    }


5. Callback at the time of destruction

    public void surfacedestroyed (Surfaceholder holder) {        synchronized (this) {            //Surface would be destroyed when we r Eturn            if (MRS! = null) {                mrs.setsurface (null, 0, 0)            ;        }    }}

6. Callback When changing

    public void surfacechanged (surfaceholder holder, int format, int w, int. h) {        synchronized (this) {            if (MRS! = null {                mrs.setsurface (holder, W, h);}}}    


7, pause: Notify the View the current activity has been paused, when the activity is paused must call the modification method, call this method will pause the render thread, must be in the renderer after the settings to be called.

  public void Pause () {        if (MRS! = null) {            mrs.pause ();        }    }

8, Recovery: Notify this view the current activity has been restored, when activity recovery must call this method to recreate the OpenGL display, and restore the render thread, must be set after the renderer to be called.

  public void Resume () {        if (MRS! = null) {            mrs.resume ();        }    }


9. Create RENDERSCRIPTGL

Public RENDERSCRIPTGL CREATERENDERSCRIPTGL (Renderscriptgl.surfaceconfig SC) {      RENDERSCRIPTGL rs = new RENDERSCRIPTGL (This.getcontext (), SC);        SETRENDERSCRIPTGL (RS);        return RS;    }


10, destroy the current RENDERSCRIPTGL

  public void Destroyrenderscriptgl () {        synchronized (this) {            Mrs.destroy ();            MRS = null;        }    }

11. Set RENDERSCRIPTGL

public void Setrenderscriptgl (RENDERSCRIPTGL rs) {        MRS = rs;    }

12. Get the current RENDERSCRIPTGL

    Public RENDERSCRIPTGL GETRENDERSCRIPTGL () {        return mRS;    }


Attached source code:

Package Android.renderscript;import Java.io.writer;import Java.util.arraylist;import Java.util.concurrent.semaphore;import Android.content.context;import Android.os.handler;import Android.os.Message ; Import Android.util.attributeset;import Android.util.log;import Android.view.surface;import Android.view.surfaceholder;import android.view.surfaceview;/** * @deprecated in API + * The Surface view for a graphics R Enderscript (RENDERSCRIPTGL) to draw on. * * <div class= "Special Reference" > * 





Android in Rssurfaceview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.