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

Side by Side Diff: gpu/command_buffer/service/texture_manager.h

Issue 14844004: gpu: Refactor to support cross-channel shared textures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix accidentally reverted behavior Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <set>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
16 #include "gpu/command_buffer/service/gl_utils.h" 17 #include "gpu/command_buffer/service/gl_utils.h"
17 #include "gpu/command_buffer/service/memory_tracking.h" 18 #include "gpu/command_buffer/service/memory_tracking.h"
18 #include "gpu/gpu_export.h" 19 #include "gpu/gpu_export.h"
19 #include "ui/gl/gl_image.h" 20 #include "ui/gl/gl_image.h"
20 21
21 namespace gpu { 22 namespace gpu {
22 namespace gles2 { 23 namespace gles2 {
23 24
24 class GLES2Decoder; 25 class GLES2Decoder;
25 class Display; 26 class Display;
26 class ErrorState; 27 class ErrorState;
27 class FeatureInfo; 28 class FeatureInfo;
29 class FramebufferManager;
28 class TextureDefinition; 30 class TextureDefinition;
29 class TextureManager; 31 class TextureManager;
32 class TextureRef;
30 33
31 // Info about Textures currently in the system. 34 // Info about Textures currently in the system.
32 class GPU_EXPORT Texture : public base::RefCounted<Texture> { 35 // This class wraps a real GL texture, keeping track of its meta-data. It is
36 // jointly owned by possibly multiple TextureRef.
37 class GPU_EXPORT Texture {
33 public: 38 public:
34 Texture(TextureManager* manager, GLuint service_id); 39 explicit Texture(GLuint service_id);
35 40
36 GLenum min_filter() const { 41 GLenum min_filter() const {
37 return min_filter_; 42 return min_filter_;
38 } 43 }
39 44
40 GLenum mag_filter() const { 45 GLenum mag_filter() const {
41 return mag_filter_; 46 return mag_filter_;
42 } 47 }
43 48
44 GLenum wrap_s() const { 49 GLenum wrap_s() const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 GLint target, GLint level, GLsizei* width, GLsizei* height) const; 100 GLint target, GLint level, GLsizei* width, GLsizei* height) const;
96 101
97 // Get the type of a level. Returns false if level does not exist. 102 // Get the type of a level. Returns false if level does not exist.
98 bool GetLevelType( 103 bool GetLevelType(
99 GLint target, GLint level, GLenum* type, GLenum* internal_format) const; 104 GLint target, GLint level, GLenum* type, GLenum* internal_format) const;
100 105
101 // Get the image bound to a particular level. Returns NULL if level 106 // Get the image bound to a particular level. Returns NULL if level
102 // does not exist. 107 // does not exist.
103 gfx::GLImage* GetLevelImage(GLint target, GLint level) const; 108 gfx::GLImage* GetLevelImage(GLint target, GLint level) const;
104 109
105 bool IsDeleted() const {
106 return deleted_;
107 }
108
109 // Returns true of the given dimensions are inside the dimensions of the 110 // Returns true of the given dimensions are inside the dimensions of the
110 // level and if the format and type match the level. 111 // level and if the format and type match the level.
111 bool ValidForTexture( 112 bool ValidForTexture(
112 GLint target, 113 GLint target,
113 GLint level, 114 GLint level,
114 GLint xoffset, 115 GLint xoffset,
115 GLint yoffset, 116 GLint yoffset,
116 GLsizei width, 117 GLsizei width,
117 GLsizei height, 118 GLsizei height,
118 GLenum format, 119 GLenum format,
119 GLenum type) const; 120 GLenum type) const;
120 121
121 bool IsValid() const { 122 bool IsValid() const {
122 return target() && !IsDeleted(); 123 return !!target();
123 } 124 }
124 125
125 void SetNotOwned() { 126 void SetNotOwned() {
126 owned_ = false; 127 owned_ = false;
127 } 128 }
128 129
129 bool IsAttachedToFramebuffer() const { 130 bool IsAttachedToFramebuffer() const {
130 return framebuffer_attachment_count_ != 0; 131 return framebuffer_attachment_count_ != 0;
131 } 132 }
132 133
133 void AttachToFramebuffer() { 134 void AttachToFramebuffer() {
134 ++framebuffer_attachment_count_; 135 ++framebuffer_attachment_count_;
135 } 136 }
136 137
137 void DetachFromFramebuffer() { 138 void DetachFromFramebuffer() {
138 DCHECK_GT(framebuffer_attachment_count_, 0); 139 DCHECK_GT(framebuffer_attachment_count_, 0);
139 --framebuffer_attachment_count_; 140 --framebuffer_attachment_count_;
140 } 141 }
141 142
142 bool IsStreamTexture() const { 143 bool IsStreamTexture() const {
143 return stream_texture_; 144 return stream_texture_;
144 } 145 }
145 146
146 gpu::AsyncPixelTransferState* GetAsyncTransferState() const { 147 // Gets the async transfer state for this texture. Note: the transfer state is
147 return async_transfer_state_.get(); 148 // owned by a single TextureRef.
148 } 149 AsyncPixelTransferState* GetAsyncTransferState() const;
149 void SetAsyncTransferState(scoped_ptr<gpu::AsyncPixelTransferState> state) { 150
150 async_transfer_state_ = state.Pass();
151 }
152 bool AsyncTransferIsInProgress() { 151 bool AsyncTransferIsInProgress() {
153 return async_transfer_state_ && 152 AsyncPixelTransferState* state = GetAsyncTransferState();
154 async_transfer_state_->TransferIsInProgress(); 153 return state && state->TransferIsInProgress();
155 } 154 }
156 155
157 void SetImmutable(bool immutable) { 156 void SetImmutable(bool immutable) {
158 immutable_ = immutable; 157 immutable_ = immutable;
159 } 158 }
160 159
161 bool IsImmutable() const { 160 bool IsImmutable() const {
162 return immutable_; 161 return immutable_;
163 } 162 }
164 163
165 // Whether a particular level/face is cleared. 164 // Whether a particular level/face is cleared.
166 bool IsLevelCleared(GLenum target, GLint level) const; 165 bool IsLevelCleared(GLenum target, GLint level) const;
167 166
168 // Whether the texture has been defined 167 // Whether the texture has been defined
169 bool IsDefined() const { 168 bool IsDefined() const {
170 return estimated_size() > 0; 169 return estimated_size() > 0;
171 } 170 }
172 171
173 private: 172 private:
174 friend class TextureManager; 173 friend class TextureManager;
174 friend class TextureRef;
175 friend class TextureTestHelper; 175 friend class TextureTestHelper;
176 friend class base::RefCounted<Texture>;
177 176
178 ~Texture(); 177 ~Texture();
178 void AddTextureRef(TextureRef* ref);
179 void RemoveTextureRef(TextureRef* ref, bool have_context);
180 MemoryTypeTracker* GetMemTracker();
181
182 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
183 // depends on context support for non-power-of-two textures (i.e. will be
184 // renderable if NPOT support is in the context, otherwise not, e.g. texture
185 // with a NPOT level). ALWAYS means it doesn't depend on context features
186 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
187 // incomplete).
188 enum CanRenderCondition {
189 CAN_RENDER_ALWAYS,
190 CAN_RENDER_NEVER,
191 CAN_RENDER_ONLY_IF_NPOT
192 };
179 193
180 struct LevelInfo { 194 struct LevelInfo {
181 LevelInfo(); 195 LevelInfo();
182 LevelInfo(const LevelInfo& rhs); 196 LevelInfo(const LevelInfo& rhs);
183 ~LevelInfo(); 197 ~LevelInfo();
184 198
185 bool cleared; 199 bool cleared;
186 GLenum target; 200 GLenum target;
187 GLint level; 201 GLint level;
188 GLenum internal_format; 202 GLenum internal_format;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return cube_complete_; 237 return cube_complete_;
224 } 238 }
225 239
226 // Whether or not this texture is a non-power-of-two texture. 240 // Whether or not this texture is a non-power-of-two texture.
227 bool npot() const { 241 bool npot() const {
228 return npot_; 242 return npot_;
229 } 243 }
230 244
231 void SetStreamTexture(bool stream_texture) { 245 void SetStreamTexture(bool stream_texture) {
232 stream_texture_ = stream_texture; 246 stream_texture_ = stream_texture;
247 UpdateCanRenderCondition();
233 } 248 }
234 249
235 // Marks a particular level as cleared or uncleared. 250 // Marks a particular level as cleared or uncleared.
236 void SetLevelCleared(GLenum target, GLint level, bool cleared); 251 void SetLevelCleared(GLenum target, GLint level, bool cleared);
237 252
238 // Updates the cleared flag for this texture by inspecting all the mips. 253 // Updates the cleared flag for this texture by inspecting all the mips.
239 void UpdateCleared(); 254 void UpdateCleared();
240 255
241 // Clears any renderable uncleared levels. 256 // Clears any renderable uncleared levels.
242 // Returns false if a GL error was generated. 257 // Returns false if a GL error was generated.
243 bool ClearRenderableLevels(GLES2Decoder* decoder); 258 bool ClearRenderableLevels(GLES2Decoder* decoder);
244 259
245 // Clears the level. 260 // Clears the level.
246 // Returns false if a GL error was generated. 261 // Returns false if a GL error was generated.
247 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); 262 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level);
248 263
249 // Sets a texture parameter. 264 // Sets a texture parameter.
250 // TODO(gman): Expand to SetParameteri,f,iv,fv 265 // TODO(gman): Expand to SetParameteri,f,iv,fv
251 // Returns GL_NO_ERROR on success. Otherwise the error to generate. 266 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
252 GLenum SetParameter( 267 GLenum SetParameter(
253 const FeatureInfo* feature_info, GLenum pname, GLint param); 268 const FeatureInfo* feature_info, GLenum pname, GLint param);
254 269
255 // Makes each of the mip levels as though they were generated. 270 // Makes each of the mip levels as though they were generated.
256 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); 271 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
257 272
258 void MarkAsDeleted() {
259 deleted_ = true;
260 }
261
262 bool NeedsMips() const { 273 bool NeedsMips() const {
263 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; 274 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR;
264 } 275 }
265 276
266 // True if this texture meets all the GLES2 criteria for rendering. 277 // True if this texture meets all the GLES2 criteria for rendering.
267 // See section 3.8.2 of the GLES2 spec. 278 // See section 3.8.2 of the GLES2 spec.
268 bool CanRender(const FeatureInfo* feature_info) const; 279 bool CanRender(const FeatureInfo* feature_info) const;
269 280
270 // Returns true if mipmaps can be generated by GL. 281 // Returns true if mipmaps can be generated by GL.
271 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; 282 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
(...skipping 14 matching lines...) Expand all
286 const FeatureInfo* feature_info, 297 const FeatureInfo* feature_info,
287 GLenum target, 298 GLenum target,
288 GLint level, 299 GLint level,
289 gfx::GLImage* image); 300 gfx::GLImage* image);
290 301
291 // Appends a signature for the given level. 302 // Appends a signature for the given level.
292 void AddToSignature( 303 void AddToSignature(
293 const FeatureInfo* feature_info, 304 const FeatureInfo* feature_info,
294 GLenum target, GLint level, std::string* signature) const; 305 GLenum target, GLint level, std::string* signature) const;
295 306
307 // Updates the unsafe textures count in all the managers referencing this
308 // texture.
309 void UpdateSafeToRenderFrom(bool cleared);
310
311 // Updates the uncleared mip count in all the managers referencing this
312 // texture.
313 void UpdateMipCleared(LevelInfo* info, bool cleared);
314
315 // Computes the CanRenderCondition flag.
316 CanRenderCondition GetCanRenderCondition() const;
317
318 // Updates the unrenderable texture count in all the managers referencing this
319 // texture.
320 void UpdateCanRenderCondition();
321
322 // Increment the framebuffer state change count in all the managers
323 // referencing this texture.
324 void IncAllFramebufferStateChangeCount();
325
296 // Info about each face and level of texture. 326 // Info about each face and level of texture.
297 std::vector<std::vector<LevelInfo> > level_infos_; 327 std::vector<std::vector<LevelInfo> > level_infos_;
298 328
299 // The texture manager that manages this Texture. 329 // The texture refs that point to this Texture.
300 TextureManager* manager_; 330 typedef std::set<TextureRef*> RefSet;
331 RefSet refs_;
332
333 // The single TextureRef that accounts for memory for this texture. Must be
334 // one of refs_.
335 TextureRef* memory_tracking_ref_;
301 336
302 // The id of the texure 337 // The id of the texure
303 GLuint service_id_; 338 GLuint service_id_;
304 339
305 // Whether this texture has been deleted.
306 bool deleted_;
307
308 // Whether all renderable mips of this texture have been cleared. 340 // Whether all renderable mips of this texture have been cleared.
309 bool cleared_; 341 bool cleared_;
310 342
311 int num_uncleared_mips_; 343 int num_uncleared_mips_;
312 344
313 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. 345 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
314 GLenum target_; 346 GLenum target_;
315 347
316 // Texture parameters. 348 // Texture parameters.
317 GLenum min_filter_; 349 GLenum min_filter_;
(...skipping 21 matching lines...) Expand all
339 // The number of framebuffers this texture is attached to. 371 // The number of framebuffers this texture is attached to.
340 int framebuffer_attachment_count_; 372 int framebuffer_attachment_count_;
341 373
342 // Whether the associated context group owns this texture and should delete 374 // Whether the associated context group owns this texture and should delete
343 // it. 375 // it.
344 bool owned_; 376 bool owned_;
345 377
346 // Whether this is a special streaming texture. 378 // Whether this is a special streaming texture.
347 bool stream_texture_; 379 bool stream_texture_;
348 380
349 // State to facilitate async transfers on this texture.
350 scoped_ptr<gpu::AsyncPixelTransferState> async_transfer_state_;
351
352 // Whether the texture is immutable and no further changes to the format 381 // Whether the texture is immutable and no further changes to the format
353 // or dimensions of the texture object can be made. 382 // or dimensions of the texture object can be made.
354 bool immutable_; 383 bool immutable_;
355 384
356 // Size in bytes this texture is assumed to take in memory. 385 // Size in bytes this texture is assumed to take in memory.
357 uint32 estimated_size_; 386 uint32 estimated_size_;
358 387
388 // Cache of the computed CanRenderCondition flag.
389 CanRenderCondition can_render_condition_;
390
359 DISALLOW_COPY_AND_ASSIGN(Texture); 391 DISALLOW_COPY_AND_ASSIGN(Texture);
360 }; 392 };
361 393
394 // This class represents a texture in a client context group. It's mostly 1:1
395 // with a client id, though it can outlive the client id if it's still bound to
396 // a FBO or another context when destroyed.
397 // Multiple TextureRef can point to the same texture with cross-context sharing.
398 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> {
399 public:
400 TextureRef(TextureManager* manager, Texture* texture);
401 static scoped_refptr<TextureRef> Create(TextureManager* manager,
402 GLuint service_id);
403 const Texture* texture() const { return texture_; }
404 Texture* texture() { return texture_; }
405 GLuint service_id() const { return texture_->service_id(); }
406
407 // Sets the async transfer state for this texture. Only a single TextureRef
408 // can set this on a given texture at any time.
409 // NOTE: this should be per-context rather than per-texture. crbug.com/240504
410 void SetAsyncTransferState(
411 scoped_ptr<AsyncPixelTransferState> state) {
412 DCHECK(!state || !texture_->GetAsyncTransferState());
413 async_transfer_state_ = state.Pass();
414 }
415
416 private:
417 friend class base::RefCounted<TextureRef>;
418 friend class Texture;
419 friend class TextureManager;
420
421 ~TextureRef();
422 const TextureManager* manager() const { return manager_; }
423 TextureManager* manager() { return manager_; }
424 AsyncPixelTransferState* async_transfer_state() const {
425 return async_transfer_state_.get();
426 }
427
428 TextureManager* manager_;
429 Texture* texture_;
430
431 // State to facilitate async transfers on this texture.
432 scoped_ptr<AsyncPixelTransferState> async_transfer_state_;
433
434 DISALLOW_COPY_AND_ASSIGN(TextureRef);
435 };
436
362 // This class keeps track of the textures and their sizes so we can do NPOT and 437 // This class keeps track of the textures and their sizes so we can do NPOT and
363 // texture complete checking. 438 // texture complete checking.
364 // 439 //
365 // NOTE: To support shared resources an instance of this class will need to be 440 // NOTE: To support shared resources an instance of this class will need to be
366 // shared by multiple GLES2Decoders. 441 // shared by multiple GLES2Decoders.
367 class GPU_EXPORT TextureManager { 442 class GPU_EXPORT TextureManager {
368 public: 443 public:
369 enum DefaultAndBlackTextures { 444 enum DefaultAndBlackTextures {
370 kTexture2D, 445 kTexture2D,
371 kCubeMap, 446 kCubeMap,
372 kExternalOES, 447 kExternalOES,
373 kRectangleARB, 448 kRectangleARB,
374 kNumDefaultTextures 449 kNumDefaultTextures
375 }; 450 };
376 451
377 TextureManager(MemoryTracker* memory_tracker, 452 TextureManager(MemoryTracker* memory_tracker,
378 FeatureInfo* feature_info, 453 FeatureInfo* feature_info,
379 GLsizei max_texture_size, 454 GLsizei max_texture_size,
380 GLsizei max_cube_map_texture_size); 455 GLsizei max_cube_map_texture_size);
381 ~TextureManager(); 456 ~TextureManager();
382 457
458 void set_framebuffer_manager(FramebufferManager* manager) {
459 framebuffer_manager_ = manager;
460 }
461
383 // Init the texture manager. 462 // Init the texture manager.
384 bool Initialize(); 463 bool Initialize();
385 464
386 // Must call before destruction. 465 // Must call before destruction.
387 void Destroy(bool have_context); 466 void Destroy(bool have_context);
388 467
389 // Returns the maximum number of levels. 468 // Returns the maximum number of levels.
390 GLint MaxLevelsForTarget(GLenum target) const { 469 GLint MaxLevelsForTarget(GLenum target) const {
391 switch (target) { 470 switch (target) {
392 case GL_TEXTURE_2D: 471 case GL_TEXTURE_2D:
(...skipping 20 matching lines...) Expand all
413 static GLsizei ComputeMipMapCount( 492 static GLsizei ComputeMipMapCount(
414 GLsizei width, GLsizei height, GLsizei depth); 493 GLsizei width, GLsizei height, GLsizei depth);
415 494
416 // Checks if a dimensions are valid for a given target. 495 // Checks if a dimensions are valid for a given target.
417 bool ValidForTarget( 496 bool ValidForTarget(
418 GLenum target, GLint level, 497 GLenum target, GLint level,
419 GLsizei width, GLsizei height, GLsizei depth); 498 GLsizei width, GLsizei height, GLsizei depth);
420 499
421 // True if this texture meets all the GLES2 criteria for rendering. 500 // True if this texture meets all the GLES2 criteria for rendering.
422 // See section 3.8.2 of the GLES2 spec. 501 // See section 3.8.2 of the GLES2 spec.
423 bool CanRender(const Texture* texture) const { 502 bool CanRender(const TextureRef* ref) const {
424 return texture->CanRender(feature_info_); 503 return ref->texture()->CanRender(feature_info_);
425 } 504 }
426 505
427 // Returns true if mipmaps can be generated by GL. 506 // Returns true if mipmaps can be generated by GL.
428 bool CanGenerateMipmaps(const Texture* texture) const { 507 bool CanGenerateMipmaps(const TextureRef* ref) const {
429 return texture->CanGenerateMipmaps(feature_info_); 508 return ref->texture()->CanGenerateMipmaps(feature_info_);
430 } 509 }
431 510
432 // Sets the Texture's target 511 // Sets the Texture's target
433 // Parameters: 512 // Parameters:
434 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP 513 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
435 // max_levels: The maximum levels this type of target can have. 514 // max_levels: The maximum levels this type of target can have.
436 void SetTarget( 515 void SetTarget(
437 Texture* texture, 516 TextureRef* ref,
438 GLenum target); 517 GLenum target);
439 518
440 // Marks a texture as a stream texture. 519 // Marks a texture as a stream texture.
441 void SetStreamTexture(Texture* texture, bool stream_texture); 520 void SetStreamTexture(TextureRef* ref, bool stream_texture);
442 521
443 // Set the info for a particular level in a TexureInfo. 522 // Set the info for a particular level in a TexureInfo.
444 void SetLevelInfo( 523 void SetLevelInfo(
445 Texture* texture, 524 TextureRef* ref,
446 GLenum target, 525 GLenum target,
447 GLint level, 526 GLint level,
448 GLenum internal_format, 527 GLenum internal_format,
449 GLsizei width, 528 GLsizei width,
450 GLsizei height, 529 GLsizei height,
451 GLsizei depth, 530 GLsizei depth,
452 GLint border, 531 GLint border,
453 GLenum format, 532 GLenum format,
454 GLenum type, 533 GLenum type,
455 bool cleared); 534 bool cleared);
456 535
457 // Adapter to call above function. 536 // Adapter to call above function.
458 void SetLevelInfoFromParams(Texture* texture, 537 void SetLevelInfoFromParams(TextureRef* ref,
459 const gpu::AsyncTexImage2DParams& params) { 538 const gpu::AsyncTexImage2DParams& params) {
460 SetLevelInfo( 539 SetLevelInfo(
461 texture, params.target, params.level, params.internal_format, 540 ref, params.target, params.level, params.internal_format,
462 params.width, params.height, 1 /* depth */, 541 params.width, params.height, 1 /* depth */,
463 params.border, params.format, 542 params.border, params.format,
464 params.type, true /* cleared */ ); 543 params.type, true /* cleared */ );
465 } 544 }
466 545
467 // Save the texture definition and leave it undefined. 546 // Save the texture definition and leave it undefined.
468 TextureDefinition* Save(Texture* texture); 547 TextureDefinition* Save(TextureRef* ref);
469 548
470 // Redefine all the levels from the texture definition. 549 // Redefine all the levels from the texture definition.
471 bool Restore( 550 bool Restore(
472 const char* function_name, 551 const char* function_name,
473 GLES2Decoder* decoder, 552 GLES2Decoder* decoder,
474 Texture* texture, 553 TextureRef* ref,
475 TextureDefinition* definition); 554 TextureDefinition* definition);
476 555
477 // Sets a mip as cleared. 556 // Sets a mip as cleared.
478 void SetLevelCleared(Texture* texture, GLenum target, 557 void SetLevelCleared(TextureRef* ref, GLenum target,
479 GLint level, bool cleared); 558 GLint level, bool cleared);
480 559
481 // Sets a texture parameter of a Texture 560 // Sets a texture parameter of a Texture
482 // Returns GL_NO_ERROR on success. Otherwise the error to generate. 561 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
483 // TODO(gman): Expand to SetParameteri,f,iv,fv 562 // TODO(gman): Expand to SetParameteri,f,iv,fv
484 void SetParameter( 563 void SetParameter(
485 const char* function_name, ErrorState* error_state, 564 const char* function_name, ErrorState* error_state,
486 Texture* texture, GLenum pname, GLint param); 565 TextureRef* ref, GLenum pname, GLint param);
487 566
488 // Makes each of the mip levels as though they were generated. 567 // Makes each of the mip levels as though they were generated.
489 // Returns false if that's not allowed for the given texture. 568 // Returns false if that's not allowed for the given texture.
490 bool MarkMipmapsGenerated(Texture* texture); 569 bool MarkMipmapsGenerated(TextureRef* ref);
491 570
492 // Clears any uncleared renderable levels. 571 // Clears any uncleared renderable levels.
493 bool ClearRenderableLevels(GLES2Decoder* decoder, Texture* texture); 572 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureRef* ref);
494 573
495 // Clear a specific level. 574 // Clear a specific level.
496 bool ClearTextureLevel( 575 bool ClearTextureLevel(
497 GLES2Decoder* decoder,Texture* texture, GLenum target, GLint level); 576 GLES2Decoder* decoder, TextureRef* ref, GLenum target, GLint level);
498 577
499 // Creates a new texture info. 578 // Creates a new texture info.
500 Texture* CreateTexture(GLuint client_id, GLuint service_id); 579 TextureRef* CreateTexture(GLuint client_id, GLuint service_id);
501 580
502 // Gets the texture info for the given texture. 581 // Gets the texture info for the given texture.
503 Texture* GetTexture(GLuint client_id) const; 582 TextureRef* GetTexture(GLuint client_id) const;
504 583
505 // Removes a texture info. 584 // Removes a texture info.
506 void RemoveTexture(GLuint client_id); 585 void RemoveTexture(GLuint client_id);
507 586
508 // Gets a client id for a given service id. 587 // Gets a client id for a given service id.
509 bool GetClientId(GLuint service_id, GLuint* client_id) const; 588 bool GetClientId(GLuint service_id, GLuint* client_id) const;
510 589
511 Texture* GetDefaultTextureInfo(GLenum target) { 590 TextureRef* GetDefaultTextureInfo(GLenum target) {
512 switch (target) { 591 switch (target) {
513 case GL_TEXTURE_2D: 592 case GL_TEXTURE_2D:
514 return default_textures_[kTexture2D]; 593 return default_textures_[kTexture2D];
515 case GL_TEXTURE_CUBE_MAP: 594 case GL_TEXTURE_CUBE_MAP:
516 return default_textures_[kCubeMap]; 595 return default_textures_[kCubeMap];
517 case GL_TEXTURE_EXTERNAL_OES: 596 case GL_TEXTURE_EXTERNAL_OES:
518 return default_textures_[kExternalOES]; 597 return default_textures_[kExternalOES];
519 case GL_TEXTURE_RECTANGLE_ARB: 598 case GL_TEXTURE_RECTANGLE_ARB:
520 return default_textures_[kRectangleARB]; 599 return default_textures_[kRectangleARB];
521 default: 600 default:
(...skipping 30 matching lines...) Expand all
552 } 631 }
553 } 632 }
554 633
555 size_t mem_represented() const { 634 size_t mem_represented() const {
556 return 635 return
557 memory_tracker_managed_->GetMemRepresented() + 636 memory_tracker_managed_->GetMemRepresented() +
558 memory_tracker_unmanaged_->GetMemRepresented(); 637 memory_tracker_unmanaged_->GetMemRepresented();
559 } 638 }
560 639
561 void SetLevelImage( 640 void SetLevelImage(
562 Texture* texture, 641 TextureRef* ref,
563 GLenum target, 642 GLenum target,
564 GLint level, 643 GLint level,
565 gfx::GLImage* image); 644 gfx::GLImage* image);
566 645
567 void AddToSignature( 646 void AddToSignature(
568 Texture* texture, 647 TextureRef* ref,
569 GLenum target, 648 GLenum target,
570 GLint level, 649 GLint level,
571 std::string* signature) const; 650 std::string* signature) const;
572 651
573 private: 652 private:
574 friend class Texture; 653 friend class Texture;
654 friend class TextureRef;
575 655
576 // Helper for Initialize(). 656 // Helper for Initialize().
577 scoped_refptr<Texture> CreateDefaultAndBlackTextures( 657 scoped_refptr<TextureRef> CreateDefaultAndBlackTextures(
578 GLenum target, 658 GLenum target,
579 GLuint* black_texture); 659 GLuint* black_texture);
580 660
581 void StartTracking(Texture* texture); 661 void StartTracking(TextureRef* texture);
582 void StopTracking(Texture* texture); 662 void StopTracking(TextureRef* texture);
663
664 void UpdateSafeToRenderFrom(int delta);
665 void UpdateUnclearedMips(int delta);
666 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition,
667 Texture::CanRenderCondition new_condition);
668 void IncFramebufferStateChangeCount();
583 669
584 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); 670 MemoryTypeTracker* GetMemTracker(GLenum texture_pool);
585 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; 671 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_;
586 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; 672 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_;
587 673
588 scoped_refptr<FeatureInfo> feature_info_; 674 scoped_refptr<FeatureInfo> feature_info_;
589 675
676 FramebufferManager* framebuffer_manager_;
677
590 // Info for each texture in the system. 678 // Info for each texture in the system.
591 typedef base::hash_map<GLuint, scoped_refptr<Texture> > TextureMap; 679 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap;
592 TextureMap textures_; 680 TextureMap textures_;
593 681
594 GLsizei max_texture_size_; 682 GLsizei max_texture_size_;
595 GLsizei max_cube_map_texture_size_; 683 GLsizei max_cube_map_texture_size_;
596 GLint max_levels_; 684 GLint max_levels_;
597 GLint max_cube_map_levels_; 685 GLint max_cube_map_levels_;
598 686
599 int num_unrenderable_textures_; 687 int num_unrenderable_textures_;
600 int num_unsafe_textures_; 688 int num_unsafe_textures_;
601 int num_uncleared_mips_; 689 int num_uncleared_mips_;
602 690
603 // Counts the number of Textures allocated with 'this' as its manager. 691 // Counts the number of Textures allocated with 'this' as its manager.
604 // Allows to check no Texture will outlive this. 692 // Allows to check no Texture will outlive this.
605 unsigned int texture_count_; 693 unsigned int texture_count_;
606 694
607 bool have_context_; 695 bool have_context_;
608 696
609 // Black (0,0,0,1) textures for when non-renderable textures are used. 697 // Black (0,0,0,1) textures for when non-renderable textures are used.
610 // NOTE: There is no corresponding Texture for these textures. 698 // NOTE: There is no corresponding Texture for these textures.
611 // TextureInfos are only for textures the client side can access. 699 // TextureInfos are only for textures the client side can access.
612 GLuint black_texture_ids_[kNumDefaultTextures]; 700 GLuint black_texture_ids_[kNumDefaultTextures];
613 701
614 // The default textures for each target (texture name = 0) 702 // The default textures for each target (texture name = 0)
615 scoped_refptr<Texture> default_textures_[kNumDefaultTextures]; 703 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures];
616 704
617 DISALLOW_COPY_AND_ASSIGN(TextureManager); 705 DISALLOW_COPY_AND_ASSIGN(TextureManager);
618 }; 706 };
619 707
620 } // namespace gles2 708 } // namespace gles2
621 } // namespace gpu 709 } // namespace gpu
622 710
623 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 711 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/test_helper.cc ('k') | gpu/command_buffer/service/texture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698