Hi,

Thanks Romain! I tried overriding this method and managed to get the
results I wanted.

Just thought that I'd post how I did it. Perhaps it helps someone, or
perhaps someone has pointers on how to do it cleaner:

I overrode invalidateChildInParent(), storing the dirty region in a
member variable.
invalidateChildInParent() gets called directly when any of my child
views does invalidate(). Here I post a job to draw myself, with the
texture's Canvas (A Canvas to a Bitmap). Then I return null to ensure
that nobody else gets the call - that way nobody thinks they need to
be redrawn because they overlap this view.

    @Override
    public ViewParent invalidateChildInParent(int[] location, Rect
dirty) {
        mDirty.set(dirty);
        post(mDrawRunnable);
        return null;
    }

    mDrawRunnable = new Runnable() {
        @Override
        public void run() {
            draw(mTextureCanvas);
        }
    };

Then in the draw() method (and also in the dispatchDraw() method) I
set thecanvas clip to my dirty region. I clear the dirty region of the
Canvas if it is not opaque. And then I call super.draw(mTextureCanvas)
to draw the view to the texture, uploading it to GL.
Under ICS I rather lock the Canvas of a SurfaceTexture's Surface, and
draw on that instead, avoiding the constant texture uploads to GL.

    @Override
    public void draw(Canvas textureCanvas) {
        textureCanvas.clipRect(mDirty);
        if (!textureCanvas.isOpaque()) {
            textureCanvas.drawColor(0x00000000,
PorterDuff.Mode.CLEAR);
        }
        super.draw(textureCanvas);
        uploadTextureToOpenGL();
    }

The fastest solution under ICS should of course be to enable HW
acceleration of Views and to steal their OpenGL textures instead of
drawing them to a SurfaceTexture, but I haven't looked in to that.



On Apr 7, 5:27 pm, Romain Guy <romain...@android.com> wrote:
> Hi,
>
> You can try to override ViewGroup.invalidateChildInParentto achieve
> what you want (return null immediately.) You should know however that
> the UI toolkit was never designed in such a way and that you will
> likely run into other issues.
>
>
>
>
>
>
>
>
>
> On Sat, Apr 7, 2012 at 4:06 AM, hanni <hann...@gmail.com> wrote:
> > Hi all,
>
> > I'm making an app that has standard Android Views on OpenGL ES
> > textures, allowing them to be rendered on any 3D mesh. I have
> > everything working, like touch and correct View invalidates. The way
> > I'm doing it is putting all the Android Views that are supposed to
> > rendered to textures in my root content view, along with the actual GL
> > Surface View. All the Android views have overridden draw methods, that
> > draw to a texture matching the View's size, instead of the screen. I
> > call those views the off-screen View hierarchy.
>
> > My problem is, every View in the off-screen View hierarchy is
> > positioned at the same coordinate (0, 0), in order for it to be drawn
> > to the top left pixel of its own texture. This has the effect that
> > when a View; let's say a Button, is invalidated because the user
> > pressed it, all the other Views are also automatically invalidated.
> > This is because Android redraws all views which intersect with an
> > invalidated View, and in the off-screen View hierarchy they are all
> > positioned at (0, 0) and all overlapping. This is not what I want,
> > since all views are drawn to different textures and they are not
> > really overlapping on screen, just in the off-screen View hierarchy.
>
> > I really want to prevent Views in the off-screen View hierarchy from
> > invalidating each other but all the things I have tried already,
> > failed:
>
> > * I tried offsetting each View so that it does not overlap any other
> > View. Then I translate the canvas just before drawing to get the View
> > to be drawn on coordinate (0, 0) of the texture. The problem I face
> > with this method is that when I have many Views, so that some must be
> > offset to the extent that they are outside the "screen", they are not
> > rendered at all (Probably an optimization in the View framework, not
> > drawing Views outside the screen, but I need all Views to be drawn
> > when requested).
>
> > * I tried overriding all the different invalidate()-methods of View,
> > to prevent Views from invalidating each other. That doesn't help at
> > all, and it really looks like the method I should be overriding is
> > ViewGroup.invalidateChild(), which is final, and can't be overridden.
>
> > * I tried adding each off-screen View via addContentView() instead of
> > putting them all in a single View hierarchy, but they still invalidate
> > each other.
>
> > Does anyone with great knowledge of the View-framework have a solution
> > to this?
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Romain Guy
> Android framework engineer
> romain...@android.com

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

Reply via email to