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

Unified Diff: gpu/ipc/service/stream_texture_android.cc

Issue 1129943006: Implement StreamTexture::BindTexImage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « gpu/ipc/service/stream_texture_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/ipc/service/stream_texture_android.cc
diff --git a/gpu/ipc/service/stream_texture_android.cc b/gpu/ipc/service/stream_texture_android.cc
index 5754ec8f6fc8580579272d4d660db177ad068a4b..fb77e4a8214dfb4f42ea6e4c724667039135d531 100644
--- a/gpu/ipc/service/stream_texture_android.cc
+++ b/gpu/ipc/service/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 "gpu/ipc/common/android/surface_texture_peer.h"
#include "gpu/ipc/common/gpu_messages.h"
@@ -25,42 +26,28 @@ namespace gpu {
using gles2::ContextGroup;
using gles2::GLES2Decoder;
+using gpu::gles2::ImageManager;
using gles2::TextureManager;
using gles2::TextureRef;
// static
bool StreamTexture::Create(GpuCommandBufferStub* owner_stub,
- uint32_t client_texture_id,
+ int32_t image_id,
int stream_id) {
+ DCHECK(owner_stub);
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<gpu::gles2::GLStreamTextureImage> 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->SetLevelStreamTextureImage(
- texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get(),
- gles2::Texture::UNBOUND, 0);
- return true;
- }
-
- return false;
+ 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;
}
StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
int32_t route_id,
- uint32_t texture_id)
+ int32_t texture_id)
: surface_texture_(gl::SurfaceTexture::Create(texture_id)),
size_(0, 0),
has_pending_frame_(false),
@@ -184,7 +171,7 @@ bool StreamTexture::CopyTexImage(unsigned target) {
// On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as
// glGetIntegerv() parameter. In this case the value of |texture_id| will be
// zero and we assume that it is properly bound to |texture_id_|.
- if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_)
+ if (texture_id > 0 && texture_id != texture_id_)
return false;
UpdateTexImage();
@@ -249,8 +236,47 @@ void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t 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;
+ }
+
+ DCHECK(surface_texture_.get());
+ if (texture_id != texture_id_) {
+ // 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) {
« no previous file with comments | « gpu/ipc/service/stream_texture_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698