OLD | NEW |
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 "media/gpu/android_copying_backing_strategy.h" | 5 #include "media/gpu/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 "gpu/command_buffer/service/context_group.h" | 10 #include "gpu/command_buffer/service/context_group.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/gpu/avda_return_on_failure.h" | 14 #include "media/gpu/avda_return_on_failure.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 media { | 19 namespace media { |
20 | 20 |
21 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy( | 21 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy( |
22 AVDAStateProvider* state_provider) | 22 AVDAStateProvider* state_provider) |
23 : state_provider_(state_provider), | 23 : state_provider_(state_provider), |
24 surface_texture_id_(0), | 24 surface_texture_id_(0), |
25 media_codec_(nullptr) {} | 25 media_codec_(nullptr) {} |
26 | 26 |
27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} | 27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} |
28 | 28 |
29 gfx::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize( | 29 gl::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize( |
30 int surface_view_id) { | 30 int surface_view_id) { |
31 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { | 31 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { |
32 LOG(ERROR) << "The copying strategy should not be initialized with a " | 32 LOG(ERROR) << "The copying strategy should not be initialized with a " |
33 "surface id."; | 33 "surface id."; |
34 return gfx::ScopedJavaSurface(); | 34 return gl::ScopedJavaSurface(); |
35 } | 35 } |
36 | 36 |
37 // Create a texture and attach the SurfaceTexture to it. | 37 // Create a texture and attach the SurfaceTexture to it. |
38 glGenTextures(1, &surface_texture_id_); | 38 glGenTextures(1, &surface_texture_id_); |
39 glActiveTexture(GL_TEXTURE0); | 39 glActiveTexture(GL_TEXTURE0); |
40 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); | 40 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); |
41 | 41 |
42 // Note that the target will be correctly sized, so nearest filtering is all | 42 // Note that the target will be correctly sized, so nearest filtering is all |
43 // that's needed. | 43 // that's needed. |
44 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 44 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
45 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 45 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
46 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 46 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
47 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 47 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
48 | 48 |
49 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); | 49 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); |
50 state_provider_->GetGlDecoder()->RestoreActiveTexture(); | 50 state_provider_->GetGlDecoder()->RestoreActiveTexture(); |
51 | 51 |
52 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); | 52 surface_texture_ = gl::SurfaceTexture::Create(surface_texture_id_); |
53 | 53 |
54 return gfx::ScopedJavaSurface(surface_texture_.get()); | 54 return gl::ScopedJavaSurface(surface_texture_.get()); |
55 } | 55 } |
56 | 56 |
57 void AndroidCopyingBackingStrategy::Cleanup( | 57 void AndroidCopyingBackingStrategy::Cleanup( |
58 bool have_context, | 58 bool have_context, |
59 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 59 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
60 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); | 60 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); |
61 | 61 |
62 if (copier_) | 62 if (copier_) |
63 copier_->Destroy(); | 63 copier_->Destroy(); |
64 | 64 |
65 if (surface_texture_id_ && have_context) | 65 if (surface_texture_id_ && have_context) |
66 glDeleteTextures(1, &surface_texture_id_); | 66 glDeleteTextures(1, &surface_texture_id_); |
67 } | 67 } |
68 | 68 |
69 scoped_refptr<gfx::SurfaceTexture> | 69 scoped_refptr<gl::SurfaceTexture> |
70 AndroidCopyingBackingStrategy::GetSurfaceTexture() const { | 70 AndroidCopyingBackingStrategy::GetSurfaceTexture() const { |
71 return surface_texture_; | 71 return surface_texture_; |
72 } | 72 } |
73 | 73 |
74 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { | 74 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { |
75 return GL_TEXTURE_2D; | 75 return GL_TEXTURE_2D; |
76 } | 76 } |
77 | 77 |
78 gfx::Size AndroidCopyingBackingStrategy::GetPictureBufferSize() const { | 78 gfx::Size AndroidCopyingBackingStrategy::GetPictureBufferSize() const { |
79 return state_provider_->GetSize(); | 79 return state_provider_->GetSize(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 RETURN_IF_NULL(texture_ref); | 184 RETURN_IF_NULL(texture_ref); |
185 gpu::gles2::TextureManager* texture_manager = | 185 gpu::gles2::TextureManager* texture_manager = |
186 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | 186 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); |
187 RETURN_IF_NULL(texture_manager); | 187 RETURN_IF_NULL(texture_manager); |
188 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA, | 188 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA, |
189 new_size.width(), new_size.height(), 1, 0, | 189 new_size.width(), new_size.height(), 1, 0, |
190 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(new_size)); | 190 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(new_size)); |
191 } | 191 } |
192 | 192 |
193 } // namespace media | 193 } // namespace media |
OLD | NEW |