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

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: rebase only 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/context_group.h" 11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 12 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
14 #include "media/base/limits.h" 14 #include "media/base/limits.h"
15 #include "media/video/picture.h" 15 #include "media/video/picture.h"
16 #include "ui/gl/android/surface_texture.h" 16 #include "ui/gl/android/surface_texture.h"
17 #include "ui/gl/gl_bindings.h" 17 #include "ui/gl/gl_bindings.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 21 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
22 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 22 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
23 0.0f, 0.0f, 0.0f, 1.0f}; 23 0.0f, 0.0f, 0.0f, 1.0f};
24 24
25 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy() 25 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy(
26 : state_provider_(nullptr), surface_texture_id_(0), media_codec_(nullptr) {} 26 AVDAStateProvider* state_provider)
27 : state_provider_(state_provider),
28 surface_texture_id_(0),
29 media_codec_(nullptr) {}
27 30
28 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} 31 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {}
29 32
30 void AndroidCopyingBackingStrategy::Initialize( 33 gfx::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize(
31 AVDAStateProvider* state_provider) { 34 int surface_view_id) {
32 state_provider_ = state_provider; 35 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) {
33 } 36 LOG(ERROR) << "The copying strategy should not be initialized with a "
37 "surface id.";
38 return gfx::ScopedJavaSurface();
39 }
34 40
35 void AndroidCopyingBackingStrategy::Cleanup( 41 // Create a texture and attach the SurfaceTexture to it.
36 bool have_context,
37 const AndroidVideoDecodeAccelerator::OutputBufferMap&) {
38 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
39 if (copier_)
40 copier_->Destroy();
41
42 if (surface_texture_id_ && have_context)
43 glDeleteTextures(1, &surface_texture_id_);
44 }
45
46 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const {
47 return GL_TEXTURE_2D;
48 }
49
50 scoped_refptr<gfx::SurfaceTexture>
51 AndroidCopyingBackingStrategy::CreateSurfaceTexture() {
52 glGenTextures(1, &surface_texture_id_); 42 glGenTextures(1, &surface_texture_id_);
53 glActiveTexture(GL_TEXTURE0); 43 glActiveTexture(GL_TEXTURE0);
54 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); 44 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_);
55 45
56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 46 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 47 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
58 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 48 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
59 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 49 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
50
60 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); 51 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0);
61 state_provider_->GetGlDecoder()->RestoreActiveTexture(); 52 state_provider_->GetGlDecoder()->RestoreActiveTexture();
62 53
63 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); 54 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_);
64 55
56 return gfx::ScopedJavaSurface(surface_texture_.get());
57 }
58
59 void AndroidCopyingBackingStrategy::Cleanup(
60 bool have_context,
61 const AndroidVideoDecodeAccelerator::OutputBufferMap&) {
62 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
63
64 if (copier_)
65 copier_->Destroy();
66
67 if (surface_texture_id_ && have_context)
68 glDeleteTextures(1, &surface_texture_id_);
69 }
70
71 scoped_refptr<gfx::SurfaceTexture>
72 AndroidCopyingBackingStrategy::GetSurfaceTexture() const {
65 return surface_texture_; 73 return surface_texture_;
66 } 74 }
67 75
76 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const {
77 return GL_TEXTURE_2D;
78 }
79
68 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( 80 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer(
69 int32_t codec_buf_index, 81 int32_t codec_buf_index,
70 const media::PictureBuffer& picture_buffer) { 82 const media::PictureBuffer& picture_buffer) {
71 // Make sure that the decoder is available. 83 // Make sure that the decoder is available.
72 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), 84 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(),
73 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); 85 "Failed to get gles2 decoder instance.", ILLEGAL_STATE);
74 86
75 // Render the codec buffer into |surface_texture_|, and switch it to be 87 // Render the codec buffer into |surface_texture_|, and switch it to be
76 // the front buffer. 88 // the front buffer.
77 // This ignores the emitted ByteBuffer and instead relies on rendering to 89 // This ignores the emitted ByteBuffer and instead relies on rendering to
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 media_codec_ = codec; 148 media_codec_ = codec;
137 } 149 }
138 150
139 void AndroidCopyingBackingStrategy::OnFrameAvailable() { 151 void AndroidCopyingBackingStrategy::OnFrameAvailable() {
140 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be 152 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be
141 // moved into AVDA, and we should wait for it before doing the copy. 153 // moved into AVDA, and we should wait for it before doing the copy.
142 // Because there were some test failures, we don't do this now but 154 // Because there were some test failures, we don't do this now but
143 // instead preserve the old behavior. 155 // instead preserve the old behavior.
144 } 156 }
145 157
158 bool AndroidCopyingBackingStrategy::ArePicturesOverlayable() {
159 return false;
160 }
161
146 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698