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

Side by Side Diff: content/common/gpu/media/android_copying_backing_strategy.cc

Issue 1639963002: AndroidVideoDecodeAccelerator can now render to a SurfaceView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/gpu/media/android_copying_backing_strategy.h" 5 #include "content/common/gpu/media/android_copying_backing_strategy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/common/gpu/media/avda_return_on_failure.h" 10 #include "content/common/gpu/media/avda_return_on_failure.h"
11 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 11 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
13 #include "media/base/limits.h" 13 #include "media/base/limits.h"
14 #include "media/video/picture.h" 14 #include "media/video/picture.h"
15 #include "ui/gl/android/surface_texture.h" 15 #include "ui/gl/android/surface_texture.h"
16 #include "ui/gl/gl_bindings.h" 16 #include "ui/gl/gl_bindings.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 20 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
21 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 21 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
22 0.0f, 0.0f, 0.0f, 1.0f}; 22 0.0f, 0.0f, 0.0f, 1.0f};
23 23
24 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy() 24 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy()
25 : state_provider_(nullptr), surface_texture_id_(0), media_codec_(nullptr) {} 25 : state_provider_(nullptr), surface_texture_id_(0), media_codec_(nullptr) {}
26 26
27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} 27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {}
28 28
29 void AndroidCopyingBackingStrategy::Initialize( 29 void AndroidCopyingBackingStrategy::Initialize(
30 AVDAStateProvider* state_provider) { 30 AVDAStateProvider* state_provider,
31 scoped_refptr<gfx::SurfaceTexture> surface_texture) {
32 DCHECK(surface_texture);
31 state_provider_ = state_provider; 33 state_provider_ = state_provider;
32 } 34 surface_texture_ = surface_texture;
33 35
34 void AndroidCopyingBackingStrategy::Cleanup( 36 // Create a texture and attach the SurfaceTexture to it.
35 bool have_context,
36 const AndroidVideoDecodeAccelerator::OutputBufferMap&) {
37 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
38 if (copier_)
39 copier_->Destroy();
40
41 if (surface_texture_id_ && have_context)
42 glDeleteTextures(1, &surface_texture_id_);
43 }
44
45 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const {
46 return GL_TEXTURE_2D;
47 }
48
49 scoped_refptr<gfx::SurfaceTexture>
50 AndroidCopyingBackingStrategy::CreateSurfaceTexture() {
51 glGenTextures(1, &surface_texture_id_); 37 glGenTextures(1, &surface_texture_id_);
52 glActiveTexture(GL_TEXTURE0); 38 glActiveTexture(GL_TEXTURE0);
53 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); 39 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_);
54 40
55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 41 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 42 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 43 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 44 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
45
46 surface_texture_->AttachToGLContext();
47
59 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); 48 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0);
60 state_provider_->GetGlDecoder()->RestoreActiveTexture(); 49 state_provider_->GetGlDecoder()->RestoreActiveTexture();
50 }
61 51
62 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); 52 void AndroidCopyingBackingStrategy::Cleanup(
53 bool have_context,
54 const AndroidVideoDecodeAccelerator::OutputBufferMap&) {
55 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
56 if (copier_)
57 copier_->Destroy();
63 58
64 return surface_texture_; 59 if (surface_texture_id_ && have_context)
60 glDeleteTextures(1, &surface_texture_id_);
61 }
62
63 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const {
64 return GL_TEXTURE_2D;
65 } 65 }
66 66
67 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( 67 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer(
68 int32_t codec_buf_index, 68 int32_t codec_buf_index,
69 const media::PictureBuffer& picture_buffer) { 69 const media::PictureBuffer& picture_buffer) {
70 // Make sure that the decoder is available. 70 // Make sure that the decoder is available.
71 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), 71 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(),
72 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); 72 "Failed to get gles2 decoder instance.", ILLEGAL_STATE);
73 73
74 // Render the codec buffer into |surface_texture_|, and switch it to be 74 // Render the codec buffer into |surface_texture_|, and switch it to be
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 134 }
135 135
136 void AndroidCopyingBackingStrategy::OnFrameAvailable() { 136 void AndroidCopyingBackingStrategy::OnFrameAvailable() {
137 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be 137 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be
138 // moved into AVDA, and we should wait for it before doing the copy. 138 // moved into AVDA, and we should wait for it before doing the copy.
139 // Because there were some test failures, we don't do this now but 139 // Because there were some test failures, we don't do this now but
140 // instead preserve the old behavior. 140 // instead preserve the old behavior.
141 } 141 }
142 142
143 } // namespace content 143 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698