Skip to content

Commit

Permalink
This is initial API support required for enabling SurfaceTexture back…
Browse files Browse the repository at this point in the history
…ed zero-copy for Android

BUG=269808

Review URL: https://codereview.chromium.org/191933002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256604 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sohan.jyoti@samsung.com committed Mar 12, 2014
1 parent 0939e16 commit 89f6fb9
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
gl_decoder_->RestoreTextureUnitBindings(0);
gl_decoder_->RestoreActiveTexture();

surface_texture_ = new gfx::SurfaceTexture(surface_texture_id_);
surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_);

if (!ConfigureMediaCodec()) {
LOG(ERROR) << "Failed to create MediaCodec instance.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AndroidVideoDecodeAcceleratorTest : public testing::Test {
bool Configure(media::VideoCodec codec) {
AndroidVideoDecodeAccelerator* accelerator =
static_cast<AndroidVideoDecodeAccelerator*>(accelerator_.get());
accelerator->surface_texture_ = new gfx::SurfaceTexture(0);
accelerator->surface_texture_ = gfx::SurfaceTexture::Create(0);
accelerator->codec_ = codec;
return accelerator->ConfigureMediaCodec();
}
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/stream_texture_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int32 StreamTexture::Create(
StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
int32 route_id,
uint32 texture_id)
: surface_texture_(new gfx::SurfaceTexture(texture_id)),
: surface_texture_(gfx::SurfaceTexture::Create(texture_id)),
size_(0, 0),
has_valid_frame_(false),
has_pending_frame_(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ GLuint StreamTextureManagerInProcess::CreateStreamTexture(
}

scoped_refptr<gfx::SurfaceTexture> surface_texture(
new gfx::SurfaceTexture(texture->service_id()));
gfx::SurfaceTexture::Create(texture->service_id()));

uint32 stream_id = next_id_++;
base::Closure release_callback =
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/tests/gl_unittests_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST_F(GLSurfaceTextureTest, SimpleTest) {
GLuint texture = 0xFEEDBEEF;

scoped_refptr<gfx::SurfaceTexture> surface_texture(
new gfx::SurfaceTexture(texture));
gfx::SurfaceTexture::Create(texture));
gfx::AcceleratedWidget window = surface_texture->CreateSurface();
EXPECT_TRUE(window != NULL);

Expand Down
6 changes: 3 additions & 3 deletions media/base/android/media_source_player_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ class MediaSourcePlayerTest : public testing::Test {
void CreateNextTextureAndSetVideoSurface() {
gfx::SurfaceTexture* surface_texture;
if (surface_texture_a_is_next_) {
surface_texture_a_ = new gfx::SurfaceTexture(next_texture_id_++);
surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++);
surface_texture = surface_texture_a_.get();
} else {
surface_texture_b_ = new gfx::SurfaceTexture(next_texture_id_++);
surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++);
surface_texture = surface_texture_b_.get();
}

Expand Down Expand Up @@ -803,7 +803,7 @@ TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {

// Test video decoder job will not be created when surface is invalid.
scoped_refptr<gfx::SurfaceTexture> surface_texture(
new gfx::SurfaceTexture(0));
gfx::SurfaceTexture::Create(0));
gfx::ScopedJavaSurface surface(surface_texture.get());
StartVideoDecoderJob(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ private static SurfaceTexture create(int textureId) {
return new SurfaceTexture(textureId);
}

@CalledByNative
private static SurfaceTexture createSingleBuffered(int textureId) {
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
return new SurfaceTexture(textureId, true);
}

@CalledByNative
private static void destroy(SurfaceTexture surfaceTexture) {
surfaceTexture.setOnFrameAvailableListener(null);
Expand All @@ -47,6 +53,12 @@ private static void updateTexImage(SurfaceTexture surfaceTexture) {
}
}

@CalledByNative
private static void releaseTexImage(SurfaceTexture surfaceTexture) {
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
surfaceTexture.releaseTexImage();
}

@CalledByNative
private static void setDefaultBufferSize(SurfaceTexture surfaceTexture, int width,
int height) {
Expand Down
28 changes: 26 additions & 2 deletions ui/gl/android/surface_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ bool GlContextMethodsAvailable() {

namespace gfx {

SurfaceTexture::SurfaceTexture(int texture_id) {
scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) {
JNIEnv* env = base::android::AttachCurrentThread();
j_surface_texture_.Reset(
return new SurfaceTexture(
Java_SurfaceTexturePlatformWrapper_create(env, texture_id));
}

scoped_refptr<SurfaceTexture> SurfaceTexture::CreateSingleBuffered(
int texture_id) {
DCHECK(IsSingleBufferModeSupported());
JNIEnv* env = base::android::AttachCurrentThread();
return new SurfaceTexture(
Java_SurfaceTexturePlatformWrapper_createSingleBuffered(env, texture_id));
}

SurfaceTexture::SurfaceTexture(
const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) {
j_surface_texture_.Reset(j_surface_texture);
}

SurfaceTexture::~SurfaceTexture() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj());
Expand All @@ -52,6 +65,13 @@ void SurfaceTexture::UpdateTexImage() {
j_surface_texture_.obj());
}

void SurfaceTexture::ReleaseTexImage() {
DCHECK(IsSingleBufferModeSupported());
JNIEnv* env = base::android::AttachCurrentThread();
Java_SurfaceTexturePlatformWrapper_releaseTexImage(env,
j_surface_texture_.obj());
}

void SurfaceTexture::GetTransformMatrix(float mtx[16]) {
JNIEnv* env = base::android::AttachCurrentThread();

Expand Down Expand Up @@ -109,6 +129,10 @@ ANativeWindow* SurfaceTexture::CreateSurface() {
}

// static
bool SurfaceTexture::IsSingleBufferModeSupported() {
return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
}

bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) {
return RegisterNativesImpl(env);
}
Expand Down
19 changes: 18 additions & 1 deletion ui/gl/android/surface_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ namespace gfx {
class GL_EXPORT SurfaceTexture
: public base::RefCountedThreadSafe<SurfaceTexture>{
public:
explicit SurfaceTexture(int texture_id);
static scoped_refptr<SurfaceTexture> Create(int texture_id);

static scoped_refptr<SurfaceTexture> CreateSingleBuffered(int texture_id);

// Set the listener callback, which will be invoked on the same thread that
// is being called from here for registration.
Expand All @@ -33,6 +35,13 @@ class GL_EXPORT SurfaceTexture
// Update the texture image to the most recent frame from the image stream.
void UpdateTexImage();

// Release the texture content. This is needed only in single buffered mode
// to allow the image content producer to take ownership
// of the image buffer.
// This is *only* supported on SurfaceTexture instantiated via
// |CreateSingleBuffered(...)|.
void ReleaseTexImage();

// Retrieve the 4x4 texture coordinate transform matrix associated with the
// texture image set by the most recent call to updateTexImage.
void GetTransformMatrix(float mtx[16]);
Expand All @@ -57,8 +66,16 @@ class GL_EXPORT SurfaceTexture
return j_surface_texture_;
}

// This should only be used to guard the SurfaceTexture instantiated via
// |CreateSingleBuffered(...)|
static bool IsSingleBufferModeSupported();

static bool RegisterSurfaceTexture(JNIEnv* env);

protected:
explicit SurfaceTexture(
const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture);

private:
friend class base::RefCountedThreadSafe<SurfaceTexture>;
~SurfaceTexture();
Expand Down

0 comments on commit 89f6fb9

Please sign in to comment.