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

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, 6 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..1690fede9702c07a4559804546c3ad256e24a359 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,42 +21,26 @@ 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::Create(GpuCommandBufferStub* owner_stub,
+ int32 image_id,
+ int32 stream_id) {
GLES2Decoder* decoder = owner_stub->decoder();
- TextureManager* texture_manager =
- decoder->GetContextGroup()->texture_manager();
- TextureRef* texture = texture_manager->GetTexture(client_texture_id);
-
- if (texture && (!texture->texture()->target() ||
- texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) {
-
- // TODO: Ideally a valid image id was returned to the client so that
- // it could then call glBindTexImage2D() for doing the following.
- scoped_refptr<gfx::GLImage> gl_image(
- new StreamTexture(owner_stub, stream_id, texture->service_id()));
- gfx::Size size = gl_image->GetSize();
- texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
- texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
- size.width(), size.height(), 1, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, gfx::Rect(size));
- texture_manager->SetLevelImage(
- texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get());
- return true;
- }
-
- return false;
+ ImageManager* image_manager = decoder->GetImageManager();
+ DCHECK(decoder);
+ DCHECK(image_manager);
+ image_manager->AddImage(new StreamTexture(owner_stub, stream_id, 0),
+ image_id);
+ return true;
}
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 +48,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 +177,44 @@ 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) {
+ LOG(ERROR) << "Surface texture can only be bound to one texture ID";
+ return false;
+ }
+
+ if (texture_id != texture_id_) {
piman 2015/06/30 23:04:20 nit: this is really if (!texture_id_) because of t
sivag 2015/07/16 14:24:58 Done.
+ // 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.
+ DCHECK_EQ(0, texture_id_);
+ surface_texture_->DetachFromGLContext();
+ // This will attach the surface texture to the texture currently bound to
+ // GL_TEXTURE_EXTERNAL_OES target.
+ surface_texture_->AttachToGLContext();
+ texture_id_ = texture_id;
+ }
+
+ surface_texture_->UpdateTexImage();
+ return true;
}
void StreamTexture::ReleaseTexImage(unsigned target) {

Powered by Google App Engine
This is Rietveld 408576698