Hi friends,
    I am using SurfaceView to render a image buffer.
    The image buffer is generated by a interval timer,  what I need to
do is to show the image data in phone.

    Surface can finish this work,  the following is my steps to show
the image.

    in java layer, create a view, which will driver from SurfaceView,
and get the created surface, set the type as
SURFACE_TYPE_PUSH_BUFFERS, pass the surface to JNI.

    then register two buffer to this surface,  when the data is
coming, will copy the image data to the framebuffer and do postBuffer.

    I am puzzled, sometimes it works fine, sometimes no image show.

static void android_media_Player_setSurface(JNIEnv *env, jobject thiz)
{

    jobject surface = env->GetObjectField(thiz, fields.surface);
    sp<ISurface> iSurface=NULL;
    if (surface != NULL)
    {
        const sp<Surface>& native_surface = get_surface(env, surface);
        iSurface = native_surface->getISurface();
        if (iSurface == m_iSurface) {
            return;
        }
        m_iSurface.clear();
        m_frameHeap.clear();
    }
    m_iSurface = iSurface;

    if (m_iSurface.get())
    {
        //RGB-565 frames are 2 bytes/pixel
        const sp<Surface>& native_surface = get_surface(env, surface);
        int x=0; int y=0; int w=0; int h=0; int freeze=0;
        m_iSurface->getSurfaceInformation(x, y, w, h, freeze);

        m_heigh = h;
        m_width = w;

        //double buffer
        int frameSize = w * h * 2 * 2;
        m_frameHeap = new android::MemoryHeapBase(frameSize);
        if (m_frameHeap->heapID() < 0) {
            return;
        }

        android::ISurface::BufferHeap buffers(w, h, w, h,
android::PIXEL_FORMAT_RGB_565, m_frameHeap);
        android::status_t ret = m_iSurface->registerBuffers(buffers);

        m_frameBufferOffset = 0;
    }
}

Here is to postBuffers, called by image generation program, we just
copy the whole region
void postBuffer(unsigned char * idata, int offset, int iLen)
{
    if(m_iSurface.get())
    {
        unsigned char* frameAddr = static_cast<unsigned char*>
(m_frameHeap->base());
        if(frameAddr != NULL)
        {
                if(m_frameBufferOffset == 0)
                {
                    m_frameBufferOffset = m_width * m_heigh*2;
                }
                else
                {
                    m_frameBufferOffset = 0;
                }
                memcpy(frameAddr + m_frameBufferOffset, idata-offset,
m_width * m_heigh * 2);

                m_iSurface->postBuffer(m_frameBufferOffset);
        }
    }
}


Thanks
Huadong

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to