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

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

Issue 1370443007: Move SurfaceTexture construction to BackingStrategy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased. Created 5 years, 2 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"
(...skipping 11 matching lines...) Expand all
22 // could occur during preroll. More recent tests have shown some 22 // could occur during preroll. More recent tests have shown some
23 // instability with kNumPictureBuffers==2 with similar symptoms 23 // instability with kNumPictureBuffers==2 with similar symptoms
24 // during playback. crbug.com/:531588 . 24 // during playback. crbug.com/:531588 .
25 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 }; 25 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 };
26 26
27 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 27 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
28 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 28 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
29 0.0f, 0.0f, 0.0f, 1.0f}; 29 0.0f, 0.0f, 0.0f, 1.0f};
30 30
31 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy() 31 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy()
32 : state_provider_(nullptr) {} 32 : state_provider_(nullptr)
33 , surface_texture_id_(0) {}
33 34
34 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} 35 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {}
35 36
36 void AndroidCopyingBackingStrategy::SetStateProvider( 37 void AndroidCopyingBackingStrategy::SetStateProvider(
37 AndroidVideoDecodeAcceleratorStateProvider* state_provider) { 38 AndroidVideoDecodeAcceleratorStateProvider* state_provider) {
38 state_provider_ = state_provider; 39 state_provider_ = state_provider;
39 } 40 }
40 41
41 void AndroidCopyingBackingStrategy::Cleanup() { 42 void AndroidCopyingBackingStrategy::Cleanup() {
42 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); 43 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread());
43 if (copier_) 44 if (copier_)
44 copier_->Destroy(); 45 copier_->Destroy();
46
47 if (surface_texture_id_)
48 glDeleteTextures(1, &surface_texture_id_);
45 } 49 }
46 50
47 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const { 51 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const {
48 return kNumPictureBuffers; 52 return kNumPictureBuffers;
49 } 53 }
50 54
51 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const { 55 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const {
52 return GL_TEXTURE_2D; 56 return GL_TEXTURE_2D;
53 } 57 }
54 58
55 void AndroidCopyingBackingStrategy::AssignCurrentSurfaceToPictureBuffer( 59 scoped_refptr<gfx::SurfaceTexture>
60 AndroidCopyingBackingStrategy::CreateSurfaceTexture() {
61 glGenTextures(1, &surface_texture_id_);
62 glActiveTexture(GL_TEXTURE0);
63 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_);
64
65 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
66 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
67 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
68 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
69 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0);
70 state_provider_->GetGlDecoder()->RestoreActiveTexture();
71
72 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_);
73
74 return surface_texture_;
75 }
76
77 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer(
56 int32 codec_buf_index, 78 int32 codec_buf_index,
57 const media::PictureBuffer& picture_buffer) { 79 const media::PictureBuffer& picture_buffer) {
58 // Make sure that the decoder is available. 80 // Make sure that the decoder is available.
59 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(), 81 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(),
60 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); 82 "Failed to get gles2 decoder instance.", ILLEGAL_STATE);
61 83
62 // Render the codec buffer into |surface_texture_|, and switch it to be 84 // Render the codec buffer into |surface_texture_|, and switch it to be
63 // the front buffer. 85 // the front buffer.
64 // This ignores the emitted ByteBuffer and instead relies on rendering to 86 // This ignores the emitted ByteBuffer and instead relies on rendering to
65 // the codec's SurfaceTexture and then copying from that texture to the 87 // the codec's SurfaceTexture and then copying from that texture to the
(...skipping 10 matching lines...) Expand all
76 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific, 98 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific,
77 // opaque/non-standard format. It's not possible to negotiate the 99 // opaque/non-standard format. It's not possible to negotiate the
78 // decoder to emit a specific colorspace, even using HW CSC. b/10706245 100 // decoder to emit a specific colorspace, even using HW CSC. b/10706245
79 // So, we live with these two extra copies per picture :( 101 // So, we live with these two extra copies per picture :(
80 { 102 {
81 TRACE_EVENT0("media", "AVDA::ReleaseOutputBuffer"); 103 TRACE_EVENT0("media", "AVDA::ReleaseOutputBuffer");
82 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index, 104 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index,
83 true); 105 true);
84 } 106 }
85 107
86 gfx::SurfaceTexture* surface_texture = state_provider_->GetSurfaceTexture();
87 { 108 {
88 TRACE_EVENT0("media", "AVDA::UpdateTexImage"); 109 TRACE_EVENT0("media", "AVDA::UpdateTexImage");
89 surface_texture->UpdateTexImage(); 110 surface_texture_->UpdateTexImage();
90 } 111 }
91 112
92 float transfrom_matrix[16]; 113 float transfrom_matrix[16];
93 surface_texture->GetTransformMatrix(transfrom_matrix); 114 surface_texture_->GetTransformMatrix(transfrom_matrix);
94 115
95 uint32 picture_buffer_texture_id = picture_buffer.texture_id(); 116 uint32 picture_buffer_texture_id = picture_buffer.texture_id();
96 117
97 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is 118 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
98 // needed because it takes 10s of milliseconds to initialize. 119 // needed because it takes 10s of milliseconds to initialize.
99 if (!copier_) { 120 if (!copier_) {
100 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager()); 121 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager());
101 copier_->Initialize(state_provider_->GetGlDecoder()); 122 copier_->Initialize(state_provider_->GetGlDecoder());
102 } 123 }
103 124
104 // Here, we copy |surface_texture_id_| to the picture buffer instead of 125 // Here, we copy |surface_texture_id_| to the picture buffer instead of
105 // setting new texture to |surface_texture_| by calling attachToGLContext() 126 // setting new texture to |surface_texture_| by calling attachToGLContext()
106 // because: 127 // because:
107 // 1. Once we call detachFrameGLContext(), it deletes the texture previous 128 // 1. Once we call detachFrameGLContext(), it deletes the texture previous
108 // attached. 129 // attached.
109 // 2. SurfaceTexture requires us to apply a transform matrix when we show 130 // 2. SurfaceTexture requires us to apply a transform matrix when we show
110 // the texture. 131 // the texture.
111 // TODO(hkuang): get the StreamTexture transform matrix in GPU process 132 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
112 // instead of using default matrix crbug.com/226218. 133 // instead of using default matrix crbug.com/226218.
113 copier_->DoCopyTextureWithTransform( 134 copier_->DoCopyTextureWithTransform(
114 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES, 135 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES,
115 state_provider_->GetSurfaceTextureId(), picture_buffer_texture_id, 136 surface_texture_id_, picture_buffer_texture_id,
116 state_provider_->GetSize().width(), state_provider_->GetSize().height(), 137 state_provider_->GetSize().width(), state_provider_->GetSize().height(),
117 false, false, false, kIdentityMatrix); 138 false, false, false, kIdentityMatrix);
118 } 139 }
119 140
120 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698