Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: content/common/gpu/stream_texture_android.cc

Issue 1129943006: Implement StreamTexture::BindTexImage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/stream_texture_android.cc
diff --git a/content/common/gpu/stream_texture_android.cc b/content/common/gpu/stream_texture_android.cc
index ffc9e8686d2389ee77d6818ebd30de3aec992fa1..005cd2d3ccd4f4a6480f5b31494e42a8a2a5b45b 100644
--- a/content/common/gpu/stream_texture_android.cc
+++ b/content/common/gpu/stream_texture_android.cc
@@ -11,6 +11,7 @@
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/context_state.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
+#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_context.h"
@@ -20,14 +21,29 @@ namespace content {
using gpu::gles2::ContextGroup;
using gpu::gles2::GLES2Decoder;
+using gpu::gles2::ImageManager;
using gpu::gles2::TextureManager;
using gpu::gles2::TextureRef;
// static
-bool StreamTexture::Create(
- GpuCommandBufferStub* owner_stub,
- uint32 client_texture_id,
- int stream_id) {
+bool StreamTexture::CreateStreamTextureImage(GpuCommandBufferStub* owner_stub,
+ int32 image_id,
+ int32 stream_id) {
+ DCHECK(owner_stub);
+ GLES2Decoder* decoder = owner_stub->decoder();
+ DCHECK(decoder);
+ ImageManager* image_manager = decoder->GetImageManager();
+ DCHECK(image_manager);
+ scoped_refptr<StreamTexture> image(
+ new StreamTexture(owner_stub, stream_id, 0));
+ image_manager->AddImage(image.get(), image_id);
+ return true;
+}
+
+// static
+bool StreamTexture::CreateStreamTexture(GpuCommandBufferStub* owner_stub,
+ uint32 client_texture_id,
+ int stream_id) {
GLES2Decoder* decoder = owner_stub->decoder();
TextureManager* texture_manager =
decoder->GetContextGroup()->texture_manager();
@@ -55,7 +71,7 @@ bool StreamTexture::Create(
StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
int32 route_id,
- uint32 texture_id)
+ int32 texture_id)
: surface_texture_(gfx::SurfaceTexture::Create(texture_id)),
size_(0, 0),
has_valid_frame_(false),
@@ -63,6 +79,7 @@ StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
owner_stub_(owner_stub),
route_id_(route_id),
has_listener_(false),
+ texture_id_(texture_id),
weak_factory_(this) {
owner_stub->AddDestructionObserver(this);
memset(current_matrix_, 0, sizeof(current_matrix_));
@@ -191,8 +208,41 @@ void StreamTexture::OnEstablishPeer(int32 primary_id, int32 secondary_id) {
}
bool StreamTexture::BindTexImage(unsigned target) {
- NOTREACHED();
- return false;
+ TRACE_EVENT0("gpu", "StreamTexture::BindTexImage");
+ DCHECK(surface_texture_.get());
+ if (!owner_stub_ || !surface_texture_.get())
+ return false;
+
+ if (target != GL_TEXTURE_EXTERNAL_OES) {
+ LOG(ERROR)
+ << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
+ return false;
+ }
+
+ GLint texture_id;
+ glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
+ DCHECK(texture_id);
+ if (!texture_id_)
+ texture_id_ = texture_id;
+ if (texture_id_ && texture_id_ != texture_id) {
+ LOG(ERROR) << "Surface texture can only be bound to one texture ID";
+ return false;
+ }
+ // Note: Surface textures used as gpu memory buffers are created with an
+ // initial dummy texture id of 0. We need to call DetachFromGLContext() here
+ // to detach from the dummy texture before we can attach to a real texture
+ // id. DetachFromGLContext() will delete the texture for the current
+ // attachment point so it's important that this is never called when
+ // attached to a real texture id. Detaching from the dummy texture id should
+ // not cause any problems as the GL should silently ignore 0 when passed to
+ // glDeleteTextures.
+ surface_texture_->DetachFromGLContext();
+ // This will attach the surface texture to the texture currently bound to
+ // GL_TEXTURE_EXTERNAL_OES target.
+ surface_texture_->AttachToGLContext();
+
+ surface_texture_->UpdateTexImage();
+ return true;
}
void StreamTexture::ReleaseTexImage(unsigned target) {

Powered by Google App Engine
This is Rietveld 408576698