OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 #include "base/bits.h" | 6 #include "base/bits.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/service/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 default: | 56 default: |
57 NOTREACHED(); | 57 NOTREACHED(); |
58 return 0; | 58 return 0; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 TextureManager::~TextureManager() { | 62 TextureManager::~TextureManager() { |
63 DCHECK(texture_infos_.empty()); | 63 DCHECK(texture_infos_.empty()); |
64 | 64 |
65 // If this triggers, that means something is keeping a reference to | 65 // If this triggers, that means something is keeping a reference to |
66 // a TextureInfo belonging to this. | 66 // a Texture belonging to this. |
67 CHECK_EQ(texture_info_count_, 0u); | 67 CHECK_EQ(texture_info_count_, 0u); |
68 | 68 |
69 DCHECK_EQ(0, num_unrenderable_textures_); | 69 DCHECK_EQ(0, num_unrenderable_textures_); |
70 DCHECK_EQ(0, num_unsafe_textures_); | 70 DCHECK_EQ(0, num_unsafe_textures_); |
71 DCHECK_EQ(0, num_uncleared_mips_); | 71 DCHECK_EQ(0, num_uncleared_mips_); |
72 } | 72 } |
73 | 73 |
74 void TextureManager::Destroy(bool have_context) { | 74 void TextureManager::Destroy(bool have_context) { |
75 have_context_ = have_context; | 75 have_context_ = have_context; |
76 texture_infos_.clear(); | 76 texture_infos_.clear(); |
77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
78 default_textures_[ii] = NULL; | 78 default_textures_[ii] = NULL; |
79 } | 79 } |
80 | 80 |
81 if (have_context) { | 81 if (have_context) { |
82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); | 82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); |
83 } | 83 } |
84 | 84 |
85 DCHECK_EQ(0u, memory_tracker_managed_->GetMemRepresented()); | 85 DCHECK_EQ(0u, memory_tracker_managed_->GetMemRepresented()); |
86 DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented()); | 86 DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented()); |
87 } | 87 } |
88 | 88 |
89 TextureManager::TextureInfo::TextureInfo(TextureManager* manager, | 89 Texture::Texture(TextureManager* manager, |
90 GLuint service_id) | 90 GLuint service_id) |
91 : manager_(manager), | 91 : manager_(manager), |
92 service_id_(service_id), | 92 service_id_(service_id), |
93 deleted_(false), | 93 deleted_(false), |
94 cleared_(true), | 94 cleared_(true), |
95 num_uncleared_mips_(0), | 95 num_uncleared_mips_(0), |
96 target_(0), | 96 target_(0), |
97 min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 97 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
98 mag_filter_(GL_LINEAR), | 98 mag_filter_(GL_LINEAR), |
99 wrap_s_(GL_REPEAT), | 99 wrap_s_(GL_REPEAT), |
100 wrap_t_(GL_REPEAT), | 100 wrap_t_(GL_REPEAT), |
101 usage_(GL_NONE), | 101 usage_(GL_NONE), |
102 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), | 102 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), |
103 max_level_set_(-1), | 103 max_level_set_(-1), |
104 texture_complete_(false), | 104 texture_complete_(false), |
105 cube_complete_(false), | 105 cube_complete_(false), |
106 npot_(false), | 106 npot_(false), |
107 has_been_bound_(false), | 107 has_been_bound_(false), |
108 framebuffer_attachment_count_(0), | 108 framebuffer_attachment_count_(0), |
109 owned_(true), | 109 owned_(true), |
110 stream_texture_(false), | 110 stream_texture_(false), |
111 immutable_(false), | 111 immutable_(false), |
112 estimated_size_(0) { | 112 estimated_size_(0) { |
113 if (manager_) { | 113 if (manager_) { |
114 manager_->StartTracking(this); | 114 manager_->StartTracking(this); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 TextureManager::TextureInfo::~TextureInfo() { | 118 Texture::~Texture() { |
119 if (manager_) { | 119 if (manager_) { |
120 if (owned_ && manager_->have_context_) { | 120 if (owned_ && manager_->have_context_) { |
121 GLuint id = service_id(); | 121 GLuint id = service_id(); |
122 glDeleteTextures(1, &id); | 122 glDeleteTextures(1, &id); |
123 } | 123 } |
124 MarkAsDeleted(); | 124 MarkAsDeleted(); |
125 manager_->StopTracking(this); | 125 manager_->StopTracking(this); |
126 manager_ = NULL; | 126 manager_ = NULL; |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 TextureManager::TextureInfo::LevelInfo::LevelInfo() | 130 Texture::LevelInfo::LevelInfo() |
131 : cleared(true), | 131 : cleared(true), |
132 target(0), | 132 target(0), |
133 level(-1), | 133 level(-1), |
134 internal_format(0), | 134 internal_format(0), |
135 width(0), | 135 width(0), |
136 height(0), | 136 height(0), |
137 depth(0), | 137 depth(0), |
138 border(0), | 138 border(0), |
139 format(0), | 139 format(0), |
140 type(0), | 140 type(0), |
141 estimated_size(0) { | 141 estimated_size(0) { |
142 } | 142 } |
143 | 143 |
144 TextureManager::TextureInfo::LevelInfo::LevelInfo(const LevelInfo& rhs) | 144 Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) |
145 : cleared(rhs.cleared), | 145 : cleared(rhs.cleared), |
146 target(rhs.target), | 146 target(rhs.target), |
147 level(rhs.level), | 147 level(rhs.level), |
148 internal_format(rhs.internal_format), | 148 internal_format(rhs.internal_format), |
149 width(rhs.width), | 149 width(rhs.width), |
150 height(rhs.height), | 150 height(rhs.height), |
151 depth(rhs.depth), | 151 depth(rhs.depth), |
152 border(rhs.border), | 152 border(rhs.border), |
153 format(rhs.format), | 153 format(rhs.format), |
154 type(rhs.type), | 154 type(rhs.type), |
155 image(rhs.image), | 155 image(rhs.image), |
156 estimated_size(rhs.estimated_size) { | 156 estimated_size(rhs.estimated_size) { |
157 } | 157 } |
158 | 158 |
159 TextureManager::TextureInfo::LevelInfo::~LevelInfo() { | 159 Texture::LevelInfo::~LevelInfo() { |
160 } | 160 } |
161 | 161 |
162 bool TextureManager::TextureInfo::CanRender( | 162 bool Texture::CanRender( |
163 const FeatureInfo* feature_info) const { | 163 const FeatureInfo* feature_info) const { |
164 if (target_ == 0) { | 164 if (target_ == 0) { |
165 return false; | 165 return false; |
166 } | 166 } |
167 bool needs_mips = NeedsMips(); | 167 bool needs_mips = NeedsMips(); |
168 if ((npot() && !feature_info->feature_flags().npot_ok) || | 168 if ((npot() && !feature_info->feature_flags().npot_ok) || |
169 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { | 169 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { |
170 return !needs_mips && | 170 return !needs_mips && |
171 wrap_s_ == GL_CLAMP_TO_EDGE && | 171 wrap_s_ == GL_CLAMP_TO_EDGE && |
172 wrap_t_ == GL_CLAMP_TO_EDGE; | 172 wrap_t_ == GL_CLAMP_TO_EDGE; |
173 } | 173 } |
174 if (needs_mips) { | 174 if (needs_mips) { |
175 if (target_ == GL_TEXTURE_2D) { | 175 if (target_ == GL_TEXTURE_2D) { |
176 return texture_complete(); | 176 return texture_complete(); |
177 } else { | 177 } else { |
178 return texture_complete() && cube_complete(); | 178 return texture_complete() && cube_complete(); |
179 } | 179 } |
180 } else { | 180 } else { |
181 return true; | 181 return true; |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 void TextureManager::TextureInfo::AddToSignature( | 185 void Texture::AddToSignature( |
186 const FeatureInfo* feature_info, | 186 const FeatureInfo* feature_info, |
187 GLenum target, | 187 GLenum target, |
188 GLint level, | 188 GLint level, |
189 std::string* signature) const { | 189 std::string* signature) const { |
190 DCHECK(feature_info); | 190 DCHECK(feature_info); |
191 DCHECK(signature); | 191 DCHECK(signature); |
192 DCHECK_GE(level, 0); | 192 DCHECK_GE(level, 0); |
193 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), | 193 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
194 level_infos_.size()); | 194 level_infos_.size()); |
195 DCHECK_LT(static_cast<size_t>(level), | 195 DCHECK_LT(static_cast<size_t>(level), |
196 level_infos_[GLTargetToFaceIndex(target)].size()); | 196 level_infos_[GLTargetToFaceIndex(target)].size()); |
197 const TextureInfo::LevelInfo& info = | 197 const Texture::LevelInfo& info = |
198 level_infos_[GLTargetToFaceIndex(target)][level]; | 198 level_infos_[GLTargetToFaceIndex(target)][level]; |
199 *signature += base::StringPrintf( | 199 *signature += base::StringPrintf( |
200 "|Texture|target=%04x|level=%d|internal_format=%04x" | 200 "|Texture|target=%04x|level=%d|internal_format=%04x" |
201 "|width=%d|height=%d|depth=%d|border=%d|format=%04x|type=%04x" | 201 "|width=%d|height=%d|depth=%d|border=%d|format=%04x|type=%04x" |
202 "|image=%d|canrender=%d|canrenderto=%d|npot_=%d" | 202 "|image=%d|canrender=%d|canrenderto=%d|npot_=%d" |
203 "|min_filter=%04x|mag_filter=%04x|wrap_s=%04x|wrap_t=%04x" | 203 "|min_filter=%04x|mag_filter=%04x|wrap_s=%04x|wrap_t=%04x" |
204 "|usage=%04x", | 204 "|usage=%04x", |
205 target, level, info.internal_format, | 205 target, level, info.internal_format, |
206 info.width, info.height, info.depth, info.border, | 206 info.width, info.height, info.depth, info.border, |
207 info.format, info.type, info.image.get() != NULL, | 207 info.format, info.type, info.image.get() != NULL, |
208 CanRender(feature_info), CanRenderTo(), npot_, | 208 CanRender(feature_info), CanRenderTo(), npot_, |
209 min_filter_, mag_filter_, wrap_s_, wrap_t_, | 209 min_filter_, mag_filter_, wrap_s_, wrap_t_, |
210 usage_); | 210 usage_); |
211 } | 211 } |
212 | 212 |
213 bool TextureManager::TextureInfo::MarkMipmapsGenerated( | 213 bool Texture::MarkMipmapsGenerated( |
214 const FeatureInfo* feature_info) { | 214 const FeatureInfo* feature_info) { |
215 if (!CanGenerateMipmaps(feature_info)) { | 215 if (!CanGenerateMipmaps(feature_info)) { |
216 return false; | 216 return false; |
217 } | 217 } |
218 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 218 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
219 const TextureInfo::LevelInfo& info1 = level_infos_[ii][0]; | 219 const Texture::LevelInfo& info1 = level_infos_[ii][0]; |
220 GLsizei width = info1.width; | 220 GLsizei width = info1.width; |
221 GLsizei height = info1.height; | 221 GLsizei height = info1.height; |
222 GLsizei depth = info1.depth; | 222 GLsizei depth = info1.depth; |
223 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : | 223 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : |
224 FaceIndexToGLTarget(ii); | 224 FaceIndexToGLTarget(ii); |
225 int num_mips = ComputeMipMapCount(width, height, depth); | 225 int num_mips = TextureManager::ComputeMipMapCount(width, height, depth); |
226 for (int level = 1; level < num_mips; ++level) { | 226 for (int level = 1; level < num_mips; ++level) { |
227 width = std::max(1, width >> 1); | 227 width = std::max(1, width >> 1); |
228 height = std::max(1, height >> 1); | 228 height = std::max(1, height >> 1); |
229 depth = std::max(1, depth >> 1); | 229 depth = std::max(1, depth >> 1); |
230 SetLevelInfo(feature_info, | 230 SetLevelInfo(feature_info, |
231 target, | 231 target, |
232 level, | 232 level, |
233 info1.internal_format, | 233 info1.internal_format, |
234 width, | 234 width, |
235 height, | 235 height, |
236 depth, | 236 depth, |
237 info1.border, | 237 info1.border, |
238 info1.format, | 238 info1.format, |
239 info1.type, | 239 info1.type, |
240 true); | 240 true); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 return true; | 244 return true; |
245 } | 245 } |
246 | 246 |
247 void TextureManager::TextureInfo::SetTarget(GLenum target, GLint max_levels) { | 247 void Texture::SetTarget(GLenum target, GLint max_levels) { |
248 DCHECK_EQ(0u, target_); // you can only set this once. | 248 DCHECK_EQ(0u, target_); // you can only set this once. |
249 target_ = target; | 249 target_ = target; |
250 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 250 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
251 level_infos_.resize(num_faces); | 251 level_infos_.resize(num_faces); |
252 for (size_t ii = 0; ii < num_faces; ++ii) { | 252 for (size_t ii = 0; ii < num_faces; ++ii) { |
253 level_infos_[ii].resize(max_levels); | 253 level_infos_[ii].resize(max_levels); |
254 } | 254 } |
255 | 255 |
256 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 256 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
257 min_filter_ = GL_LINEAR; | 257 min_filter_ = GL_LINEAR; |
258 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; | 258 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 bool TextureManager::TextureInfo::CanGenerateMipmaps( | 262 bool Texture::CanGenerateMipmaps( |
263 const FeatureInfo* feature_info) const { | 263 const FeatureInfo* feature_info) const { |
264 if ((npot() && !feature_info->feature_flags().npot_ok) || | 264 if ((npot() && !feature_info->feature_flags().npot_ok) || |
265 level_infos_.empty() || | 265 level_infos_.empty() || |
266 target_ == GL_TEXTURE_EXTERNAL_OES || | 266 target_ == GL_TEXTURE_EXTERNAL_OES || |
267 target_ == GL_TEXTURE_RECTANGLE_ARB) { | 267 target_ == GL_TEXTURE_RECTANGLE_ARB) { |
268 return false; | 268 return false; |
269 } | 269 } |
270 | 270 |
271 // Can't generate mips for depth or stencil textures. | 271 // Can't generate mips for depth or stencil textures. |
272 const TextureInfo::LevelInfo& first = level_infos_[0][0]; | 272 const Texture::LevelInfo& first = level_infos_[0][0]; |
273 uint32 channels = GLES2Util::GetChannelsForFormat(first.format); | 273 uint32 channels = GLES2Util::GetChannelsForFormat(first.format); |
274 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { | 274 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { |
275 return false; | 275 return false; |
276 } | 276 } |
277 | 277 |
278 // TODO(gman): Check internal_format, format and type. | 278 // TODO(gman): Check internal_format, format and type. |
279 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 279 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
280 const LevelInfo& info = level_infos_[ii][0]; | 280 const LevelInfo& info = level_infos_[ii][0]; |
281 if ((info.target == 0) || | 281 if ((info.target == 0) || |
282 (info.width != first.width) || | 282 (info.width != first.width) || |
283 (info.height != first.height) || | 283 (info.height != first.height) || |
284 (info.depth != 1) || | 284 (info.depth != 1) || |
285 (info.format != first.format) || | 285 (info.format != first.format) || |
286 (info.internal_format != first.internal_format) || | 286 (info.internal_format != first.internal_format) || |
287 (info.type != first.type) || | 287 (info.type != first.type) || |
288 feature_info->validators()->compressed_texture_format.IsValid( | 288 feature_info->validators()->compressed_texture_format.IsValid( |
289 info.internal_format) || | 289 info.internal_format) || |
290 info.image) { | 290 info.image) { |
291 return false; | 291 return false; |
292 } | 292 } |
293 } | 293 } |
294 return true; | 294 return true; |
295 } | 295 } |
296 | 296 |
297 void TextureManager::TextureInfo::SetLevelCleared(GLenum target, | 297 void Texture::SetLevelCleared(GLenum target, |
298 GLint level, | 298 GLint level, |
299 bool cleared) { | 299 bool cleared) { |
300 DCHECK_GE(level, 0); | 300 DCHECK_GE(level, 0); |
301 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), | 301 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
302 level_infos_.size()); | 302 level_infos_.size()); |
303 DCHECK_LT(static_cast<size_t>(level), | 303 DCHECK_LT(static_cast<size_t>(level), |
304 level_infos_[GLTargetToFaceIndex(target)].size()); | 304 level_infos_[GLTargetToFaceIndex(target)].size()); |
305 TextureInfo::LevelInfo& info = | 305 Texture::LevelInfo& info = |
306 level_infos_[GLTargetToFaceIndex(target)][level]; | 306 level_infos_[GLTargetToFaceIndex(target)][level]; |
307 if (!info.cleared) { | 307 if (!info.cleared) { |
308 DCHECK_NE(0, num_uncleared_mips_); | 308 DCHECK_NE(0, num_uncleared_mips_); |
309 --num_uncleared_mips_; | 309 --num_uncleared_mips_; |
310 } else { | 310 } else { |
311 ++num_uncleared_mips_; | 311 ++num_uncleared_mips_; |
312 } | 312 } |
313 info.cleared = cleared; | 313 info.cleared = cleared; |
314 UpdateCleared(); | 314 UpdateCleared(); |
315 } | 315 } |
316 | 316 |
317 void TextureManager::TextureInfo::UpdateCleared() { | 317 void Texture::UpdateCleared() { |
318 if (level_infos_.empty()) { | 318 if (level_infos_.empty()) { |
319 return; | 319 return; |
320 } | 320 } |
321 | 321 |
322 const TextureInfo::LevelInfo& first_face = level_infos_[0][0]; | 322 const Texture::LevelInfo& first_face = level_infos_[0][0]; |
323 int levels_needed = ComputeMipMapCount( | 323 int levels_needed = TextureManager::ComputeMipMapCount( |
324 first_face.width, first_face.height, first_face.depth); | 324 first_face.width, first_face.height, first_face.depth); |
325 cleared_ = true; | 325 cleared_ = true; |
326 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 326 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
327 for (GLint jj = 0; jj < levels_needed; ++jj) { | 327 for (GLint jj = 0; jj < levels_needed; ++jj) { |
328 const TextureInfo::LevelInfo& info = level_infos_[ii][jj]; | 328 const Texture::LevelInfo& info = level_infos_[ii][jj]; |
329 if (info.width > 0 && info.height > 0 && info.depth > 0 && | 329 if (info.width > 0 && info.height > 0 && info.depth > 0 && |
330 !info.cleared) { | 330 !info.cleared) { |
331 cleared_ = false; | 331 cleared_ = false; |
332 return; | 332 return; |
333 } | 333 } |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 void TextureManager::TextureInfo::SetLevelInfo( | 338 void Texture::SetLevelInfo( |
339 const FeatureInfo* feature_info, | 339 const FeatureInfo* feature_info, |
340 GLenum target, | 340 GLenum target, |
341 GLint level, | 341 GLint level, |
342 GLenum internal_format, | 342 GLenum internal_format, |
343 GLsizei width, | 343 GLsizei width, |
344 GLsizei height, | 344 GLsizei height, |
345 GLsizei depth, | 345 GLsizei depth, |
346 GLint border, | 346 GLint border, |
347 GLenum format, | 347 GLenum format, |
348 GLenum type, | 348 GLenum type, |
349 bool cleared) { | 349 bool cleared) { |
350 DCHECK_GE(level, 0); | 350 DCHECK_GE(level, 0); |
351 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), | 351 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
352 level_infos_.size()); | 352 level_infos_.size()); |
353 DCHECK_LT(static_cast<size_t>(level), | 353 DCHECK_LT(static_cast<size_t>(level), |
354 level_infos_[GLTargetToFaceIndex(target)].size()); | 354 level_infos_[GLTargetToFaceIndex(target)].size()); |
355 DCHECK_GE(width, 0); | 355 DCHECK_GE(width, 0); |
356 DCHECK_GE(height, 0); | 356 DCHECK_GE(height, 0); |
357 DCHECK_GE(depth, 0); | 357 DCHECK_GE(depth, 0); |
358 TextureInfo::LevelInfo& info = | 358 Texture::LevelInfo& info = |
359 level_infos_[GLTargetToFaceIndex(target)][level]; | 359 level_infos_[GLTargetToFaceIndex(target)][level]; |
360 info.target = target; | 360 info.target = target; |
361 info.level = level; | 361 info.level = level; |
362 info.internal_format = internal_format; | 362 info.internal_format = internal_format; |
363 info.width = width; | 363 info.width = width; |
364 info.height = height; | 364 info.height = height; |
365 info.depth = depth; | 365 info.depth = depth; |
366 info.border = border; | 366 info.border = border; |
367 info.format = format; | 367 info.format = format; |
368 info.type = type; | 368 info.type = type; |
(...skipping 10 matching lines...) Expand all Loading... |
379 } | 379 } |
380 info.cleared = cleared; | 380 info.cleared = cleared; |
381 if (!info.cleared) { | 381 if (!info.cleared) { |
382 ++num_uncleared_mips_; | 382 ++num_uncleared_mips_; |
383 } | 383 } |
384 max_level_set_ = std::max(max_level_set_, level); | 384 max_level_set_ = std::max(max_level_set_, level); |
385 Update(feature_info); | 385 Update(feature_info); |
386 UpdateCleared(); | 386 UpdateCleared(); |
387 } | 387 } |
388 | 388 |
389 bool TextureManager::TextureInfo::ValidForTexture( | 389 bool Texture::ValidForTexture( |
390 GLint target, | 390 GLint target, |
391 GLint level, | 391 GLint level, |
392 GLint xoffset, | 392 GLint xoffset, |
393 GLint yoffset, | 393 GLint yoffset, |
394 GLsizei width, | 394 GLsizei width, |
395 GLsizei height, | 395 GLsizei height, |
396 GLenum format, | 396 GLenum format, |
397 GLenum type) const { | 397 GLenum type) const { |
398 size_t face_index = GLTargetToFaceIndex(target); | 398 size_t face_index = GLTargetToFaceIndex(target); |
399 if (level >= 0 && face_index < level_infos_.size() && | 399 if (level >= 0 && face_index < level_infos_.size() && |
400 static_cast<size_t>(level) < level_infos_[face_index].size()) { | 400 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
401 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 401 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
402 int32 right; | 402 int32 right; |
403 int32 top; | 403 int32 top; |
404 return SafeAddInt32(xoffset, width, &right) && | 404 return SafeAddInt32(xoffset, width, &right) && |
405 SafeAddInt32(yoffset, height, &top) && | 405 SafeAddInt32(yoffset, height, &top) && |
406 xoffset >= 0 && | 406 xoffset >= 0 && |
407 yoffset >= 0 && | 407 yoffset >= 0 && |
408 right <= info.width && | 408 right <= info.width && |
409 top <= info.height && | 409 top <= info.height && |
410 format == info.internal_format && | 410 format == info.internal_format && |
411 type == info.type; | 411 type == info.type; |
412 } | 412 } |
413 return false; | 413 return false; |
414 } | 414 } |
415 | 415 |
416 bool TextureManager::TextureInfo::GetLevelSize( | 416 bool Texture::GetLevelSize( |
417 GLint target, GLint level, GLsizei* width, GLsizei* height) const { | 417 GLint target, GLint level, GLsizei* width, GLsizei* height) const { |
418 DCHECK(width); | 418 DCHECK(width); |
419 DCHECK(height); | 419 DCHECK(height); |
420 size_t face_index = GLTargetToFaceIndex(target); | 420 size_t face_index = GLTargetToFaceIndex(target); |
421 if (level >= 0 && face_index < level_infos_.size() && | 421 if (level >= 0 && face_index < level_infos_.size() && |
422 static_cast<size_t>(level) < level_infos_[face_index].size()) { | 422 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
423 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 423 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
424 if (info.target != 0) { | 424 if (info.target != 0) { |
425 *width = info.width; | 425 *width = info.width; |
426 *height = info.height; | 426 *height = info.height; |
427 return true; | 427 return true; |
428 } | 428 } |
429 } | 429 } |
430 return false; | 430 return false; |
431 } | 431 } |
432 | 432 |
433 bool TextureManager::TextureInfo::GetLevelType( | 433 bool Texture::GetLevelType( |
434 GLint target, GLint level, GLenum* type, GLenum* internal_format) const { | 434 GLint target, GLint level, GLenum* type, GLenum* internal_format) const { |
435 DCHECK(type); | 435 DCHECK(type); |
436 DCHECK(internal_format); | 436 DCHECK(internal_format); |
437 size_t face_index = GLTargetToFaceIndex(target); | 437 size_t face_index = GLTargetToFaceIndex(target); |
438 if (level >= 0 && face_index < level_infos_.size() && | 438 if (level >= 0 && face_index < level_infos_.size() && |
439 static_cast<size_t>(level) < level_infos_[face_index].size()) { | 439 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
440 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 440 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
441 if (info.target != 0) { | 441 if (info.target != 0) { |
442 *type = info.type; | 442 *type = info.type; |
443 *internal_format = info.internal_format; | 443 *internal_format = info.internal_format; |
444 return true; | 444 return true; |
445 } | 445 } |
446 } | 446 } |
447 return false; | 447 return false; |
448 } | 448 } |
449 | 449 |
450 GLenum TextureManager::TextureInfo::SetParameter( | 450 GLenum Texture::SetParameter( |
451 const FeatureInfo* feature_info, GLenum pname, GLint param) { | 451 const FeatureInfo* feature_info, GLenum pname, GLint param) { |
452 DCHECK(feature_info); | 452 DCHECK(feature_info); |
453 | 453 |
454 if (target_ == GL_TEXTURE_EXTERNAL_OES || | 454 if (target_ == GL_TEXTURE_EXTERNAL_OES || |
455 target_ == GL_TEXTURE_RECTANGLE_ARB) { | 455 target_ == GL_TEXTURE_RECTANGLE_ARB) { |
456 if (pname == GL_TEXTURE_MIN_FILTER && | 456 if (pname == GL_TEXTURE_MIN_FILTER && |
457 (param != GL_NEAREST && param != GL_LINEAR)) | 457 (param != GL_NEAREST && param != GL_LINEAR)) |
458 return GL_INVALID_ENUM; | 458 return GL_INVALID_ENUM; |
459 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && | 459 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && |
460 param != GL_CLAMP_TO_EDGE) | 460 param != GL_CLAMP_TO_EDGE) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 break; | 507 break; |
508 default: | 508 default: |
509 NOTREACHED(); | 509 NOTREACHED(); |
510 return GL_INVALID_ENUM; | 510 return GL_INVALID_ENUM; |
511 } | 511 } |
512 Update(feature_info); | 512 Update(feature_info); |
513 UpdateCleared(); | 513 UpdateCleared(); |
514 return GL_NO_ERROR; | 514 return GL_NO_ERROR; |
515 } | 515 } |
516 | 516 |
517 void TextureManager::TextureInfo::Update(const FeatureInfo* feature_info) { | 517 void Texture::Update(const FeatureInfo* feature_info) { |
518 // Update npot status. | 518 // Update npot status. |
519 npot_ = false; | 519 npot_ = false; |
520 | 520 |
521 if (level_infos_.empty()) { | 521 if (level_infos_.empty()) { |
522 texture_complete_ = false; | 522 texture_complete_ = false; |
523 cube_complete_ = false; | 523 cube_complete_ = false; |
524 return; | 524 return; |
525 } | 525 } |
526 | 526 |
527 // checks that the first mip of any face is npot. | 527 // checks that the first mip of any face is npot. |
528 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 528 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
529 const TextureInfo::LevelInfo& info = level_infos_[ii][0]; | 529 const Texture::LevelInfo& info = level_infos_[ii][0]; |
530 if (GLES2Util::IsNPOT(info.width) || | 530 if (GLES2Util::IsNPOT(info.width) || |
531 GLES2Util::IsNPOT(info.height) || | 531 GLES2Util::IsNPOT(info.height) || |
532 GLES2Util::IsNPOT(info.depth)) { | 532 GLES2Util::IsNPOT(info.depth)) { |
533 npot_ = true; | 533 npot_ = true; |
534 break; | 534 break; |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 // Update texture_complete and cube_complete status. | 538 // Update texture_complete and cube_complete status. |
539 const TextureInfo::LevelInfo& first_face = level_infos_[0][0]; | 539 const Texture::LevelInfo& first_face = level_infos_[0][0]; |
540 int levels_needed = ComputeMipMapCount( | 540 int levels_needed = TextureManager::ComputeMipMapCount( |
541 first_face.width, first_face.height, first_face.depth); | 541 first_face.width, first_face.height, first_face.depth); |
542 texture_complete_ = | 542 texture_complete_ = |
543 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 543 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
544 cube_complete_ = (level_infos_.size() == 6) && | 544 cube_complete_ = (level_infos_.size() == 6) && |
545 (first_face.width == first_face.height); | 545 (first_face.width == first_face.height); |
546 if (first_face.width == 0 || first_face.height == 0) { | 546 if (first_face.width == 0 || first_face.height == 0) { |
547 texture_complete_ = false; | 547 texture_complete_ = false; |
548 } | 548 } |
549 if (first_face.type == GL_FLOAT && | 549 if (first_face.type == GL_FLOAT && |
550 !feature_info->feature_flags().enable_texture_float_linear && | 550 !feature_info->feature_flags().enable_texture_float_linear && |
551 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 551 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
552 mag_filter_ != GL_NEAREST)) { | 552 mag_filter_ != GL_NEAREST)) { |
553 texture_complete_ = false; | 553 texture_complete_ = false; |
554 } else if (first_face.type == GL_HALF_FLOAT_OES && | 554 } else if (first_face.type == GL_HALF_FLOAT_OES && |
555 !feature_info->feature_flags().enable_texture_half_float_linear && | 555 !feature_info->feature_flags().enable_texture_half_float_linear && |
556 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 556 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
557 mag_filter_ != GL_NEAREST)) { | 557 mag_filter_ != GL_NEAREST)) { |
558 texture_complete_ = false; | 558 texture_complete_ = false; |
559 } | 559 } |
560 for (size_t ii = 0; | 560 for (size_t ii = 0; |
561 ii < level_infos_.size() && (cube_complete_ || texture_complete_); | 561 ii < level_infos_.size() && (cube_complete_ || texture_complete_); |
562 ++ii) { | 562 ++ii) { |
563 const TextureInfo::LevelInfo& level0 = level_infos_[ii][0]; | 563 const Texture::LevelInfo& level0 = level_infos_[ii][0]; |
564 if (level0.target == 0 || | 564 if (level0.target == 0 || |
565 level0.width != first_face.width || | 565 level0.width != first_face.width || |
566 level0.height != first_face.height || | 566 level0.height != first_face.height || |
567 level0.depth != 1 || | 567 level0.depth != 1 || |
568 level0.internal_format != first_face.internal_format || | 568 level0.internal_format != first_face.internal_format || |
569 level0.format != first_face.format || | 569 level0.format != first_face.format || |
570 level0.type != first_face.type) { | 570 level0.type != first_face.type) { |
571 cube_complete_ = false; | 571 cube_complete_ = false; |
572 } | 572 } |
573 // Get level0 dimensions | 573 // Get level0 dimensions |
574 GLsizei width = level0.width; | 574 GLsizei width = level0.width; |
575 GLsizei height = level0.height; | 575 GLsizei height = level0.height; |
576 GLsizei depth = level0.depth; | 576 GLsizei depth = level0.depth; |
577 for (GLint jj = 1; jj < levels_needed; ++jj) { | 577 for (GLint jj = 1; jj < levels_needed; ++jj) { |
578 // compute required size for mip. | 578 // compute required size for mip. |
579 width = std::max(1, width >> 1); | 579 width = std::max(1, width >> 1); |
580 height = std::max(1, height >> 1); | 580 height = std::max(1, height >> 1); |
581 depth = std::max(1, depth >> 1); | 581 depth = std::max(1, depth >> 1); |
582 const TextureInfo::LevelInfo& info = level_infos_[ii][jj]; | 582 const Texture::LevelInfo& info = level_infos_[ii][jj]; |
583 if (info.target == 0 || | 583 if (info.target == 0 || |
584 info.width != width || | 584 info.width != width || |
585 info.height != height || | 585 info.height != height || |
586 info.depth != depth || | 586 info.depth != depth || |
587 info.internal_format != level0.internal_format || | 587 info.internal_format != level0.internal_format || |
588 info.format != level0.format || | 588 info.format != level0.format || |
589 info.type != level0.type) { | 589 info.type != level0.type) { |
590 texture_complete_ = false; | 590 texture_complete_ = false; |
591 break; | 591 break; |
592 } | 592 } |
593 } | 593 } |
594 } | 594 } |
595 } | 595 } |
596 | 596 |
597 bool TextureManager::TextureInfo::ClearRenderableLevels(GLES2Decoder* decoder) { | 597 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { |
598 DCHECK(decoder); | 598 DCHECK(decoder); |
599 if (SafeToRenderFrom()) { | 599 if (SafeToRenderFrom()) { |
600 return true; | 600 return true; |
601 } | 601 } |
602 | 602 |
603 const TextureInfo::LevelInfo& first_face = level_infos_[0][0]; | 603 const Texture::LevelInfo& first_face = level_infos_[0][0]; |
604 int levels_needed = ComputeMipMapCount( | 604 int levels_needed = TextureManager::ComputeMipMapCount( |
605 first_face.width, first_face.height, first_face.depth); | 605 first_face.width, first_face.height, first_face.depth); |
606 | 606 |
607 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 607 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
608 for (GLint jj = 0; jj < levels_needed; ++jj) { | 608 for (GLint jj = 0; jj < levels_needed; ++jj) { |
609 TextureInfo::LevelInfo& info = level_infos_[ii][jj]; | 609 Texture::LevelInfo& info = level_infos_[ii][jj]; |
610 if (info.target != 0) { | 610 if (info.target != 0) { |
611 if (!ClearLevel(decoder, info.target, jj)) { | 611 if (!ClearLevel(decoder, info.target, jj)) { |
612 return false; | 612 return false; |
613 } | 613 } |
614 } | 614 } |
615 } | 615 } |
616 } | 616 } |
617 cleared_ = true; | 617 cleared_ = true; |
618 return true; | 618 return true; |
619 } | 619 } |
620 | 620 |
621 bool TextureManager::TextureInfo::IsLevelCleared(GLenum target, GLint level) { | 621 bool Texture::IsLevelCleared(GLenum target, GLint level) { |
622 size_t face_index = GLTargetToFaceIndex(target); | 622 size_t face_index = GLTargetToFaceIndex(target); |
623 if (face_index >= level_infos_.size() || | 623 if (face_index >= level_infos_.size() || |
624 level >= static_cast<GLint>(level_infos_[face_index].size())) { | 624 level >= static_cast<GLint>(level_infos_[face_index].size())) { |
625 return true; | 625 return true; |
626 } | 626 } |
627 | 627 |
628 TextureInfo::LevelInfo& info = level_infos_[face_index][level]; | 628 Texture::LevelInfo& info = level_infos_[face_index][level]; |
629 | 629 |
630 return info.cleared; | 630 return info.cleared; |
631 } | 631 } |
632 | 632 |
633 bool TextureManager::TextureInfo::ClearLevel( | 633 bool Texture::ClearLevel( |
634 GLES2Decoder* decoder, GLenum target, GLint level) { | 634 GLES2Decoder* decoder, GLenum target, GLint level) { |
635 DCHECK(decoder); | 635 DCHECK(decoder); |
636 size_t face_index = GLTargetToFaceIndex(target); | 636 size_t face_index = GLTargetToFaceIndex(target); |
637 if (face_index >= level_infos_.size() || | 637 if (face_index >= level_infos_.size() || |
638 level >= static_cast<GLint>(level_infos_[face_index].size())) { | 638 level >= static_cast<GLint>(level_infos_[face_index].size())) { |
639 return true; | 639 return true; |
640 } | 640 } |
641 | 641 |
642 TextureInfo::LevelInfo& info = level_infos_[face_index][level]; | 642 Texture::LevelInfo& info = level_infos_[face_index][level]; |
643 | 643 |
644 DCHECK(target == info.target); | 644 DCHECK(target == info.target); |
645 | 645 |
646 if (info.target == 0 || | 646 if (info.target == 0 || |
647 info.cleared || | 647 info.cleared || |
648 info.width == 0 || | 648 info.width == 0 || |
649 info.height == 0 || | 649 info.height == 0 || |
650 info.depth == 0) { | 650 info.depth == 0) { |
651 return true; | 651 return true; |
652 } | 652 } |
653 | 653 |
654 DCHECK_NE(0, num_uncleared_mips_); | 654 DCHECK_NE(0, num_uncleared_mips_); |
655 --num_uncleared_mips_; | 655 --num_uncleared_mips_; |
656 | 656 |
657 // NOTE: It seems kind of gross to call back into the decoder for this | 657 // NOTE: It seems kind of gross to call back into the decoder for this |
658 // but only the decoder knows all the state (like unpack_alignment_) that's | 658 // but only the decoder knows all the state (like unpack_alignment_) that's |
659 // needed to be able to call GL correctly. | 659 // needed to be able to call GL correctly. |
660 info.cleared = decoder->ClearLevel( | 660 info.cleared = decoder->ClearLevel( |
661 service_id_, target_, info.target, info.level, info.format, info.type, | 661 service_id_, target_, info.target, info.level, info.format, info.type, |
662 info.width, info.height, immutable_); | 662 info.width, info.height, immutable_); |
663 if (!info.cleared) { | 663 if (!info.cleared) { |
664 ++num_uncleared_mips_; | 664 ++num_uncleared_mips_; |
665 } | 665 } |
666 return info.cleared; | 666 return info.cleared; |
667 } | 667 } |
668 | 668 |
669 void TextureManager::TextureInfo::SetLevelImage( | 669 void Texture::SetLevelImage( |
670 const FeatureInfo* feature_info, | 670 const FeatureInfo* feature_info, |
671 GLenum target, | 671 GLenum target, |
672 GLint level, | 672 GLint level, |
673 gfx::GLImage* image) { | 673 gfx::GLImage* image) { |
674 DCHECK_GE(level, 0); | 674 DCHECK_GE(level, 0); |
675 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), | 675 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
676 level_infos_.size()); | 676 level_infos_.size()); |
677 DCHECK_LT(static_cast<size_t>(level), | 677 DCHECK_LT(static_cast<size_t>(level), |
678 level_infos_[GLTargetToFaceIndex(target)].size()); | 678 level_infos_[GLTargetToFaceIndex(target)].size()); |
679 TextureInfo::LevelInfo& info = | 679 Texture::LevelInfo& info = |
680 level_infos_[GLTargetToFaceIndex(target)][level]; | 680 level_infos_[GLTargetToFaceIndex(target)][level]; |
681 DCHECK_EQ(info.target, target); | 681 DCHECK_EQ(info.target, target); |
682 DCHECK_EQ(info.level, level); | 682 DCHECK_EQ(info.level, level); |
683 info.image = image; | 683 info.image = image; |
684 } | 684 } |
685 | 685 |
686 gfx::GLImage* TextureManager::TextureInfo::GetLevelImage( | 686 gfx::GLImage* Texture::GetLevelImage( |
687 GLint target, GLint level) const { | 687 GLint target, GLint level) const { |
688 size_t face_index = GLTargetToFaceIndex(target); | 688 size_t face_index = GLTargetToFaceIndex(target); |
689 if (level >= 0 && face_index < level_infos_.size() && | 689 if (level >= 0 && face_index < level_infos_.size() && |
690 static_cast<size_t>(level) < level_infos_[face_index].size()) { | 690 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
691 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 691 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
692 if (info.target != 0) { | 692 if (info.target != 0) { |
693 return info.image; | 693 return info.image; |
694 } | 694 } |
695 } | 695 } |
696 return 0; | 696 return 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 } | 740 } |
741 | 741 |
742 if (feature_info_->feature_flags().arb_texture_rectangle) { | 742 if (feature_info_->feature_flags().arb_texture_rectangle) { |
743 default_textures_[kRectangleARB] = CreateDefaultAndBlackTextures( | 743 default_textures_[kRectangleARB] = CreateDefaultAndBlackTextures( |
744 GL_TEXTURE_RECTANGLE_ARB, &black_texture_ids_[kRectangleARB]); | 744 GL_TEXTURE_RECTANGLE_ARB, &black_texture_ids_[kRectangleARB]); |
745 } | 745 } |
746 | 746 |
747 return true; | 747 return true; |
748 } | 748 } |
749 | 749 |
750 TextureManager::TextureInfo::Ref TextureManager::CreateDefaultAndBlackTextures( | 750 scoped_refptr<Texture> |
751 GLenum target, | 751 TextureManager::CreateDefaultAndBlackTextures( |
752 GLuint* black_texture) { | 752 GLenum target, |
| 753 GLuint* black_texture) { |
753 static uint8 black[] = {0, 0, 0, 255}; | 754 static uint8 black[] = {0, 0, 0, 255}; |
754 | 755 |
755 // Sampling a texture not associated with any EGLImage sibling will return | 756 // Sampling a texture not associated with any EGLImage sibling will return |
756 // black values according to the spec. | 757 // black values according to the spec. |
757 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); | 758 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); |
758 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); | 759 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); |
759 | 760 |
760 // Make default textures and texture for replacing non-renderable textures. | 761 // Make default textures and texture for replacing non-renderable textures. |
761 GLuint ids[2]; | 762 GLuint ids[2]; |
762 glGenTextures(arraysize(ids), ids); | 763 glGenTextures(arraysize(ids), ids); |
763 for (unsigned long ii = 0; ii < arraysize(ids); ++ii) { | 764 for (unsigned long ii = 0; ii < arraysize(ids); ++ii) { |
764 glBindTexture(target, ids[ii]); | 765 glBindTexture(target, ids[ii]); |
765 if (needs_initialization) { | 766 if (needs_initialization) { |
766 if (needs_faces) { | 767 if (needs_faces) { |
767 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) { | 768 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) { |
768 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0, | 769 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0, |
769 GL_RGBA, GL_UNSIGNED_BYTE, black); | 770 GL_RGBA, GL_UNSIGNED_BYTE, black); |
770 } | 771 } |
771 } else { | 772 } else { |
772 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | 773 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
773 GL_UNSIGNED_BYTE, black); | 774 GL_UNSIGNED_BYTE, black); |
774 } | 775 } |
775 } | 776 } |
776 } | 777 } |
777 glBindTexture(target, 0); | 778 glBindTexture(target, 0); |
778 | 779 |
779 // Since we are manually setting up these textures | 780 // Since we are manually setting up these textures |
780 // we need to manually manipulate some of the their bookkeeping. | 781 // we need to manually manipulate some of the their bookkeeping. |
781 ++num_unrenderable_textures_; | 782 ++num_unrenderable_textures_; |
782 TextureInfo::Ref default_texture = TextureInfo::Ref( | 783 scoped_refptr<Texture> default_texture(new Texture(this, ids[1])); |
783 new TextureInfo(this, ids[1])); | |
784 SetInfoTarget(default_texture, target); | 784 SetInfoTarget(default_texture, target); |
785 if (needs_faces) { | 785 if (needs_faces) { |
786 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 786 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
787 SetLevelInfo( | 787 SetLevelInfo( |
788 default_texture, GLES2Util::IndexToGLFaceTarget(ii), | 788 default_texture, GLES2Util::IndexToGLFaceTarget(ii), |
789 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); | 789 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); |
790 } | 790 } |
791 } else { | 791 } else { |
792 if (needs_initialization) { | 792 if (needs_initialization) { |
793 SetLevelInfo(default_texture, | 793 SetLevelInfo(default_texture, |
(...skipping 23 matching lines...) Expand all Loading... |
817 depth <= max_size && | 817 depth <= max_size && |
818 (level == 0 || feature_info_->feature_flags().npot_ok || | 818 (level == 0 || feature_info_->feature_flags().npot_ok || |
819 (!GLES2Util::IsNPOT(width) && | 819 (!GLES2Util::IsNPOT(width) && |
820 !GLES2Util::IsNPOT(height) && | 820 !GLES2Util::IsNPOT(height) && |
821 !GLES2Util::IsNPOT(depth))) && | 821 !GLES2Util::IsNPOT(depth))) && |
822 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && | 822 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && |
823 (target != GL_TEXTURE_2D || (depth == 1)); | 823 (target != GL_TEXTURE_2D || (depth == 1)); |
824 } | 824 } |
825 | 825 |
826 void TextureManager::SetInfoTarget( | 826 void TextureManager::SetInfoTarget( |
827 TextureManager::TextureInfo* info, GLenum target) { | 827 Texture* info, GLenum target) { |
828 DCHECK(info); | 828 DCHECK(info); |
829 if (!info->CanRender(feature_info_)) { | 829 if (!info->CanRender(feature_info_)) { |
830 DCHECK_NE(0, num_unrenderable_textures_); | 830 DCHECK_NE(0, num_unrenderable_textures_); |
831 --num_unrenderable_textures_; | 831 --num_unrenderable_textures_; |
832 } | 832 } |
833 info->SetTarget(target, MaxLevelsForTarget(target)); | 833 info->SetTarget(target, MaxLevelsForTarget(target)); |
834 if (!info->CanRender(feature_info_)) { | 834 if (!info->CanRender(feature_info_)) { |
835 ++num_unrenderable_textures_; | 835 ++num_unrenderable_textures_; |
836 } | 836 } |
837 } | 837 } |
838 | 838 |
839 void TextureManager::SetLevelCleared(TextureManager::TextureInfo* info, | 839 void TextureManager::SetLevelCleared(Texture* info, |
840 GLenum target, | 840 GLenum target, |
841 GLint level, | 841 GLint level, |
842 bool cleared) { | 842 bool cleared) { |
843 DCHECK(info); | 843 DCHECK(info); |
844 if (!info->SafeToRenderFrom()) { | 844 if (!info->SafeToRenderFrom()) { |
845 DCHECK_NE(0, num_unsafe_textures_); | 845 DCHECK_NE(0, num_unsafe_textures_); |
846 --num_unsafe_textures_; | 846 --num_unsafe_textures_; |
847 } | 847 } |
848 num_uncleared_mips_ -= info->num_uncleared_mips(); | 848 num_uncleared_mips_ -= info->num_uncleared_mips(); |
849 DCHECK_GE(num_uncleared_mips_, 0); | 849 DCHECK_GE(num_uncleared_mips_, 0); |
850 info->SetLevelCleared(target, level, cleared); | 850 info->SetLevelCleared(target, level, cleared); |
851 num_uncleared_mips_ += info->num_uncleared_mips(); | 851 num_uncleared_mips_ += info->num_uncleared_mips(); |
852 if (!info->SafeToRenderFrom()) { | 852 if (!info->SafeToRenderFrom()) { |
853 ++num_unsafe_textures_; | 853 ++num_unsafe_textures_; |
854 } | 854 } |
855 } | 855 } |
856 | 856 |
857 bool TextureManager::ClearRenderableLevels( | 857 bool TextureManager::ClearRenderableLevels( |
858 GLES2Decoder* decoder,TextureManager::TextureInfo* info) { | 858 GLES2Decoder* decoder,Texture* info) { |
859 DCHECK(info); | 859 DCHECK(info); |
860 if (info->SafeToRenderFrom()) { | 860 if (info->SafeToRenderFrom()) { |
861 return true; | 861 return true; |
862 } | 862 } |
863 DCHECK_NE(0, num_unsafe_textures_); | 863 DCHECK_NE(0, num_unsafe_textures_); |
864 --num_unsafe_textures_; | 864 --num_unsafe_textures_; |
865 num_uncleared_mips_ -= info->num_uncleared_mips(); | 865 num_uncleared_mips_ -= info->num_uncleared_mips(); |
866 DCHECK_GE(num_uncleared_mips_, 0); | 866 DCHECK_GE(num_uncleared_mips_, 0); |
867 bool result = info->ClearRenderableLevels(decoder); | 867 bool result = info->ClearRenderableLevels(decoder); |
868 num_uncleared_mips_ += info->num_uncleared_mips(); | 868 num_uncleared_mips_ += info->num_uncleared_mips(); |
869 if (!info->SafeToRenderFrom()) { | 869 if (!info->SafeToRenderFrom()) { |
870 ++num_unsafe_textures_; | 870 ++num_unsafe_textures_; |
871 } | 871 } |
872 return result; | 872 return result; |
873 } | 873 } |
874 | 874 |
875 bool TextureManager::ClearTextureLevel( | 875 bool TextureManager::ClearTextureLevel( |
876 GLES2Decoder* decoder,TextureManager::TextureInfo* info, | 876 GLES2Decoder* decoder,Texture* info, |
877 GLenum target, GLint level) { | 877 GLenum target, GLint level) { |
878 DCHECK(info); | 878 DCHECK(info); |
879 if (info->num_uncleared_mips() == 0) { | 879 if (info->num_uncleared_mips() == 0) { |
880 return true; | 880 return true; |
881 } | 881 } |
882 num_uncleared_mips_ -= info->num_uncleared_mips(); | 882 num_uncleared_mips_ -= info->num_uncleared_mips(); |
883 DCHECK_GE(num_uncleared_mips_, 0); | 883 DCHECK_GE(num_uncleared_mips_, 0); |
884 if (!info->SafeToRenderFrom()) { | 884 if (!info->SafeToRenderFrom()) { |
885 DCHECK_NE(0, num_unsafe_textures_); | 885 DCHECK_NE(0, num_unsafe_textures_); |
886 --num_unsafe_textures_; | 886 --num_unsafe_textures_; |
887 } | 887 } |
888 bool result = info->ClearLevel(decoder, target, level); | 888 bool result = info->ClearLevel(decoder, target, level); |
889 info->UpdateCleared(); | 889 info->UpdateCleared(); |
890 num_uncleared_mips_ += info->num_uncleared_mips(); | 890 num_uncleared_mips_ += info->num_uncleared_mips(); |
891 if (!info->SafeToRenderFrom()) { | 891 if (!info->SafeToRenderFrom()) { |
892 ++num_unsafe_textures_; | 892 ++num_unsafe_textures_; |
893 } | 893 } |
894 return result; | 894 return result; |
895 } | 895 } |
896 | 896 |
897 void TextureManager::SetLevelInfo( | 897 void TextureManager::SetLevelInfo( |
898 TextureManager::TextureInfo* info, | 898 Texture* info, |
899 GLenum target, | 899 GLenum target, |
900 GLint level, | 900 GLint level, |
901 GLenum internal_format, | 901 GLenum internal_format, |
902 GLsizei width, | 902 GLsizei width, |
903 GLsizei height, | 903 GLsizei height, |
904 GLsizei depth, | 904 GLsizei depth, |
905 GLint border, | 905 GLint border, |
906 GLenum format, | 906 GLenum format, |
907 GLenum type, | 907 GLenum type, |
908 bool cleared) { | 908 bool cleared) { |
(...skipping 17 matching lines...) Expand all Loading... |
926 | 926 |
927 num_uncleared_mips_ += info->num_uncleared_mips(); | 927 num_uncleared_mips_ += info->num_uncleared_mips(); |
928 if (!info->CanRender(feature_info_)) { | 928 if (!info->CanRender(feature_info_)) { |
929 ++num_unrenderable_textures_; | 929 ++num_unrenderable_textures_; |
930 } | 930 } |
931 if (!info->SafeToRenderFrom()) { | 931 if (!info->SafeToRenderFrom()) { |
932 ++num_unsafe_textures_; | 932 ++num_unsafe_textures_; |
933 } | 933 } |
934 } | 934 } |
935 | 935 |
936 TextureDefinition* TextureManager::Save(TextureInfo* info) { | 936 TextureDefinition* TextureManager::Save(Texture* info) { |
937 DCHECK(info->owned_); | 937 DCHECK(info->owned_); |
938 | 938 |
939 if (info->IsAttachedToFramebuffer()) | 939 if (info->IsAttachedToFramebuffer()) |
940 return NULL; | 940 return NULL; |
941 | 941 |
942 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); | 942 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); |
943 for (size_t face = 0; face < level_infos.size(); ++face) { | 943 for (size_t face = 0; face < level_infos.size(); ++face) { |
944 GLenum target = info->target() == GL_TEXTURE_2D ? | 944 GLenum target = info->target() == GL_TEXTURE_2D ? |
945 GL_TEXTURE_2D : FaceIndexToGLTarget(face); | 945 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
946 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { | 946 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
947 const TextureInfo::LevelInfo& level_info = | 947 const Texture::LevelInfo& level_info = |
948 info->level_infos_[face][level]; | 948 info->level_infos_[face][level]; |
949 level_infos[face].push_back( | 949 level_infos[face].push_back( |
950 TextureDefinition::LevelInfo(target, | 950 TextureDefinition::LevelInfo(target, |
951 level_info.internal_format, | 951 level_info.internal_format, |
952 level_info.width, | 952 level_info.width, |
953 level_info.height, | 953 level_info.height, |
954 level_info.depth, | 954 level_info.depth, |
955 level_info.border, | 955 level_info.border, |
956 level_info.format, | 956 level_info.format, |
957 level_info.type, | 957 level_info.type, |
(...skipping 25 matching lines...) Expand all Loading... |
983 old_service_id, | 983 old_service_id, |
984 info->min_filter(), | 984 info->min_filter(), |
985 info->mag_filter(), | 985 info->mag_filter(), |
986 info->wrap_s(), | 986 info->wrap_s(), |
987 info->wrap_t(), | 987 info->wrap_t(), |
988 info->usage(), | 988 info->usage(), |
989 immutable, | 989 immutable, |
990 level_infos); | 990 level_infos); |
991 } | 991 } |
992 | 992 |
993 bool TextureManager::Restore(TextureInfo* info, | 993 bool TextureManager::Restore(Texture* info, |
994 TextureDefinition* definition) { | 994 TextureDefinition* definition) { |
995 DCHECK(info->owned_); | 995 DCHECK(info->owned_); |
996 | 996 |
997 scoped_ptr<TextureDefinition> scoped_definition(definition); | 997 scoped_ptr<TextureDefinition> scoped_definition(definition); |
998 | 998 |
999 if (info->IsAttachedToFramebuffer()) | 999 if (info->IsAttachedToFramebuffer()) |
1000 return false; | 1000 return false; |
1001 | 1001 |
1002 if (info->target() != definition->target()) | 1002 if (info->target() != definition->target()) |
1003 return false; | 1003 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 SetParameter(info, GL_TEXTURE_MIN_FILTER, definition->min_filter()); | 1035 SetParameter(info, GL_TEXTURE_MIN_FILTER, definition->min_filter()); |
1036 SetParameter(info, GL_TEXTURE_MAG_FILTER, definition->mag_filter()); | 1036 SetParameter(info, GL_TEXTURE_MAG_FILTER, definition->mag_filter()); |
1037 SetParameter(info, GL_TEXTURE_WRAP_S, definition->wrap_s()); | 1037 SetParameter(info, GL_TEXTURE_WRAP_S, definition->wrap_s()); |
1038 SetParameter(info, GL_TEXTURE_WRAP_T, definition->wrap_t()); | 1038 SetParameter(info, GL_TEXTURE_WRAP_T, definition->wrap_t()); |
1039 SetParameter(info, GL_TEXTURE_USAGE_ANGLE, definition->usage()); | 1039 SetParameter(info, GL_TEXTURE_USAGE_ANGLE, definition->usage()); |
1040 | 1040 |
1041 return true; | 1041 return true; |
1042 } | 1042 } |
1043 | 1043 |
1044 GLenum TextureManager::SetParameter( | 1044 GLenum TextureManager::SetParameter( |
1045 TextureManager::TextureInfo* info, GLenum pname, GLint param) { | 1045 Texture* info, GLenum pname, GLint param) { |
1046 DCHECK(info); | 1046 DCHECK(info); |
1047 if (!info->CanRender(feature_info_)) { | 1047 if (!info->CanRender(feature_info_)) { |
1048 DCHECK_NE(0, num_unrenderable_textures_); | 1048 DCHECK_NE(0, num_unrenderable_textures_); |
1049 --num_unrenderable_textures_; | 1049 --num_unrenderable_textures_; |
1050 } | 1050 } |
1051 if (!info->SafeToRenderFrom()) { | 1051 if (!info->SafeToRenderFrom()) { |
1052 DCHECK_NE(0, num_unsafe_textures_); | 1052 DCHECK_NE(0, num_unsafe_textures_); |
1053 --num_unsafe_textures_; | 1053 --num_unsafe_textures_; |
1054 } | 1054 } |
1055 GLenum result = info->SetParameter(feature_info_, pname, param); | 1055 GLenum result = info->SetParameter(feature_info_, pname, param); |
1056 if (!info->CanRender(feature_info_)) { | 1056 if (!info->CanRender(feature_info_)) { |
1057 ++num_unrenderable_textures_; | 1057 ++num_unrenderable_textures_; |
1058 } | 1058 } |
1059 if (!info->SafeToRenderFrom()) { | 1059 if (!info->SafeToRenderFrom()) { |
1060 ++num_unsafe_textures_; | 1060 ++num_unsafe_textures_; |
1061 } | 1061 } |
1062 return result; | 1062 return result; |
1063 } | 1063 } |
1064 | 1064 |
1065 bool TextureManager::MarkMipmapsGenerated(TextureManager::TextureInfo* info) { | 1065 bool TextureManager::MarkMipmapsGenerated(Texture* info) { |
1066 DCHECK(info); | 1066 DCHECK(info); |
1067 if (!info->CanRender(feature_info_)) { | 1067 if (!info->CanRender(feature_info_)) { |
1068 DCHECK_NE(0, num_unrenderable_textures_); | 1068 DCHECK_NE(0, num_unrenderable_textures_); |
1069 --num_unrenderable_textures_; | 1069 --num_unrenderable_textures_; |
1070 } | 1070 } |
1071 if (!info->SafeToRenderFrom()) { | 1071 if (!info->SafeToRenderFrom()) { |
1072 DCHECK_NE(0, num_unsafe_textures_); | 1072 DCHECK_NE(0, num_unsafe_textures_); |
1073 --num_unsafe_textures_; | 1073 --num_unsafe_textures_; |
1074 } | 1074 } |
1075 num_uncleared_mips_ -= info->num_uncleared_mips(); | 1075 num_uncleared_mips_ -= info->num_uncleared_mips(); |
1076 DCHECK_GE(num_uncleared_mips_, 0); | 1076 DCHECK_GE(num_uncleared_mips_, 0); |
1077 GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); | 1077 GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); |
1078 bool result = info->MarkMipmapsGenerated(feature_info_); | 1078 bool result = info->MarkMipmapsGenerated(feature_info_); |
1079 GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); | 1079 GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); |
1080 | 1080 |
1081 num_uncleared_mips_ += info->num_uncleared_mips(); | 1081 num_uncleared_mips_ += info->num_uncleared_mips(); |
1082 if (!info->CanRender(feature_info_)) { | 1082 if (!info->CanRender(feature_info_)) { |
1083 ++num_unrenderable_textures_; | 1083 ++num_unrenderable_textures_; |
1084 } | 1084 } |
1085 if (!info->SafeToRenderFrom()) { | 1085 if (!info->SafeToRenderFrom()) { |
1086 ++num_unsafe_textures_; | 1086 ++num_unsafe_textures_; |
1087 } | 1087 } |
1088 return result; | 1088 return result; |
1089 } | 1089 } |
1090 | 1090 |
1091 TextureManager::TextureInfo* TextureManager::CreateTextureInfo( | 1091 Texture* TextureManager::CreateTexture( |
1092 GLuint client_id, GLuint service_id) { | 1092 GLuint client_id, GLuint service_id) { |
1093 DCHECK_NE(0u, service_id); | 1093 DCHECK_NE(0u, service_id); |
1094 TextureInfo::Ref info(new TextureInfo(this, service_id)); | 1094 scoped_refptr<Texture> info(new Texture(this, service_id)); |
1095 std::pair<TextureInfoMap::iterator, bool> result = | 1095 std::pair<TextureInfoMap::iterator, bool> result = |
1096 texture_infos_.insert(std::make_pair(client_id, info)); | 1096 texture_infos_.insert(std::make_pair(client_id, info)); |
1097 DCHECK(result.second); | 1097 DCHECK(result.second); |
1098 if (!info->CanRender(feature_info_)) { | 1098 if (!info->CanRender(feature_info_)) { |
1099 ++num_unrenderable_textures_; | 1099 ++num_unrenderable_textures_; |
1100 } | 1100 } |
1101 if (!info->SafeToRenderFrom()) { | 1101 if (!info->SafeToRenderFrom()) { |
1102 ++num_unsafe_textures_; | 1102 ++num_unsafe_textures_; |
1103 } | 1103 } |
1104 num_uncleared_mips_ += info->num_uncleared_mips(); | 1104 num_uncleared_mips_ += info->num_uncleared_mips(); |
1105 return info.get(); | 1105 return info.get(); |
1106 } | 1106 } |
1107 | 1107 |
1108 TextureManager::TextureInfo* TextureManager::GetTextureInfo( | 1108 Texture* TextureManager::GetTexture( |
1109 GLuint client_id) const { | 1109 GLuint client_id) const { |
1110 TextureInfoMap::const_iterator it = texture_infos_.find(client_id); | 1110 TextureInfoMap::const_iterator it = texture_infos_.find(client_id); |
1111 return it != texture_infos_.end() ? it->second : NULL; | 1111 return it != texture_infos_.end() ? it->second : NULL; |
1112 } | 1112 } |
1113 | 1113 |
1114 void TextureManager::RemoveTextureInfo(GLuint client_id) { | 1114 void TextureManager::RemoveTexture(GLuint client_id) { |
1115 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 1115 TextureInfoMap::iterator it = texture_infos_.find(client_id); |
1116 if (it != texture_infos_.end()) { | 1116 if (it != texture_infos_.end()) { |
1117 TextureInfo* info = it->second; | 1117 Texture* info = it->second; |
1118 info->MarkAsDeleted(); | 1118 info->MarkAsDeleted(); |
1119 texture_infos_.erase(it); | 1119 texture_infos_.erase(it); |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 void TextureManager::StartTracking(TextureManager::TextureInfo* /* texture */) { | 1123 void TextureManager::StartTracking(Texture* /* texture */) { |
1124 ++texture_info_count_; | 1124 ++texture_info_count_; |
1125 } | 1125 } |
1126 | 1126 |
1127 void TextureManager::StopTracking(TextureManager::TextureInfo* texture) { | 1127 void TextureManager::StopTracking(Texture* texture) { |
1128 --texture_info_count_; | 1128 --texture_info_count_; |
1129 if (!texture->CanRender(feature_info_)) { | 1129 if (!texture->CanRender(feature_info_)) { |
1130 DCHECK_NE(0, num_unrenderable_textures_); | 1130 DCHECK_NE(0, num_unrenderable_textures_); |
1131 --num_unrenderable_textures_; | 1131 --num_unrenderable_textures_; |
1132 } | 1132 } |
1133 if (!texture->SafeToRenderFrom()) { | 1133 if (!texture->SafeToRenderFrom()) { |
1134 DCHECK_NE(0, num_unsafe_textures_); | 1134 DCHECK_NE(0, num_unsafe_textures_); |
1135 --num_unsafe_textures_; | 1135 --num_unsafe_textures_; |
1136 } | 1136 } |
1137 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1137 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
(...skipping 27 matching lines...) Expand all Loading... |
1165 } | 1165 } |
1166 return false; | 1166 return false; |
1167 } | 1167 } |
1168 | 1168 |
1169 GLsizei TextureManager::ComputeMipMapCount( | 1169 GLsizei TextureManager::ComputeMipMapCount( |
1170 GLsizei width, GLsizei height, GLsizei depth) { | 1170 GLsizei width, GLsizei height, GLsizei depth) { |
1171 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1171 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
1172 } | 1172 } |
1173 | 1173 |
1174 void TextureManager::SetLevelImage( | 1174 void TextureManager::SetLevelImage( |
1175 TextureManager::TextureInfo* info, | 1175 Texture* info, |
1176 GLenum target, | 1176 GLenum target, |
1177 GLint level, | 1177 GLint level, |
1178 gfx::GLImage* image) { | 1178 gfx::GLImage* image) { |
1179 DCHECK(info); | 1179 DCHECK(info); |
1180 if (!info->CanRender(feature_info_)) { | 1180 if (!info->CanRender(feature_info_)) { |
1181 DCHECK_NE(0, num_unrenderable_textures_); | 1181 DCHECK_NE(0, num_unrenderable_textures_); |
1182 --num_unrenderable_textures_; | 1182 --num_unrenderable_textures_; |
1183 } | 1183 } |
1184 if (!info->SafeToRenderFrom()) { | 1184 if (!info->SafeToRenderFrom()) { |
1185 DCHECK_NE(0, num_unsafe_textures_); | 1185 DCHECK_NE(0, num_unsafe_textures_); |
1186 --num_unsafe_textures_; | 1186 --num_unsafe_textures_; |
1187 } | 1187 } |
1188 info->SetLevelImage(feature_info_, target, level, image); | 1188 info->SetLevelImage(feature_info_, target, level, image); |
1189 if (!info->CanRender(feature_info_)) { | 1189 if (!info->CanRender(feature_info_)) { |
1190 ++num_unrenderable_textures_; | 1190 ++num_unrenderable_textures_; |
1191 } | 1191 } |
1192 if (!info->SafeToRenderFrom()) { | 1192 if (!info->SafeToRenderFrom()) { |
1193 ++num_unsafe_textures_; | 1193 ++num_unsafe_textures_; |
1194 } | 1194 } |
1195 } | 1195 } |
1196 | 1196 |
1197 void TextureManager::AddToSignature( | 1197 void TextureManager::AddToSignature( |
1198 TextureInfo* info, | 1198 Texture* info, |
1199 GLenum target, | 1199 GLenum target, |
1200 GLint level, | 1200 GLint level, |
1201 std::string* signature) const { | 1201 std::string* signature) const { |
1202 info->AddToSignature(feature_info_.get(), target, level, signature); | 1202 info->AddToSignature(feature_info_.get(), target, level, signature); |
1203 } | 1203 } |
1204 | 1204 |
1205 void TextureManager::AddPendingAsyncPixelTransfer( | 1205 void TextureManager::AddPendingAsyncPixelTransfer( |
1206 base::WeakPtr<gfx::AsyncPixelTransferState> state, TextureInfo* info) { | 1206 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* info) { |
1207 pending_async_transfers_.push_back(PendingAsyncTransfer(state,info)); | 1207 pending_async_transfers_.push_back(PendingAsyncTransfer(state,info)); |
1208 } | 1208 } |
1209 | 1209 |
1210 void TextureManager::BindFinishedAsyncPixelTransfers( | 1210 void TextureManager::BindFinishedAsyncPixelTransfers( |
1211 bool* texture_dirty, bool* framebuffer_dirty) { | 1211 bool* texture_dirty, bool* framebuffer_dirty) { |
1212 DCHECK(texture_dirty); | 1212 DCHECK(texture_dirty); |
1213 DCHECK(framebuffer_dirty); | 1213 DCHECK(framebuffer_dirty); |
1214 *texture_dirty = false; | 1214 *texture_dirty = false; |
1215 *framebuffer_dirty = false; | 1215 *framebuffer_dirty = false; |
1216 | 1216 |
1217 // Remove finished transfers from the list, while | 1217 // Remove finished transfers from the list, while |
1218 // marking whether texture unit 0 or frame_buffer status is dirty. | 1218 // marking whether texture unit 0 or frame_buffer status is dirty. |
1219 while(!pending_async_transfers_.empty()) { | 1219 while(!pending_async_transfers_.empty()) { |
1220 PendingAsyncTransfer state_info = pending_async_transfers_.front(); | 1220 PendingAsyncTransfer state_info = pending_async_transfers_.front(); |
1221 if (!state_info.first.get()) { | 1221 if (!state_info.first.get()) { |
1222 // The AsyncState is owned by the TextureInfo. So if the | 1222 // The AsyncState is owned by the Texture. So if the |
1223 // async state is deleted, so is the TextureInfo. | 1223 // async state is deleted, so is the Texture. |
1224 pending_async_transfers_.pop_front(); | 1224 pending_async_transfers_.pop_front(); |
1225 continue; | 1225 continue; |
1226 } | 1226 } |
1227 // Terminate early, as all transfers finish in order. | 1227 // Terminate early, as all transfers finish in order. |
1228 if (state_info.first->TransferIsInProgress()) | 1228 if (state_info.first->TransferIsInProgress()) |
1229 break; | 1229 break; |
1230 // If the transfer is finished, bind it to the texture, | 1230 // If the transfer is finished, bind it to the texture, |
1231 // update the TextureInfo, and remove it from pending list. | 1231 // update the Texture, and remove it from pending list. |
1232 *texture_dirty = true; | 1232 *texture_dirty = true; |
1233 *framebuffer_dirty |= state_info.second->IsAttachedToFramebuffer(); | 1233 *framebuffer_dirty |= state_info.second->IsAttachedToFramebuffer(); |
1234 gfx::AsyncTexImage2DParams tex_define_params; | 1234 gfx::AsyncTexImage2DParams tex_define_params; |
1235 state_info.second-> | 1235 state_info.second-> |
1236 GetAsyncTransferState()->BindTransfer(&tex_define_params); | 1236 GetAsyncTransferState()->BindTransfer(&tex_define_params); |
1237 SetLevelInfo( | 1237 SetLevelInfo( |
1238 state_info.second, | 1238 state_info.second, |
1239 tex_define_params.target, | 1239 tex_define_params.target, |
1240 tex_define_params.level, | 1240 tex_define_params.level, |
1241 tex_define_params.internal_format, | 1241 tex_define_params.internal_format, |
1242 tex_define_params.width, | 1242 tex_define_params.width, |
1243 tex_define_params.height, | 1243 tex_define_params.height, |
1244 1, // depth | 1244 1, // depth |
1245 tex_define_params.border, | 1245 tex_define_params.border, |
1246 tex_define_params.format, | 1246 tex_define_params.format, |
1247 tex_define_params.type, | 1247 tex_define_params.type, |
1248 true); // cleared | 1248 true); // cleared |
1249 pending_async_transfers_.pop_front(); | 1249 pending_async_transfers_.pop_front(); |
1250 } | 1250 } |
1251 } | 1251 } |
1252 | 1252 |
1253 } // namespace gles2 | 1253 } // namespace gles2 |
1254 } // namespace gpu | 1254 } // namespace gpu |
OLD | NEW |