OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" | 5 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "gpu/command_buffer/service/texture_manager.h" | 9 #include "gpu/command_buffer/service/texture_manager.h" |
10 #include "ui/gfx/geometry/size.h" | 10 #include "ui/gfx/geometry/size.h" |
11 #include "ui/gl/android/surface_texture.h" | 11 #include "ui/gl/android/surface_texture.h" |
12 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
13 #include "ui/gl/gl_image.h" | 13 #include "ui/gl/gl_image.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Simply wraps a SurfaceTexture reference as a GLImage. | 19 // Simply wraps a SurfaceTexture reference as a GLImage. |
20 class GLImageImpl : public gfx::GLImage { | 20 class GLImageImpl : public gfx::GLImage { |
21 public: | 21 public: |
22 GLImageImpl(const scoped_refptr<gfx::SurfaceTexture>& surface_texture, | 22 GLImageImpl(gles2::TextureRef* texture_ref, |
| 23 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
23 const base::Closure& release_callback); | 24 const base::Closure& release_callback); |
24 | 25 |
25 // implement gfx::GLImage | 26 // implement gfx::GLImage |
26 void Destroy(bool have_context) override; | 27 void Destroy(bool have_context) override; |
27 gfx::Size GetSize() override; | 28 gfx::Size GetSize() override; |
28 unsigned GetInternalFormat() override; | 29 unsigned GetInternalFormat() override; |
29 bool BindTexImage(unsigned target) override; | 30 bool BindTexImage(unsigned target) override; |
30 void ReleaseTexImage(unsigned target) override; | 31 void ReleaseTexImage(unsigned target) override; |
| 32 bool CopyTexImage(unsigned target) override; |
31 bool CopyTexSubImage(unsigned target, | 33 bool CopyTexSubImage(unsigned target, |
32 const gfx::Point& offset, | 34 const gfx::Point& offset, |
33 const gfx::Rect& rect) override; | 35 const gfx::Rect& rect) override; |
34 void WillUseTexImage() override; | |
35 void DidUseTexImage() override {} | |
36 void WillModifyTexImage() override {} | |
37 void DidModifyTexImage() override {} | |
38 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 36 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
39 int z_order, | 37 int z_order, |
40 gfx::OverlayTransform transform, | 38 gfx::OverlayTransform transform, |
41 const gfx::Rect& bounds_rect, | 39 const gfx::Rect& bounds_rect, |
42 const gfx::RectF& crop_rect) override; | 40 const gfx::RectF& crop_rect) override; |
43 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 41 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
44 uint64_t process_tracing_id, | 42 uint64_t process_tracing_id, |
45 const std::string& dump_name) override; | 43 const std::string& dump_name) override; |
46 | 44 |
47 private: | 45 private: |
48 ~GLImageImpl() override; | 46 ~GLImageImpl() override; |
49 | 47 |
| 48 gles2::TextureRef* texture_ref_; |
50 scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 49 scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
51 base::Closure release_callback_; | 50 base::Closure release_callback_; |
52 | 51 |
53 DISALLOW_COPY_AND_ASSIGN(GLImageImpl); | 52 DISALLOW_COPY_AND_ASSIGN(GLImageImpl); |
54 }; | 53 }; |
55 | 54 |
56 GLImageImpl::GLImageImpl( | 55 GLImageImpl::GLImageImpl( |
| 56 gles2::TextureRef* texture_ref, |
57 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, | 57 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
58 const base::Closure& release_callback) | 58 const base::Closure& release_callback) |
59 : surface_texture_(surface_texture), release_callback_(release_callback) {} | 59 : texture_ref_(texture_ref), |
| 60 surface_texture_(surface_texture), |
| 61 release_callback_(release_callback) {} |
60 | 62 |
61 GLImageImpl::~GLImageImpl() { | 63 GLImageImpl::~GLImageImpl() { |
62 release_callback_.Run(); | 64 release_callback_.Run(); |
63 } | 65 } |
64 | 66 |
65 void GLImageImpl::Destroy(bool have_context) { | 67 void GLImageImpl::Destroy(bool have_context) { |
66 NOTREACHED(); | 68 NOTREACHED(); |
67 } | 69 } |
68 | 70 |
69 gfx::Size GLImageImpl::GetSize() { | 71 gfx::Size GLImageImpl::GetSize() { |
70 return gfx::Size(); | 72 return gfx::Size(); |
71 } | 73 } |
72 | 74 |
73 unsigned GLImageImpl::GetInternalFormat() { | 75 unsigned GLImageImpl::GetInternalFormat() { |
74 return GL_RGBA; | 76 return GL_RGBA; |
75 } | 77 } |
76 | 78 |
77 bool GLImageImpl::BindTexImage(unsigned target) { | 79 bool GLImageImpl::BindTexImage(unsigned target) { |
78 NOTREACHED(); | 80 NOTREACHED(); |
79 return false; | 81 return false; |
80 } | 82 } |
81 | 83 |
82 void GLImageImpl::ReleaseTexImage(unsigned target) { | 84 void GLImageImpl::ReleaseTexImage(unsigned target) { |
83 NOTREACHED(); | 85 NOTREACHED(); |
84 } | 86 } |
85 | 87 |
| 88 bool GLImageImpl::CopyTexImage(unsigned target) { |
| 89 surface_texture_->UpdateTexImage(); |
| 90 |
| 91 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 92 // CopyTexImage() is called each time the surface texture is used for |
| 93 // drawing. |
| 94 texture_ref_->texture()->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
| 95 gles2::Texture::UNBOUND); |
| 96 return true; |
| 97 } |
| 98 |
86 bool GLImageImpl::CopyTexSubImage(unsigned target, | 99 bool GLImageImpl::CopyTexSubImage(unsigned target, |
87 const gfx::Point& offset, | 100 const gfx::Point& offset, |
88 const gfx::Rect& rect) { | 101 const gfx::Rect& rect) { |
89 return false; | 102 return false; |
90 } | 103 } |
91 | 104 |
92 void GLImageImpl::WillUseTexImage() { | |
93 surface_texture_->UpdateTexImage(); | |
94 } | |
95 | |
96 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 105 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
97 int z_order, | 106 int z_order, |
98 gfx::OverlayTransform transform, | 107 gfx::OverlayTransform transform, |
99 const gfx::Rect& bounds_rect, | 108 const gfx::Rect& bounds_rect, |
100 const gfx::RectF& crop_rect) { | 109 const gfx::RectF& crop_rect) { |
101 NOTREACHED(); | 110 NOTREACHED(); |
102 return false; | 111 return false; |
103 } | 112 } |
104 | 113 |
105 void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 114 void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
(...skipping 26 matching lines...) Expand all Loading... |
132 return 0; | 141 return 0; |
133 } | 142 } |
134 | 143 |
135 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 144 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
136 gfx::SurfaceTexture::Create(texture->service_id())); | 145 gfx::SurfaceTexture::Create(texture->service_id())); |
137 | 146 |
138 uint32 stream_id = next_id_++; | 147 uint32 stream_id = next_id_++; |
139 base::Closure release_callback = | 148 base::Closure release_callback = |
140 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, | 149 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, |
141 weak_factory_.GetWeakPtr(), stream_id); | 150 weak_factory_.GetWeakPtr(), stream_id); |
142 scoped_refptr<gfx::GLImage> gl_image(new GLImageImpl(surface_texture, | 151 scoped_refptr<gfx::GLImage> gl_image( |
143 release_callback)); | 152 new GLImageImpl(texture, surface_texture, release_callback)); |
144 | 153 |
145 gfx::Size size = gl_image->GetSize(); | 154 gfx::Size size = gl_image->GetSize(); |
146 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); | 155 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); |
147 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, | 156 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, |
148 size.width(), size.height(), 1, 0, GL_RGBA, | 157 size.width(), size.height(), 1, 0, GL_RGBA, |
149 GL_UNSIGNED_BYTE, gfx::Rect(size)); | 158 GL_UNSIGNED_BYTE, gfx::Rect(size)); |
150 texture_manager->SetLevelImage( | 159 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, |
151 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get()); | 160 gl_image.get(), gles2::Texture::UNBOUND); |
152 | 161 |
153 { | 162 { |
154 base::AutoLock lock(map_lock_); | 163 base::AutoLock lock(map_lock_); |
155 textures_[stream_id] = surface_texture; | 164 textures_[stream_id] = surface_texture; |
156 } | 165 } |
157 | 166 |
158 if (next_id_ == 0) | 167 if (next_id_ == 0) |
159 next_id_++; | 168 next_id_++; |
160 | 169 |
161 return stream_id; | 170 return stream_id; |
(...skipping 10 matching lines...) Expand all Loading... |
172 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) { | 181 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) { |
173 base::AutoLock lock(map_lock_); | 182 base::AutoLock lock(map_lock_); |
174 TextureMap::const_iterator it = textures_.find(stream_id); | 183 TextureMap::const_iterator it = textures_.find(stream_id); |
175 if (it != textures_.end()) | 184 if (it != textures_.end()) |
176 return it->second; | 185 return it->second; |
177 | 186 |
178 return NULL; | 187 return NULL; |
179 } | 188 } |
180 | 189 |
181 } // namespace gpu | 190 } // namespace gpu |
OLD | NEW |