Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
TextureView canvas drawing problems
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Conrad Chapman  
View profile  
 More options Oct 2 2012, 10:40 am
From: Conrad Chapman <chapman.con...@gmail.com>
Date: Tue, 2 Oct 2012 07:40:54 -0700 (PDT)
Local: Tues, Oct 2 2012 10:40 am
Subject: TextureView canvas drawing problems

Also asked in StackOverflow here
http://stackoverflow.com/questions/12688409/android-textureview-canva...

I have an app that used SurfaceView to draw dynamic 2D graphs. It worked ok
but transormations etc as we know are not supported. So I went to
TextureView. My old code used another class/thread to do the drawing via
the Surfaceholder.lockCanvas(); So I changed this to
TextureView.lockcanvas. When this runs the canvas is not accelerated (the
view is). It does not display initially but if I touch the screen it
displays??? The touch is handled by the main activity.

Obviously it works as it will display eventually but why doesn't it display
immediately?

The TextureView class implements SurfaceTextureListener as such below.
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
// TODO Auto-generated method stub
isRunning = true;
mySurface = surface;
mChart.setTextureSurface(surface);
mChart.setSurfaceSize(width, height);
mPaint.setColor(ZOOM_BUTTONS_COLOR);
//mySurface.setOnFrameAvailableListener(frameready);
 mChart.Redraw(true);
 }
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
// TODO Auto-generated method stub
isRunning = false;
return false;

}

this block below also workswhen manipluating the view later on (pan and
zoom)
  public void Render(Bitmap buffmap){
//mCanvas = null;
  post(new Runnable() {
public void run() {
invalidate();
mySurface.updateTexImage();

}
});

The drawing from the worker thread/class is
protected void RenderCanvas(){
//mCanvas = null;
Canvas c = null;
//synchronized (mCanvas) {
 //mCanvas = null;
try {
c = mChartView.lockCanvas(null);

synchronized (mCanvas) {
c.drawBitmap(buffBitmap, 0, 0, null);

}
} finally {

if (c != null) {
mChartView.unlockCanvasAndPost(c);
 }
}

mChartView.Render(null);

}

Can I work like this? Non-GL content in a TextureView?
Please help desperate for an answer.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Oct 3 2012, 6:04 pm
From: Romain Guy <romain...@android.com>
Date: Wed, 3 Oct 2012 15:01:34 -0700
Local: Wed, Oct 3 2012 6:01 pm
Subject: Re: [android-developers] TextureView canvas drawing problems
The problem is that you are calling updateTexImage() yourself. Do
*not* do this. You are interfering with TextureView, preventing it
from receiving the events that it uses to refresh the screen.

--
Romain Guy
Android framework engineer
romain...@android.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Oct 3 2012, 6:06 pm
From: Romain Guy <romain...@android.com>
Date: Wed, 3 Oct 2012 15:03:30 -0700
Local: Wed, Oct 3 2012 6:03 pm
Subject: Re: [android-developers] TextureView canvas drawing problems
Here is a fully working example of Canvas & TextureView:

http://pastebin.com/J4uDgrZ8

--
Romain Guy
Android framework engineer
romain...@android.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Conrad Chapman  
View profile  
 More options Oct 4 2012, 11:17 am
From: Conrad Chapman <chapman.con...@gmail.com>
Date: Thu, 4 Oct 2012 08:17:33 -0700 (PDT)
Local: Thurs, Oct 4 2012 11:17 am
Subject: Re: [android-developers] TextureView canvas drawing problems

Thank you so much Romain for your reply and example. I might be the only
real canvas textureview example on the net. It worked but not quite as you
said. It might be something to do with my class structure as this part of
the program does not have internal classes..
I will explain and show a little. Maybe my approach is bad or wrong I don't
know.
CLASSES
Main Activity
spawns
- CustomTextureView class extending TextureView
              -this spawns the worker thread (it does not extend thread but
just a worker class)

the TextureView constructor

public CustomTextureView (Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
setWillNotDraw(true);
setFocusableInTouchMode(true);
setFocusable(true);
setSurfaceTextureListener(this);

}

and the listener callback within this class
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
// TODO Auto-generated method stub
isRunning = true;
mSurface = surface;
mChart.setTextureSurface(surface);//mChart is the worker class/thread
mChart.setSurfaceSize(width, height);
mChart.Redraw(true);//this does all the canvas drawing on a bitmap for
buffering.
invalidate();//this is essential to make it display on 1st run..why?

}

The worker class spawned from the CustomTextureView and the critical void
protected void RenderCanvas(){
 final Canvas canvas = CustomTextureView .lockCanvas(null);
        try {
           canvas.drawBitmap(buffBitmap, 0, 0, null);
        } finally {
        CustomTextureView .unlockCanvasAndPost(canvas);
         mSurface.updateTexImage();
        }

}

So I do not work from the main activity and don't understand why I need to
call invalidate() in onSurfaceTextureAvailable for the 1st run to display
properly.

Romain Guy you said NOT to call updateTexImage but if I don't my 2d chart
does not update with the new buffBitmap when it is available.
this I definitely don't understand????

Anyway it works and thanks for putting me on the right track but am i still
doing some android bad?

C


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Conrad Chapman  
View profile  
 More options Oct 16 2012, 11:31 am
From: Conrad Chapman <chapman.con...@gmail.com>
Date: Tue, 16 Oct 2012 08:31:33 -0700 (PDT)
Local: Tues, Oct 16 2012 11:31 am
Subject: Re: [android-developers] TextureView canvas drawing problems

I looked at this more and Romain Guy unsurprisingly got it 100% right.
My code pasted here is wrong.
DO NOT add
setWillNotDraw(true); in the TextureView and
 mSurface.updateTexImage(); in the drawing thread.
They will mess it up!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
zhu hui  
View profile  
 More options Oct 22 2012, 2:41 am
From: zhu hui <h.zhu....@gmail.com>
Date: Sun, 21 Oct 2012 23:41:48 -0700 (PDT)
Local: Mon, Oct 22 2012 2:41 am
Subject: Re: [android-developers] TextureView canvas drawing problems

Hi All:

I have tried this sample, it works great. But when I change
lockCanvas(null) into lockCanvas(new Rect(x, y, x+20, y+20)), the example
starts to flicker.
It seems 'lockCanvas(Rect)' can not work well for TextureView or any other
reasons?

I am using Motorola XOOM with android 4.0.3.
Thanks for any help!

在 2012年10月4日星期四UTC+8上午6时06分00秒,Romain Guy (Google)写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic