blob: 7ebee6096108cea96c22f4212006220a88f46520 [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2012 The Chromium Authors
gman@chromium.orga93bb842010-02-16 23:03:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Arthur Sonzogni720f1c952024-07-25 16:17:515
gman@chromium.orga93bb842010-02-16 23:03:476#ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
7#define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
8
avif15d60a2015-12-21 17:06:339#include <stddef.h>
10#include <stdint.h>
11
heejin.r.chung@samsung.comd3afab342014-06-23 04:26:0412#include <algorithm>
Kalvin Lee9e2c2e82025-04-16 22:37:4213#include <array>
mostynb6682b1c42016-04-19 10:17:3014#include <memory>
piman@chromium.org370eaf12013-05-18 09:19:4915#include <set>
gman@chromium.org73276522012-11-09 05:50:2016#include <string>
Takuto Ikutaadf31eb2019-01-05 00:32:4817#include <unordered_map>
gman@chromium.orga93bb842010-02-16 23:03:4718#include <vector>
mostynb6682b1c42016-04-19 10:17:3019
Daniel Chengd4c3eab2021-08-31 18:39:0120#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5221#include "base/memory/raw_ptr.h"
levin@chromium.org3b63f8f42011-03-28 01:54:1522#include "base/memory/ref_counted.h"
David Sandersdc8250f2022-03-17 01:52:1423#include "base/notreached.h"
Sunny Sachanandani40a03f12025-05-12 19:15:0024#include "base/trace_event/memory_dump_provider.h"
Colin Blundell09b1f8d2022-12-07 08:29:5725#include "build/build_config.h"
dongseong.hwang9e8922b2015-09-01 11:04:4926#include "gpu/command_buffer/service/feature_info.h"
gman@chromium.orga93bb842010-02-16 23:03:4727#include "gpu/command_buffer/service/gl_utils.h"
ccameron@chromium.org68e81a4a62012-12-13 01:16:4828#include "gpu/command_buffer/service/memory_tracking.h"
bajones7fd547652016-01-28 22:40:1229#include "gpu/command_buffer/service/sampler_manager.h"
Saifuddin Hitawala81cbd382022-07-20 19:14:5330#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
Antoine Labour40b0ca42018-01-03 20:15:3431#include "gpu/command_buffer/service/texture_base.h"
Antoine Labour83a0aed12018-01-10 04:52:3832#include "gpu/gpu_gles2_export.h"
reveman7c4a13b2015-06-05 22:28:1533#include "ui/gfx/geometry/rect.h"
gman@chromium.orga93bb842010-02-16 23:03:4734
Adrienne Walkera237d1802018-10-03 01:53:2235namespace gl {
36class ProgressReporter;
37}
38
gman@chromium.orga93bb842010-02-16 23:03:4739namespace gpu {
Jonathan Backerc26060e2018-03-29 15:06:2940class DecoderContext;
ericrkdc5eeaa2017-05-19 02:23:5041class ServiceDiscardableManager;
gman@chromium.orga93bb842010-02-16 23:03:4742
ericrkdc5eeaa2017-05-19 02:23:5043namespace gles2 {
kloveless@chromium.orgc986af502013-08-14 01:04:4444struct ContextState;
45struct DecoderFramebufferState;
kloveless@chromium.orgd3eba342013-04-18 21:11:5046class ErrorState;
gman@chromium.orged9f9cd2013-02-27 21:12:3547class FeatureInfo;
piman@chromium.org370eaf12013-05-18 09:19:4948class FramebufferManager;
geofflang5a3b3eea2016-09-07 21:37:3449class Texture;
gman@chromium.orged9f9cd2013-02-27 21:12:3550class TextureManager;
piman@chromium.org370eaf12013-05-18 09:19:4951class TextureRef;
gman@chromium.orged9f9cd2013-02-27 21:12:3552
geofflang851a4812016-09-14 19:20:2953// A ref-counted version of the TextureBase class that deletes the texture after
54// all references have been released.
Antoine Laboura36c7232018-08-02 04:31:0255class GPU_GLES2_EXPORT TexturePassthrough final
Frank Liberato1d58073e2018-06-06 23:48:2156 : public TextureBase,
David Bertoni94c7fb9c2024-02-06 18:27:5357 public base::RefCounted<TexturePassthrough> {
geofflang851a4812016-09-14 19:20:2958 public:
geofflang45a7bad2016-11-23 17:05:2859 TexturePassthrough(GLuint service_id, GLenum target);
geofflang851a4812016-09-14 19:20:2960
Peter BostrÃļm1ab741d2021-10-05 22:49:4161 TexturePassthrough(const TexturePassthrough&) = delete;
62 TexturePassthrough& operator=(const TexturePassthrough&) = delete;
63
Jonathan Backera1f3d7c2018-10-16 14:46:3264 // TextureBase implementation:
65 TextureBase::Type GetType() const override;
66
67 static TexturePassthrough* CheckedCast(TextureBase* texture);
68
geofflang851a4812016-09-14 19:20:2969 // Notify the texture that the context is lost and it shouldn't delete the
70 // native GL texture in the destructor
71 void MarkContextLost();
72
Colin Blundell5a1c91d2023-01-04 14:31:3873#if BUILDFLAG(IS_ANDROID)
Colin Blundellf6cf0232022-12-22 11:08:2674 void BindToServiceId(GLuint service_id);
Colin Blundell5a1c91d2023-01-04 14:31:3875#endif
Geoff Lang61aaae42019-05-29 18:30:2976
Geoff Lang72fe4762018-10-19 15:11:3677 void SetEstimatedSize(size_t size);
78 size_t estimated_size() const { return estimated_size_; }
79
geofflang851a4812016-09-14 19:20:2980 protected:
81 ~TexturePassthrough() override;
82
83 private:
84 friend class base::RefCounted<TexturePassthrough>;
85
Scott Violetbe5e7ae2021-06-16 21:19:4486 const GLuint owned_service_id_ = 0;
Geoff Lang61aaae42019-05-29 18:30:2987
geofflang851a4812016-09-14 19:20:2988 bool have_context_;
89
Geoff Lang72fe4762018-10-19 15:11:3690 size_t estimated_size_ = 0;
geofflang851a4812016-09-14 19:20:2991};
92
gman@chromium.orged9f9cd2013-02-27 21:12:3593// Info about Textures currently in the system.
piman@chromium.org370eaf12013-05-18 09:19:4994// This class wraps a real GL texture, keeping track of its meta-data. It is
95// jointly owned by possibly multiple TextureRef.
Antoine Labour83a0aed12018-01-10 04:52:3896class GPU_GLES2_EXPORT Texture final : public TextureBase {
gman@chromium.orged9f9cd2013-02-27 21:12:3597 public:
bajones2c9d7182016-03-11 18:16:2898 struct CompatibilitySwizzle {
99 GLenum format;
100 GLenum dest_format;
101 GLenum red;
102 GLenum green;
103 GLenum blue;
104 GLenum alpha;
105 };
106
Vikas Sonifa588152020-06-18 14:03:11107 struct LevelInfo {
108 LevelInfo();
109 LevelInfo(const LevelInfo& rhs);
110 ~LevelInfo();
111
112 gfx::Rect cleared_rect;
113 GLenum target = 0;
114 GLint level = -1;
115 GLenum internal_format = 0;
116 GLsizei width = 0;
117 GLsizei height = 0;
118 GLsizei depth = 0;
119 GLint border = 0;
120 GLenum format = 0;
121 GLenum type = 0;
Vikas Sonifa588152020-06-18 14:03:11122 uint32_t estimated_size = 0;
123 bool internal_workaround = false;
Colin Blundellc5985db12023-01-30 10:38:50124
125 private:
126 friend class Texture;
Vikas Sonifa588152020-06-18 14:03:11127 };
128
piman@chromium.org370eaf12013-05-18 09:19:49129 explicit Texture(GLuint service_id);
gman@chromium.orged9f9cd2013-02-27 21:12:35130
Peter BostrÃļm1ab741d2021-10-05 22:49:41131 Texture(const Texture&) = delete;
132 Texture& operator=(const Texture&) = delete;
133
Jonathan Backera1f3d7c2018-10-16 14:46:32134 // TextureBase implementation:
135 TextureBase::Type GetType() const override;
136
137 static Texture* CheckedCast(TextureBase* texture);
138
bajones7fd547652016-01-28 22:40:12139 const SamplerState& sampler_state() const {
140 return sampler_state_;
141 }
142
Vikas Sonifa588152020-06-18 14:03:11143 void set_min_filter(GLenum min_filter) {
144 sampler_state_.min_filter = min_filter;
145 }
146
gman@chromium.orged9f9cd2013-02-27 21:12:35147 GLenum min_filter() const {
bajones7fd547652016-01-28 22:40:12148 return sampler_state_.min_filter;
gman@chromium.orged9f9cd2013-02-27 21:12:35149 }
150
Vikas Sonifa588152020-06-18 14:03:11151 void set_mag_filter(GLenum mag_filter) {
152 sampler_state_.mag_filter = mag_filter;
153 }
154
gman@chromium.orged9f9cd2013-02-27 21:12:35155 GLenum mag_filter() const {
bajones7fd547652016-01-28 22:40:12156 return sampler_state_.mag_filter;
gman@chromium.orged9f9cd2013-02-27 21:12:35157 }
158
Vikas Sonifa588152020-06-18 14:03:11159 void set_wrap_r(GLenum wrap_r) { sampler_state_.wrap_r = wrap_r; }
160
guanxian.li98291952015-05-12 07:11:09161 GLenum wrap_r() const {
bajones7fd547652016-01-28 22:40:12162 return sampler_state_.wrap_r;
guanxian.li98291952015-05-12 07:11:09163 }
164
Vikas Sonifa588152020-06-18 14:03:11165 void set_wrap_s(GLenum wrap_s) { sampler_state_.wrap_s = wrap_s; }
166
gman@chromium.orged9f9cd2013-02-27 21:12:35167 GLenum wrap_s() const {
bajones7fd547652016-01-28 22:40:12168 return sampler_state_.wrap_s;
gman@chromium.orged9f9cd2013-02-27 21:12:35169 }
170
Vikas Sonifa588152020-06-18 14:03:11171 void set_wrap_t(GLenum wrap_t) { sampler_state_.wrap_t = wrap_t; }
172
gman@chromium.orged9f9cd2013-02-27 21:12:35173 GLenum wrap_t() const {
bajones7fd547652016-01-28 22:40:12174 return sampler_state_.wrap_t;
gman@chromium.orged9f9cd2013-02-27 21:12:35175 }
176
177 GLenum usage() const {
178 return usage_;
179 }
180
guanxian.li98291952015-05-12 07:11:09181 GLenum compare_func() const {
bajones7fd547652016-01-28 22:40:12182 return sampler_state_.compare_func;
guanxian.li98291952015-05-12 07:11:09183 }
184
185 GLenum compare_mode() const {
bajones7fd547652016-01-28 22:40:12186 return sampler_state_.compare_mode;
guanxian.li98291952015-05-12 07:11:09187 }
188
189 GLfloat max_lod() const {
bajones7fd547652016-01-28 22:40:12190 return sampler_state_.max_lod;
guanxian.li98291952015-05-12 07:11:09191 }
192
193 GLfloat min_lod() const {
bajones7fd547652016-01-28 22:40:12194 return sampler_state_.min_lod;
guanxian.li98291952015-05-12 07:11:09195 }
196
197 GLint base_level() const {
198 return base_level_;
199 }
200
201 GLint max_level() const {
202 return max_level_;
203 }
204
Zhenyao Mo385508d2018-08-29 20:03:50205 GLint unclamped_base_level() const { return unclamped_base_level_; }
206
207 GLint unclamped_max_level() const { return unclamped_max_level_; }
208
bajones2c9d7182016-03-11 18:16:28209 GLenum swizzle_r() const { return swizzle_r_; }
210
211 GLenum swizzle_g() const { return swizzle_g_; }
212
213 GLenum swizzle_b() const { return swizzle_b_; }
214
215 GLenum swizzle_a() const { return swizzle_a_; }
216
gman@chromium.orged9f9cd2013-02-27 21:12:35217 int num_uncleared_mips() const {
218 return num_uncleared_mips_;
219 }
220
avif15d60a2015-12-21 17:06:33221 uint32_t estimated_size() const { return estimated_size_; }
gman@chromium.orged9f9cd2013-02-27 21:12:35222
zmo59b6cc52016-01-30 02:35:59223 bool CanRenderTo(const FeatureInfo* feature_info, GLint level) const;
gman@chromium.orged9f9cd2013-02-27 21:12:35224
gman@chromium.orged9f9cd2013-02-27 21:12:35225 bool SafeToRenderFrom() const {
226 return cleared_;
227 }
228
zmo9a7b17e2015-05-06 00:22:33229 // Get the width/height/depth for a particular level. Returns false if level
gman@chromium.orged9f9cd2013-02-27 21:12:35230 // does not exist.
zmo9a7b17e2015-05-06 00:22:33231 // |depth| is optional and can be nullptr.
gman@chromium.orged9f9cd2013-02-27 21:12:35232 bool GetLevelSize(
zmo9a7b17e2015-05-06 00:22:33233 GLint target, GLint level,
234 GLsizei* width, GLsizei* height, GLsizei* depth) const;
gman@chromium.orged9f9cd2013-02-27 21:12:35235
236 // Get the type of a level. Returns false if level does not exist.
237 bool GetLevelType(
238 GLint target, GLint level, GLenum* type, GLenum* internal_format) const;
239
Colin Blundell09b1f8d2022-12-07 08:29:57240#if BUILDFLAG(IS_ANDROID)
Colin Blundellf6cf0232022-12-22 11:08:26241 // Overrides |service_id_| with a texture bound to
Colin Blundell1c2b2c032023-01-27 09:18:50242 // the stream texture. See SetStreamTextureServiceId() for the details of
243 // how |service_id| is used.
Colin Blundellf6cf0232022-12-22 11:08:26244 void BindToServiceId(GLuint service_id);
Colin Blundell09b1f8d2022-12-07 08:29:57245#endif
watke8d35a52016-06-04 03:14:37246
James Darpinian116b0e12019-03-28 06:39:07247 bool CompatibleWithSamplerUniformType(
248 GLenum type,
249 const SamplerState& sampler_state) const;
liberatodf64f2cb2016-02-24 00:24:56250
gman@chromium.orged9f9cd2013-02-27 21:12:35251 // Returns true of the given dimensions are inside the dimensions of the
zmof9139ed2015-09-18 02:24:22252 // level.
gman@chromium.orged9f9cd2013-02-27 21:12:35253 bool ValidForTexture(
254 GLint target,
255 GLint level,
256 GLint xoffset,
257 GLint yoffset,
zmo9a7b17e2015-05-06 00:22:33258 GLint zoffset,
gman@chromium.orged9f9cd2013-02-27 21:12:35259 GLsizei width,
260 GLsizei height,
zmof9139ed2015-09-18 02:24:22261 GLsizei depth) const;
gman@chromium.orged9f9cd2013-02-27 21:12:35262
263 bool IsValid() const {
piman@chromium.org370eaf12013-05-18 09:19:49264 return !!target();
gman@chromium.orged9f9cd2013-02-27 21:12:35265 }
266
gman@chromium.orged9f9cd2013-02-27 21:12:35267 bool IsAttachedToFramebuffer() const {
268 return framebuffer_attachment_count_ != 0;
269 }
270
271 void AttachToFramebuffer() {
272 ++framebuffer_attachment_count_;
273 }
274
275 void DetachFromFramebuffer() {
276 DCHECK_GT(framebuffer_attachment_count_, 0);
277 --framebuffer_attachment_count_;
278 }
279
Saman Sami20ce46c42019-06-15 01:18:23280 // |immutable| indicates that the GPU clients cannot modify the format or
281 // dimensions of the texture object. This is an artificial restriction imposed
282 // by the GPU service on its clients. |immutable_storage| indicates that the
283 // storage for the texture is allocated using glTexStorage* functions and it
284 // is equivalent to the definition of immutability as defined in OpenGL
285 // specifications.
286 void SetImmutable(bool immutable, bool immutable_storage);
gman@chromium.orged9f9cd2013-02-27 21:12:35287
gman@chromium.org5190e94c2013-05-17 03:53:42288 bool IsImmutable() const {
gman@chromium.orged9f9cd2013-02-27 21:12:35289 return immutable_;
290 }
291
Saman Sami20ce46c42019-06-15 01:18:23292 bool HasImmutableStorage() const { return immutable_storage_; }
293
zmoae9c1902016-04-15 19:56:19294 // Return 0 if it's not immutable.
295 GLint GetImmutableLevels() const;
296
reveman7c4a13b2015-06-05 22:28:15297 // Get the cleared rectangle for a particular level. Returns an empty
298 // rectangle if level does not exist.
299 gfx::Rect GetLevelClearedRect(GLenum target, GLint level) const;
300
Antoine Labour9ddf6ac2019-01-17 01:59:39301 // Marks a |rect| of a particular level as cleared.
302 void SetLevelClearedRect(GLenum target,
303 GLint level,
304 const gfx::Rect& cleared_rect);
305
gman@chromium.orged9f9cd2013-02-27 21:12:35306 // Whether a particular level/face is cleared.
sievers@chromium.org632f7992013-03-24 06:56:12307 bool IsLevelCleared(GLenum target, GLint level) const;
zmod252e3ea2016-02-23 00:38:17308 // Whether a particular level/face is partially cleared.
309 bool IsLevelPartiallyCleared(GLenum target, GLint level) const;
gman@chromium.orged9f9cd2013-02-27 21:12:35310
311 // Whether the texture has been defined
gman@chromium.org5190e94c2013-05-17 03:53:42312 bool IsDefined() const {
gman@chromium.orged9f9cd2013-02-27 21:12:35313 return estimated_size() > 0;
314 }
315
ericrk28a82a0e2015-08-21 13:28:36316 void DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd,
317 uint64_t client_tracing_id,
318 const std::string& dump_name) const;
319
James Darpiniand645c7b2018-12-01 02:21:09320 void ApplyFormatWorkarounds(const FeatureInfo* feature_info);
bajones2c9d7182016-03-11 18:16:28321
zmo9585ee5e2017-05-23 01:15:17322 // In GLES2 "texture complete" means it has all required mips for filtering
323 // down to a 1x1 pixel texture, they are in the correct order, they are all
324 // the same format.
325 bool texture_complete() const {
326 DCHECK(!completeness_dirty_);
327 return texture_complete_;
328 }
329
qiankun.miaod12b5bc2016-12-20 04:09:51330 static bool ColorRenderable(const FeatureInfo* feature_info,
331 GLenum internal_format,
332 bool immutable);
333
Jonathan Backer7e7492522018-07-20 00:23:55334 // Marks a particular level as cleared or uncleared.
335 void SetLevelCleared(GLenum target, GLint level, bool cleared);
336
Antoine Labourda594e52018-07-28 21:57:57337 MemoryTypeTracker* GetMemTracker();
338
James Darpinian0fce4522019-01-09 02:46:54339 // Returns GL_NONE on error.
340 GLenum GetInternalFormatOfBaseLevel() const;
341
Vikas Sonifa588152020-06-18 14:03:11342 void SetLightweightRef();
343
344 void RemoveLightweightRef(bool have_context);
345
346 // Set the info for a particular level.
347 void SetLevelInfo(GLenum target,
348 GLint level,
349 GLenum internal_format,
350 GLsizei width,
351 GLsizei height,
352 GLsizei depth,
353 GLint border,
354 GLenum format,
355 GLenum type,
356 const gfx::Rect& cleared_rect);
357
358 // Returns the LevelInfo for |target| and |level| if it's set, else nullptr.
359 const LevelInfo* GetLevelInfo(GLint target, GLint level) const;
360
361 // Sets the Texture's target
362 // Parameters:
363 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
Geoff Lang8fc21cd2025-05-26 13:13:29364 // GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ANGLE
Vikas Sonifa588152020-06-18 14:03:11365 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
366 // max_levels: The maximum levels this type of target can have.
367 void SetTarget(GLenum target, GLint max_levels);
368
369 void SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle);
370
371 bool NeedsMips() const {
372 return sampler_state_.min_filter != GL_NEAREST &&
373 sampler_state_.min_filter != GL_LINEAR;
374 }
375
Peng Huang6b4af5d2022-11-23 00:16:49376 size_t MaxValidMipLevel() const {
377 DCHECK(!face_infos_.empty());
378 return face_infos_[0].level_infos.size();
379 }
380
gman@chromium.orged9f9cd2013-02-27 21:12:35381 private:
382 friend class TextureManager;
piman@chromium.org370eaf12013-05-18 09:19:49383 friend class TextureRef;
gman@chromium.org53725a1f2013-04-03 07:15:53384 friend class TextureTestHelper;
Antoine Labourda594e52018-07-28 21:57:57385 FRIEND_TEST_ALL_PREFIXES(TextureMemoryTrackerTest, LightweightRef);
gman@chromium.orged9f9cd2013-02-27 21:12:35386
geofflang5a3b3eea2016-09-07 21:37:34387 ~Texture() override;
piman@chromium.org370eaf12013-05-18 09:19:49388 void AddTextureRef(TextureRef* ref);
389 void RemoveTextureRef(TextureRef* ref, bool have_context);
Antoine Labourda594e52018-07-28 21:57:57390 void MaybeDeleteThis(bool have_context);
piman@chromium.org370eaf12013-05-18 09:19:49391
392 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
393 // depends on context support for non-power-of-two textures (i.e. will be
394 // renderable if NPOT support is in the context, otherwise not, e.g. texture
395 // with a NPOT level). ALWAYS means it doesn't depend on context features
396 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
397 // incomplete).
398 enum CanRenderCondition {
399 CAN_RENDER_ALWAYS,
400 CAN_RENDER_NEVER,
bajones7fd547652016-01-28 22:40:12401 CAN_RENDER_NEEDS_VALIDATION,
piman@chromium.org370eaf12013-05-18 09:19:49402 };
gman@chromium.orged9f9cd2013-02-27 21:12:35403
dyenecc73c22014-10-10 20:44:02404 struct FaceInfo {
405 FaceInfo();
vmpstr3b7b8b22016-03-01 23:00:20406 FaceInfo(const FaceInfo& other);
dyenecc73c22014-10-10 20:44:02407 ~FaceInfo();
408
bajones833361b2015-11-24 17:06:10409 // This is relative to base_level and max_level of a texture.
dyenecc73c22014-10-10 20:44:02410 GLsizei num_mip_levels;
bajones833361b2015-11-24 17:06:10411 // This contains slots for all levels starting at 0.
dyenecc73c22014-10-10 20:44:02412 std::vector<LevelInfo> level_infos;
413 };
414
James Darpinian0fce4522019-01-09 02:46:54415 // Returns NULL if the base level is not defined.
416 const LevelInfo* GetBaseLevelInfo() const;
liberatodf64f2cb2016-02-24 00:24:56417
watke8d35a52016-06-04 03:14:37418 // Causes us to report |service_id| as our service id, but does not delete
419 // it when we are destroyed. Will rebind any OES_EXTERNAL texture units to
420 // our new service id in all contexts. If |service_id| is zero, then we
421 // revert to |owned_service_id_|.
422 void SetStreamTextureServiceId(GLuint service_id);
423
zmo59b6cc52016-01-30 02:35:59424 void MarkLevelAsInternalWorkaround(GLenum target, GLint level);
425
gman@chromium.org53725a1f2013-04-03 07:15:53426 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the
427 // same format, all the same dimensions and all width = height.
428 bool cube_complete() const {
zmo9585ee5e2017-05-23 01:15:17429 DCHECK(!completeness_dirty_);
gman@chromium.org53725a1f2013-04-03 07:15:53430 return cube_complete_;
431 }
432
433 // Whether or not this texture is a non-power-of-two texture.
434 bool npot() const {
435 return npot_;
436 }
437
gman@chromium.orged9f9cd2013-02-27 21:12:35438 // Updates the cleared flag for this texture by inspecting all the mips.
439 void UpdateCleared();
440
441 // Clears any renderable uncleared levels.
442 // Returns false if a GL error was generated.
Jonathan Backerc26060e2018-03-29 15:06:29443 bool ClearRenderableLevels(DecoderContext* decoder);
gman@chromium.orged9f9cd2013-02-27 21:12:35444
445 // Clears the level.
446 // Returns false if a GL error was generated.
Jonathan Backerc26060e2018-03-29 15:06:29447 bool ClearLevel(DecoderContext* decoder, GLenum target, GLint level);
gman@chromium.orged9f9cd2013-02-27 21:12:35448
449 // Sets a texture parameter.
zmo@chromium.org737191ee72014-03-09 08:02:42450 // TODO(gman): Expand to SetParameteriv,fv
gman@chromium.orged9f9cd2013-02-27 21:12:35451 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
zmo@chromium.org737191ee72014-03-09 08:02:42452 GLenum SetParameteri(
gman@chromium.orged9f9cd2013-02-27 21:12:35453 const FeatureInfo* feature_info, GLenum pname, GLint param);
zmo@chromium.org737191ee72014-03-09 08:02:42454 GLenum SetParameterf(
455 const FeatureInfo* feature_info, GLenum pname, GLfloat param);
gman@chromium.orged9f9cd2013-02-27 21:12:35456
457 // Makes each of the mip levels as though they were generated.
zmo59b6cc52016-01-30 02:35:59458 void MarkMipmapsGenerated();
gman@chromium.orged9f9cd2013-02-27 21:12:35459
gman@chromium.orged9f9cd2013-02-27 21:12:35460 // True if this texture meets all the GLES2 criteria for rendering.
461 // See section 3.8.2 of the GLES2 spec.
462 bool CanRender(const FeatureInfo* feature_info) const;
bajones7fd547652016-01-28 22:40:12463 bool CanRenderWithSampler(const FeatureInfo* feature_info,
464 const SamplerState& sampler_state) const;
gman@chromium.orged9f9cd2013-02-27 21:12:35465
466 // Returns true if mipmaps can be generated by GL.
467 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
468
dyenecc73c22014-10-10 20:44:02469 // Returns true if any of the texture dimensions are not a power of two.
470 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
471
472 // Returns true if texture face is complete relative to the first face.
473 static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
474 size_t face_index,
475 GLenum target,
476 GLenum internal_format,
477 GLsizei width,
478 GLsizei height,
479 GLsizei depth,
480 GLenum format,
481 GLenum type);
482
bajones833361b2015-11-24 17:06:10483 // Returns true if texture mip level is complete relative to base level.
484 // Note that level_diff = level - base_level.
485 static bool TextureMipComplete(const Texture::LevelInfo& base_level_face,
dyenecc73c22014-10-10 20:44:02486 GLenum target,
bajones833361b2015-11-24 17:06:10487 GLint level_diff,
dyenecc73c22014-10-10 20:44:02488 GLenum internal_format,
489 GLsizei width,
490 GLsizei height,
491 GLsizei depth,
492 GLenum format,
493 GLenum type);
494
zmo13f285d42016-02-06 00:48:41495 static bool TextureFilterable(const FeatureInfo* feature_info,
496 GLenum internal_format,
dongseong.hwang460cac92016-10-25 21:16:41497 GLenum type,
498 bool immutable);
zmo13f285d42016-02-06 00:48:41499
gman@chromium.orged9f9cd2013-02-27 21:12:35500 // Update info about this texture.
zmo59b6cc52016-01-30 02:35:59501 void Update();
gman@chromium.orged9f9cd2013-02-27 21:12:35502
gman@chromium.orged9f9cd2013-02-27 21:12:35503 // Appends a signature for the given level.
504 void AddToSignature(
505 const FeatureInfo* feature_info,
506 GLenum target, GLint level, std::string* signature) const;
507
piman@chromium.org370eaf12013-05-18 09:19:49508 // Updates the unsafe textures count in all the managers referencing this
509 // texture.
510 void UpdateSafeToRenderFrom(bool cleared);
511
512 // Updates the uncleared mip count in all the managers referencing this
513 // texture.
reveman7c4a13b2015-06-05 22:28:15514 void UpdateMipCleared(LevelInfo* info,
515 GLsizei width,
516 GLsizei height,
517 const gfx::Rect& cleared_rect);
piman@chromium.org370eaf12013-05-18 09:19:49518
519 // Computes the CanRenderCondition flag.
520 CanRenderCondition GetCanRenderCondition() const;
521
522 // Updates the unrenderable texture count in all the managers referencing this
523 // texture.
524 void UpdateCanRenderCondition();
525
526 // Increment the framebuffer state change count in all the managers
527 // referencing this texture.
528 void IncAllFramebufferStateChangeCount();
529
James Darpiniand645c7b2018-12-01 02:21:09530 void UpdateBaseLevel(GLint base_level, const FeatureInfo* feature_info);
bajones833361b2015-11-24 17:06:10531 void UpdateMaxLevel(GLint max_level);
Zhenyao Mo0522e1582019-07-18 22:40:55532 void UpdateFaceNumMipLevels(size_t face_index,
533 GLint width,
534 GLint height,
535 GLint depth);
536 void UpdateFaceNumMipLevels(size_t face_index);
bajones833361b2015-11-24 17:06:10537 void UpdateNumMipLevels();
538
liberato774cc112016-01-15 16:20:49539 // Increment the generation counter for all managers that have a reference to
540 // this texture.
541 void IncrementManagerServiceIdGeneration();
542
543 // Return the service id of the texture that we will delete when we are
watke8d35a52016-06-04 03:14:37544 // destroyed.
liberato774cc112016-01-15 16:20:49545 GLuint owned_service_id() const { return owned_service_id_; }
546
bajones2c9d7182016-03-11 18:16:28547 GLenum GetCompatibilitySwizzleForChannel(GLenum channel);
bajones2c9d7182016-03-11 18:16:28548
gman@chromium.orged9f9cd2013-02-27 21:12:35549 // Info about each face and level of texture.
dyenecc73c22014-10-10 20:44:02550 std::vector<FaceInfo> face_infos_;
gman@chromium.orged9f9cd2013-02-27 21:12:35551
piman@chromium.org370eaf12013-05-18 09:19:49552 // The texture refs that point to this Texture.
Ali Hijazia56154d2024-02-26 10:21:17553 typedef base::flat_set<raw_ptr<TextureRef, CtnExperimental>> RefSet;
piman@chromium.org370eaf12013-05-18 09:19:49554 RefSet refs_;
Eric Karld69119cb2018-10-31 22:19:37555 bool has_lightweight_ref_ = false;
piman@chromium.org370eaf12013-05-18 09:19:49556
557 // The single TextureRef that accounts for memory for this texture. Must be
558 // one of refs_.
Keishi Hattori0e45c022021-11-27 09:25:52559 raw_ptr<TextureRef> memory_tracking_ref_ = nullptr;
gman@chromium.orged9f9cd2013-02-27 21:12:35560
watke8d35a52016-06-04 03:14:37561 // The id of the texture that we are responsible for deleting. Normally, this
Vasiliy Telezhnikov1db6a8b2020-07-10 19:15:39562 // is the same as |service_id_|, unless a StreamTexture Image with its own
563 // service id is bound. In that case the StreamTexture service id is
watke8d35a52016-06-04 03:14:37564 // stored in |service_id_| and overrides the owned service id for all purposes
565 // except deleting the texture name.
liberato774cc112016-01-15 16:20:49566 GLuint owned_service_id_;
567
gman@chromium.orged9f9cd2013-02-27 21:12:35568 // Whether all renderable mips of this texture have been cleared.
Antoine Labourda594e52018-07-28 21:57:57569 bool cleared_ = true;
gman@chromium.orged9f9cd2013-02-27 21:12:35570
Antoine Labourda594e52018-07-28 21:57:57571 int num_uncleared_mips_ = 0;
572 int num_npot_faces_ = 0;
gman@chromium.orged9f9cd2013-02-27 21:12:35573
gman@chromium.orged9f9cd2013-02-27 21:12:35574 // Texture parameters.
bajones7fd547652016-01-28 22:40:12575 SamplerState sampler_state_;
Antoine Labourda594e52018-07-28 21:57:57576 GLenum usage_ = GL_NONE;
577 GLint base_level_ = 0;
578 GLint max_level_ = 1000;
579 GLenum swizzle_r_ = GL_RED;
580 GLenum swizzle_g_ = GL_GREEN;
581 GLenum swizzle_b_ = GL_BLUE;
582 GLenum swizzle_a_ = GL_ALPHA;
gman@chromium.orged9f9cd2013-02-27 21:12:35583
Zhenyao Mo385508d2018-08-29 20:03:50584 GLint unclamped_base_level_ = 0;
585 GLint unclamped_max_level_ = 1000;
586
gman@chromium.orged9f9cd2013-02-27 21:12:35587 // The maximum level that has been set.
Antoine Labourda594e52018-07-28 21:57:57588 GLint max_level_set_ = -1;
gman@chromium.orged9f9cd2013-02-27 21:12:35589
590 // Whether or not this texture is "texture complete"
Antoine Labourda594e52018-07-28 21:57:57591 bool texture_complete_ = false;
gman@chromium.orged9f9cd2013-02-27 21:12:35592
593 // Whether or not this texture is "cube complete"
Antoine Labourda594e52018-07-28 21:57:57594 bool cube_complete_ = false;
gman@chromium.orged9f9cd2013-02-27 21:12:35595
zmo9585ee5e2017-05-23 01:15:17596 // Whether mip levels, base_level, or max_level have changed and
597 // texture_completeness_ and cube_completeness_ should be reverified.
Antoine Labourda594e52018-07-28 21:57:57598 bool completeness_dirty_ = false;
zmo9585ee5e2017-05-23 01:15:17599
gman@chromium.orged9f9cd2013-02-27 21:12:35600 // Whether or not this texture is non-power-of-two
Antoine Labourda594e52018-07-28 21:57:57601 bool npot_ = false;
gman@chromium.orged9f9cd2013-02-27 21:12:35602
603 // Whether this texture has ever been bound.
Antoine Labourda594e52018-07-28 21:57:57604 bool has_been_bound_ = false;
gman@chromium.orged9f9cd2013-02-27 21:12:35605
606 // The number of framebuffers this texture is attached to.
Antoine Labourda594e52018-07-28 21:57:57607 int framebuffer_attachment_count_ = 0;
gman@chromium.orged9f9cd2013-02-27 21:12:35608
gman@chromium.orged9f9cd2013-02-27 21:12:35609 // Whether the texture is immutable and no further changes to the format
610 // or dimensions of the texture object can be made.
Antoine Labourda594e52018-07-28 21:57:57611 bool immutable_ = false;
gman@chromium.orged9f9cd2013-02-27 21:12:35612
Saman Sami20ce46c42019-06-15 01:18:23613 // Indicates that the storage for the texture is allocated using glTexStorage*
614 // functions.
615 bool immutable_storage_ = false;
616
gman@chromium.orged9f9cd2013-02-27 21:12:35617 // Size in bytes this texture is assumed to take in memory.
Antoine Labourda594e52018-07-28 21:57:57618 uint32_t estimated_size_ = 0;
gman@chromium.orged9f9cd2013-02-27 21:12:35619
piman@chromium.org370eaf12013-05-18 09:19:49620 // Cache of the computed CanRenderCondition flag.
Antoine Labourda594e52018-07-28 21:57:57621 CanRenderCondition can_render_condition_ = CAN_RENDER_ALWAYS;
piman@chromium.org370eaf12013-05-18 09:19:49622
Keishi Hattori0e45c022021-11-27 09:25:52623 raw_ptr<const CompatibilitySwizzle> compatibility_swizzle_ = nullptr;
gman@chromium.orged9f9cd2013-02-27 21:12:35624};
gman@chromium.org915a59a12010-09-30 21:29:11625
piman@chromium.org370eaf12013-05-18 09:19:49626// This class represents a texture in a client context group. It's mostly 1:1
627// with a client id, though it can outlive the client id if it's still bound to
628// a FBO or another context when destroyed.
629// Multiple TextureRef can point to the same texture with cross-context sharing.
Antoine Labour83a0aed12018-01-10 04:52:38630class GPU_GLES2_EXPORT TextureRef : public base::RefCounted<TextureRef> {
piman@chromium.org370eaf12013-05-18 09:19:49631 public:
piman@chromium.org62e65f02013-05-29 22:28:10632 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture);
Peter BostrÃļm1ab741d2021-10-05 22:49:41633
634 TextureRef(const TextureRef&) = delete;
635 TextureRef& operator=(const TextureRef&) = delete;
636
piman@chromium.org370eaf12013-05-18 09:19:49637 static scoped_refptr<TextureRef> Create(TextureManager* manager,
piman@chromium.org62e65f02013-05-29 22:28:10638 GLuint client_id,
piman@chromium.org370eaf12013-05-18 09:19:49639 GLuint service_id);
vmiura@chromium.org35bd3442014-04-23 23:31:03640
641 void AddObserver() { num_observers_++; }
642 void RemoveObserver() { num_observers_--; }
643
Eric Karlb1292a12018-10-17 01:20:03644 // TODO(ericrk): Remove this once the Texture itself is generated from and
645 // owns the SharedImageRepresentation.
646 void SetSharedImageRepresentation(
Saifuddin Hitawaladaed5972022-07-20 22:01:01647 std::unique_ptr<GLTextureImageRepresentation> shared_image);
piman@chromium.org370eaf12013-05-18 09:19:49648 const Texture* texture() const { return texture_; }
649 Texture* texture() { return texture_; }
piman@chromium.org62e65f02013-05-29 22:28:10650 GLuint client_id() const { return client_id_; }
piman@chromium.org370eaf12013-05-18 09:19:49651 GLuint service_id() const { return texture_->service_id(); }
vmiura@chromium.org35bd3442014-04-23 23:31:03652 GLint num_observers() const { return num_observers_; }
Saifuddin Hitawaladaed5972022-07-20 22:01:01653 GLTextureImageRepresentation* shared_image() const {
Eric Karlebc7f2d92018-11-07 13:52:26654 return shared_image_.get();
655 }
Saifuddin Hitawaladaed5972022-07-20 22:01:01656 const std::unique_ptr<GLTextureImageRepresentation::ScopedAccess>&
Peng Huange9b41cd2019-08-12 19:39:47657 shared_image_scoped_access() const {
658 return shared_image_scoped_access_;
659 }
660
661 bool BeginAccessSharedImage(GLenum mode);
662 void EndAccessSharedImage();
piman@chromium.org370eaf12013-05-18 09:19:49663
erikchen3dec65c2016-06-22 01:05:13664 // When the TextureRef is destroyed, it will assume that the context has been
665 // lost, regardless of the state of the TextureManager.
666 void ForceContextLost();
667
piman@chromium.org370eaf12013-05-18 09:19:49668 private:
669 friend class base::RefCounted<TextureRef>;
670 friend class Texture;
671 friend class TextureManager;
672
673 ~TextureRef();
674 const TextureManager* manager() const { return manager_; }
675 TextureManager* manager() { return manager_; }
piman@chromium.org62e65f02013-05-29 22:28:10676 void reset_client_id() { client_id_ = 0; }
piman@chromium.org370eaf12013-05-18 09:19:49677
Keishi Hattori0e45c022021-11-27 09:25:52678 raw_ptr<TextureManager> manager_;
PÃĸrisb3b3aba22022-10-10 08:15:20679 raw_ptr<Texture, DanglingUntriaged> texture_;
piman@chromium.org62e65f02013-05-29 22:28:10680 GLuint client_id_;
vmiura@chromium.org35bd3442014-04-23 23:31:03681 GLint num_observers_;
erikchen3dec65c2016-06-22 01:05:13682 bool force_context_lost_;
piman@chromium.org370eaf12013-05-18 09:19:49683
Saifuddin Hitawaladaed5972022-07-20 22:01:01684 std::unique_ptr<GLTextureImageRepresentation> shared_image_;
685 std::unique_ptr<GLTextureImageRepresentation::ScopedAccess>
Peng Huange9b41cd2019-08-12 19:39:47686 shared_image_scoped_access_;
piman@chromium.org370eaf12013-05-18 09:19:49687};
688
kloveless@chromium.orgc986af502013-08-14 01:04:44689// Holds data that is per gles2_cmd_decoder, but is related to to the
690// TextureManager.
691struct DecoderTextureState {
692 // total_texture_upload_time automatically initialized to 0 in default
693 // constructor.
qiankun.miao9d28c22d2017-04-20 06:22:07694 explicit DecoderTextureState(const GpuDriverBugWorkarounds& workarounds);
kloveless@chromium.orgc986af502013-08-14 01:04:44695
zmo54f23712015-05-28 19:28:49696 // This indicates all the following texSubImage*D calls that are part of the
martina.kollarovace7995a2015-07-10 15:26:06697 // failed texImage*D call should be ignored. The client calls have a lock
698 // around them, so it will affect only a single texImage*D + texSubImage*D
699 // group.
zmo54f23712015-05-28 19:28:49700 bool tex_image_failed;
kloveless@chromium.orgc986af502013-08-14 01:04:44701
dongseong.hwang9e8922b2015-09-01 11:04:49702 bool force_cube_map_positive_x_allocation;
703 bool force_cube_complete;
qiankun.miao9d28c22d2017-04-20 06:22:07704 bool force_int_or_srgb_cube_texture_complete;
zmo1afe4c32016-03-14 23:37:04705 bool unpack_alignment_workaround_with_unpack_buffer;
oetuaho0a557562016-05-10 11:36:44706 bool unpack_overlapping_rows_separately_unpack_buffer;
kloveless@chromium.orgc986af502013-08-14 01:04:44707};
708
gman@chromium.orga93bb842010-02-16 23:03:47709// This class keeps track of the textures and their sizes so we can do NPOT and
710// texture complete checking.
711//
712// NOTE: To support shared resources an instance of this class will need to be
Jonathan Backerc26060e2018-03-29 15:06:29713// shared by multiple DecoderContexts.
Antoine Labour83a0aed12018-01-10 04:52:38714class GPU_GLES2_EXPORT TextureManager
715 : public base::trace_event::MemoryDumpProvider {
gman@chromium.orga93bb842010-02-16 23:03:47716 public:
Antoine Labour83a0aed12018-01-10 04:52:38717 class GPU_GLES2_EXPORT DestructionObserver {
backer@chromium.org85a4ac22013-05-31 01:58:47718 public:
719 DestructionObserver();
Peter BostrÃļmdbacdc22021-09-23 22:11:46720
721 DestructionObserver(const DestructionObserver&) = delete;
722 DestructionObserver& operator=(const DestructionObserver&) = delete;
723
backer@chromium.org85a4ac22013-05-31 01:58:47724 virtual ~DestructionObserver();
725
726 // Called in ~TextureManager.
727 virtual void OnTextureManagerDestroying(TextureManager* manager) = 0;
728
729 // Called via ~TextureRef.
730 virtual void OnTextureRefDestroying(TextureRef* texture) = 0;
backer@chromium.org85a4ac22013-05-31 01:58:47731 };
732
gman@chromium.orgc32ff8bb2011-12-23 03:31:08733 enum DefaultAndBlackTextures {
734 kTexture2D,
qiankun.miao4e2f0d02015-09-18 03:34:48735 kTexture3D,
736 kTexture2DArray,
gman@chromium.orgc32ff8bb2011-12-23 03:31:08737 kCubeMap,
738 kExternalOES,
739 kRectangleARB,
740 kNumDefaultTextures
741 };
742
Maggie Chen40af1efa2025-06-04 18:19:57743 TextureManager(scoped_refptr<MemoryTracker> memory_tracker,
ccameron@chromium.org00b192572012-07-28 04:00:22744 FeatureInfo* feature_info,
gman@chromium.org80eb6b52012-01-19 00:14:41745 GLsizei max_texture_size,
vmiura@chromium.org5ebf59f2014-04-08 03:51:57746 GLsizei max_cube_map_texture_size,
sandersd9d0bb832014-12-17 01:24:55747 GLsizei max_rectangle_texture_size,
zmoea06a6f2015-04-30 01:15:46748 GLsizei max_3d_texture_size,
zmo9bdab5d2016-05-05 04:35:27749 GLsizei max_array_texture_layers,
ericrk8767b2b2016-10-07 00:10:48750 bool use_default_textures,
Adrienne Walkera237d1802018-10-03 01:53:22751 gl::ProgressReporter* progress_reporter,
ericrkdc5eeaa2017-05-19 02:23:50752 ServiceDiscardableManager* discardable_manager);
Peter BostrÃļmdbacdc22021-09-23 22:11:46753
754 TextureManager(const TextureManager&) = delete;
755 TextureManager& operator=(const TextureManager&) = delete;
756
ericrkf08855b42015-08-06 00:20:22757 ~TextureManager() override;
gman@chromium.orgd304cbd2010-07-01 22:41:16758
c.padhi2dfc7022017-05-18 18:40:18759 void AddFramebufferManager(FramebufferManager* framebuffer_manager);
760 void RemoveFramebufferManager(FramebufferManager* framebuffer_manager);
piman@chromium.org370eaf12013-05-18 09:19:49761
gman@chromium.org00f893d2010-08-24 18:55:49762 // Init the texture manager.
danakj45cfd232017-10-18 19:31:31763 void Initialize();
gman@chromium.org00f893d2010-08-24 18:55:49764
Sadrul Habib Chowdhury3f4dc7b2017-10-31 07:44:55765 void MarkContextLost();
766
gman@chromium.orgd304cbd2010-07-01 22:41:16767 // Must call before destruction.
Sadrul Habib Chowdhury3f4dc7b2017-10-31 07:44:55768 void Destroy();
gman@chromium.orga93bb842010-02-16 23:03:47769
770 // Returns the maximum number of levels.
771 GLint MaxLevelsForTarget(GLenum target) const {
bulach@chromium.org61eeb33f2011-07-26 15:30:31772 switch (target) {
773 case GL_TEXTURE_2D:
qiankun.miaoa0d9b3e2016-02-04 01:21:33774 case GL_TEXTURE_2D_ARRAY:
ccameronb5bc7cb2015-07-22 21:50:49775 return max_levels_;
Geoff Lang8fc21cd2025-05-26 13:13:29776 case GL_TEXTURE_RECTANGLE_ANGLE:
bulach@chromium.org61eeb33f2011-07-26 15:30:31777 case GL_TEXTURE_EXTERNAL_OES:
778 return 1;
zmoea06a6f2015-04-30 01:15:46779 case GL_TEXTURE_3D:
zmoea06a6f2015-04-30 01:15:46780 return max_3d_levels_;
bulach@chromium.org61eeb33f2011-07-26 15:30:31781 default:
782 return max_cube_map_levels_;
783 }
gman@chromium.orga93bb842010-02-16 23:03:47784 }
785
786 // Returns the maximum size.
787 GLsizei MaxSizeForTarget(GLenum target) const {
bulach@chromium.org61eeb33f2011-07-26 15:30:31788 switch (target) {
789 case GL_TEXTURE_2D:
790 case GL_TEXTURE_EXTERNAL_OES:
qiankun.miaoa0d9b3e2016-02-04 01:21:33791 case GL_TEXTURE_2D_ARRAY:
bulach@chromium.org61eeb33f2011-07-26 15:30:31792 return max_texture_size_;
Geoff Lang8fc21cd2025-05-26 13:13:29793 case GL_TEXTURE_RECTANGLE_ANGLE:
sandersd9d0bb832014-12-17 01:24:55794 return max_rectangle_texture_size_;
zmoea06a6f2015-04-30 01:15:46795 case GL_TEXTURE_3D:
zmoea06a6f2015-04-30 01:15:46796 return max_3d_texture_size_;
bulach@chromium.org61eeb33f2011-07-26 15:30:31797 default:
798 return max_cube_map_texture_size_;
799 }
gman@chromium.orga93bb842010-02-16 23:03:47800 }
801
zmo9bdab5d2016-05-05 04:35:27802 GLsizei max_array_texture_layers() const {
803 return max_array_texture_layers_;
804 }
805
vangelis@chromium.org97dc7cbe2011-12-06 17:26:17806 // Returns the maxium number of levels a texture of the given size can have.
sheu@chromium.org3ecc1052013-09-26 08:59:00807 static GLsizei ComputeMipMapCount(GLenum target,
808 GLsizei width,
809 GLsizei height,
810 GLsizei depth);
vangelis@chromium.org97dc7cbe2011-12-06 17:26:17811
bajones89cc2022015-11-20 08:35:34812 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat);
813 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat);
814
gman@chromium.orga93bb842010-02-16 23:03:47815 // Checks if a dimensions are valid for a given target.
816 bool ValidForTarget(
817 GLenum target, GLint level,
gman@chromium.org656dcaad2010-05-07 17:18:37818 GLsizei width, GLsizei height, GLsizei depth);
Peng Huang6b4af5d2022-11-23 00:16:49819 bool ValidForTextureTarget(const Texture* texture,
820 GLint level,
821 GLsizei width,
822 GLsizei height,
823 GLsizei depth);
gman@chromium.org07d0cc82010-02-17 04:51:40824
gman@chromium.org80eb6b52012-01-19 00:14:41825 // True if this texture meets all the GLES2 criteria for rendering.
826 // See section 3.8.2 of the GLES2 spec.
piman@chromium.org370eaf12013-05-18 09:19:49827 bool CanRender(const TextureRef* ref) const {
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11828 return ref->texture()->CanRender(feature_info_.get());
gman@chromium.org80eb6b52012-01-19 00:14:41829 }
830
bajones7fd547652016-01-28 22:40:12831 bool CanRenderWithSampler(
832 const TextureRef* ref, const SamplerState& sampler_state) const {
833 return ref->texture()->CanRenderWithSampler(
834 feature_info_.get(), sampler_state);
835 }
836
gman@chromium.org80eb6b52012-01-19 00:14:41837 // Returns true if mipmaps can be generated by GL.
piman@chromium.org370eaf12013-05-18 09:19:49838 bool CanGenerateMipmaps(const TextureRef* ref) const {
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11839 return ref->texture()->CanGenerateMipmaps(feature_info_.get());
gman@chromium.org80eb6b52012-01-19 00:14:41840 }
841
gman@chromium.orged9f9cd2013-02-27 21:12:35842 // Sets the Texture's target
gman@chromium.org07d0cc82010-02-17 04:51:40843 // Parameters:
844 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
guanxian.li98291952015-05-12 07:11:09845 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
gman@chromium.org07d0cc82010-02-17 04:51:40846 // max_levels: The maximum levels this type of target can have.
gman@chromium.org02965c22013-03-09 02:40:07847 void SetTarget(
piman@chromium.org370eaf12013-05-18 09:19:49848 TextureRef* ref,
sievers@chromium.orgb0af4f52011-09-28 22:04:42849 GLenum target);
gman@chromium.orga93bb842010-02-16 23:03:47850
gman@chromium.orgef526492010-06-02 23:12:25851 // Set the info for a particular level in a TexureInfo.
reveman7c4a13b2015-06-05 22:28:15852 void SetLevelInfo(TextureRef* ref,
853 GLenum target,
854 GLint level,
855 GLenum internal_format,
856 GLsizei width,
857 GLsizei height,
858 GLsizei depth,
859 GLint border,
860 GLenum format,
861 GLenum type,
862 const gfx::Rect& cleared_rect);
gman@chromium.org0d6bfdc2011-11-02 01:32:20863
piman@chromium.org62e65f02013-05-29 22:28:10864 // Maps an existing texture into the texture manager, at a given client ID.
865 TextureRef* Consume(GLuint client_id, Texture* texture);
apatrick@chromium.org78b514b2012-05-01 21:50:59866
Eric Karlb1292a12018-10-17 01:20:03867 // Maps an existing SharedImage into the texture manager, at a given client
868 // ID.
869 TextureRef* ConsumeSharedImage(
870 GLuint client_id,
Saifuddin Hitawaladaed5972022-07-20 22:01:01871 std::unique_ptr<GLTextureImageRepresentation> shared_image);
Eric Karlb1292a12018-10-17 01:20:03872
reveman7c4a13b2015-06-05 22:28:15873 // Sets |rect| of mip as cleared.
874 void SetLevelClearedRect(TextureRef* ref,
875 GLenum target,
876 GLint level,
877 const gfx::Rect& cleared_rect);
878
gman@chromium.org0d6bfdc2011-11-02 01:32:20879 // Sets a mip as cleared.
piman@chromium.org370eaf12013-05-18 09:19:49880 void SetLevelCleared(TextureRef* ref, GLenum target,
jamesr@chromium.org60f22d32012-12-12 00:31:58881 GLint level, bool cleared);
gman@chromium.orgef526492010-06-02 23:12:25882
gman@chromium.orged9f9cd2013-02-27 21:12:35883 // Sets a texture parameter of a Texture
gman@chromium.org445a8762012-12-06 15:43:21884 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
zmo@chromium.org737191ee72014-03-09 08:02:42885 // TODO(gman): Expand to SetParameteriv,fv
886 void SetParameteri(
kloveless@chromium.orgd3eba342013-04-18 21:11:50887 const char* function_name, ErrorState* error_state,
piman@chromium.org370eaf12013-05-18 09:19:49888 TextureRef* ref, GLenum pname, GLint param);
zmo@chromium.org737191ee72014-03-09 08:02:42889 void SetParameterf(
890 const char* function_name, ErrorState* error_state,
891 TextureRef* ref, GLenum pname, GLfloat param);
gman@chromium.orgef526492010-06-02 23:12:25892
893 // Makes each of the mip levels as though they were generated.
zmo494a7702016-01-22 00:08:57894 void MarkMipmapsGenerated(TextureRef* ref);
gman@chromium.org0d6bfdc2011-11-02 01:32:20895
896 // Clears any uncleared renderable levels.
Jonathan Backerc26060e2018-03-29 15:06:29897 bool ClearRenderableLevels(DecoderContext* decoder, TextureRef* ref);
gman@chromium.org0d6bfdc2011-11-02 01:32:20898
899 // Clear a specific level.
Antoine Labour10dddca12019-02-19 19:09:26900 static bool ClearTextureLevel(DecoderContext* decoder,
901 TextureRef* ref,
902 GLenum target,
903 GLint level);
gman@chromium.orgef526492010-06-02 23:12:25904
Antoine Labour10dddca12019-02-19 19:09:26905 static bool ClearTextureLevel(DecoderContext* decoder,
906 Texture* texture,
907 GLenum target,
908 GLint level);
Antoine Labour9ddf6ac2019-01-17 01:59:39909
gman@chromium.orga93bb842010-02-16 23:03:47910 // Creates a new texture info.
piman@chromium.org370eaf12013-05-18 09:19:49911 TextureRef* CreateTexture(GLuint client_id, GLuint service_id);
gman@chromium.orga93bb842010-02-16 23:03:47912
913 // Gets the texture info for the given texture.
piman@chromium.org370eaf12013-05-18 09:19:49914 TextureRef* GetTexture(GLuint client_id) const;
gman@chromium.orga93bb842010-02-16 23:03:47915
ericrkdc5eeaa2017-05-19 02:23:50916 // Takes the TextureRef for the given texture out of the texture manager.
917 scoped_refptr<TextureRef> TakeTexture(GLuint client_id);
918
919 // Returns a TextureRef to the texture manager.
920 void ReturnTexture(scoped_refptr<TextureRef> texture_ref);
921
gman@chromium.orga93bb842010-02-16 23:03:47922 // Removes a texture info.
gman@chromium.orged9f9cd2013-02-27 21:12:35923 void RemoveTexture(GLuint client_id);
gman@chromium.orgae51d192010-04-27 00:48:03924
piman@chromium.org62e65f02013-05-29 22:28:10925 // Gets a Texture for a given service id (note: it assumes the texture object
926 // is still mapped in this TextureManager).
927 Texture* GetTextureForServiceId(GLuint service_id) const;
gman@chromium.orga93bb842010-02-16 23:03:47928
piman@chromium.org370eaf12013-05-18 09:19:49929 TextureRef* GetDefaultTextureInfo(GLenum target) {
bulach@chromium.org61eeb33f2011-07-26 15:30:31930 switch (target) {
931 case GL_TEXTURE_2D:
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11932 return default_textures_[kTexture2D].get();
qiankun.miao4e2f0d02015-09-18 03:34:48933 case GL_TEXTURE_3D:
934 return default_textures_[kTexture3D].get();
935 case GL_TEXTURE_2D_ARRAY:
936 return default_textures_[kTexture2DArray].get();
bulach@chromium.org61eeb33f2011-07-26 15:30:31937 case GL_TEXTURE_CUBE_MAP:
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11938 return default_textures_[kCubeMap].get();
bulach@chromium.org61eeb33f2011-07-26 15:30:31939 case GL_TEXTURE_EXTERNAL_OES:
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11940 return default_textures_[kExternalOES].get();
Geoff Lang8fc21cd2025-05-26 13:13:29941 case GL_TEXTURE_RECTANGLE_ANGLE:
rsleevi@chromium.org7cd76fd2013-06-02 21:11:11942 return default_textures_[kRectangleARB].get();
bulach@chromium.org61eeb33f2011-07-26 15:30:31943 default:
Peter BostrÃļma11556e2024-10-31 04:49:10944 NOTREACHED();
bulach@chromium.org61eeb33f2011-07-26 15:30:31945 }
gman@chromium.org1958e0e2010-04-22 05:17:15946 }
947
gman@chromium.org0d6bfdc2011-11-02 01:32:20948 bool HaveUnsafeTextures() const {
949 return num_unsafe_textures_ > 0;
950 }
951
952 bool HaveUnclearedMips() const {
953 return num_uncleared_mips_ > 0;
954 }
955
gman@chromium.org00f893d2010-08-24 18:55:49956 GLuint black_texture_id(GLenum target) const {
bulach@chromium.org61eeb33f2011-07-26 15:30:31957 switch (target) {
958 case GL_SAMPLER_2D:
gman@chromium.orgc32ff8bb2011-12-23 03:31:08959 return black_texture_ids_[kTexture2D];
qiankun.miao4e2f0d02015-09-18 03:34:48960 case GL_SAMPLER_3D:
961 return black_texture_ids_[kTexture3D];
962 case GL_SAMPLER_2D_ARRAY:
963 return black_texture_ids_[kTexture2DArray];
bulach@chromium.org61eeb33f2011-07-26 15:30:31964 case GL_SAMPLER_CUBE:
gman@chromium.orgc32ff8bb2011-12-23 03:31:08965 return black_texture_ids_[kCubeMap];
bulach@chromium.org61eeb33f2011-07-26 15:30:31966 case GL_SAMPLER_EXTERNAL_OES:
gman@chromium.orgc32ff8bb2011-12-23 03:31:08967 return black_texture_ids_[kExternalOES];
Geoff Lang8fc21cd2025-05-26 13:13:29968 case GL_SAMPLER_2D_RECT_ANGLE:
gman@chromium.orgc32ff8bb2011-12-23 03:31:08969 return black_texture_ids_[kRectangleARB];
bulach@chromium.org61eeb33f2011-07-26 15:30:31970 default:
James Darpiniand4882c02019-04-03 00:53:12971 // The above covers ES 2, but ES 3 has many more sampler types. Rather
972 // than create a texture for all of them, just use the 0 texture, which
973 // should always be incomplete, and rely on the driver to return black
974 // when sampling it. Hopefully ES 3 drivers are better about actually
975 // returning black when sampling an incomplete texture.
bulach@chromium.org61eeb33f2011-07-26 15:30:31976 return 0;
977 }
gman@chromium.org00f893d2010-08-24 18:55:49978 }
979
ccameron@chromium.org68e81a4a62012-12-13 01:16:48980 size_t mem_represented() const {
ccamerondfb2f202015-10-09 23:17:59981 return memory_type_tracker_->GetMemRepresented();
zmo@chromium.orgd5d77fc2012-06-14 01:37:17982 }
983
dyencb017312014-09-29 18:16:20984 size_t GetSignatureSize() const;
985
gman@chromium.org73276522012-11-09 05:50:20986 void AddToSignature(
piman@chromium.org370eaf12013-05-18 09:19:49987 TextureRef* ref,
gman@chromium.org73276522012-11-09 05:50:20988 GLenum target,
989 GLint level,
990 std::string* signature) const;
991
backer@chromium.org85a4ac22013-05-31 01:58:47992 void AddObserver(DestructionObserver* observer) {
vmiura@chromium.org35bd3442014-04-23 23:31:03993 destruction_observers_.push_back(observer);
backer@chromium.org85a4ac22013-05-31 01:58:47994 }
995
996 void RemoveObserver(DestructionObserver* observer) {
vmiura@chromium.org35bd3442014-04-23 23:31:03997 for (unsigned int i = 0; i < destruction_observers_.size(); i++) {
998 if (destruction_observers_[i] == observer) {
999 std::swap(destruction_observers_[i], destruction_observers_.back());
1000 destruction_observers_.pop_back();
1001 return;
1002 }
1003 }
Peter BostrÃļma11556e2024-10-31 04:49:101004 NOTREACHED();
backer@chromium.org85a4ac22013-05-31 01:58:471005 }
1006
zmode7b4382015-05-21 21:23:001007 struct DoTexImageArguments {
Dave Tapuskab8a73b32019-09-10 13:38:391008 enum class CommandType {
zmo54f23712015-05-28 19:28:491009 kTexImage2D,
1010 kTexImage3D,
1011 };
1012
kloveless@chromium.orgc986af502013-08-14 01:04:441013 GLenum target;
1014 GLint level;
1015 GLenum internal_format;
1016 GLsizei width;
1017 GLsizei height;
zmode7b4382015-05-21 21:23:001018 GLsizei depth;
kloveless@chromium.orgc986af502013-08-14 01:04:441019 GLint border;
1020 GLenum format;
1021 GLenum type;
Keishi Hattoric1b00232022-11-22 09:04:261022 // `pixels` is not a raw_ptr<...> to avoid adding an out-of-line destructor.
1023 RAW_PTR_EXCLUSION const void* pixels;
avif15d60a2015-12-21 17:06:331024 uint32_t pixels_size;
zmo1afe4c32016-03-14 23:37:041025 uint32_t padding;
Dave Tapuskab8a73b32019-09-10 13:38:391026 CommandType command_type;
kloveless@chromium.orgc986af502013-08-14 01:04:441027 };
1028
Peng Huangb4ed1852018-12-05 03:35:291029 bool ValidateTexImage(ContextState* state,
1030 ErrorState* error_state,
1031 const char* function_name,
1032 const DoTexImageArguments& args,
1033 // Pointer to TextureRef filled in if validation
1034 // successful. Presumes the pointer is valid.
1035 TextureRef** texture_ref);
kloveless@chromium.orgc986af502013-08-14 01:04:441036
Peng Huangb4ed1852018-12-05 03:35:291037 void ValidateAndDoTexImage(DecoderTextureState* texture_state,
1038 ContextState* state,
1039 ErrorState* error_state,
1040 DecoderFramebufferState* framebuffer_state,
1041 const char* function_name,
1042 const DoTexImageArguments& args);
kloveless@chromium.orgc986af502013-08-14 01:04:441043
kkinnunen0c2dee72015-11-09 11:13:581044 struct DoTexSubImageArguments {
Dave Tapuskab8a73b32019-09-10 13:38:391045 enum class CommandType {
zmoec8cab4d2016-02-17 02:07:251046 kTexSubImage2D,
1047 kTexSubImage3D,
1048 };
1049
kkinnunen0c2dee72015-11-09 11:13:581050 GLenum target;
1051 GLint level;
1052 GLint xoffset;
1053 GLint yoffset;
zmoec8cab4d2016-02-17 02:07:251054 GLint zoffset;
kkinnunen0c2dee72015-11-09 11:13:581055 GLsizei width;
1056 GLsizei height;
zmoec8cab4d2016-02-17 02:07:251057 GLsizei depth;
kkinnunen0c2dee72015-11-09 11:13:581058 GLenum format;
1059 GLenum type;
Keishi Hattoric1b00232022-11-22 09:04:261060 // `pixels` is not a raw_ptr<...> to avoid adding an out-of-line destructor.
1061 RAW_PTR_EXCLUSION const void* pixels;
avif15d60a2015-12-21 17:06:331062 uint32_t pixels_size;
zmo1afe4c32016-03-14 23:37:041063 uint32_t padding;
Dave Tapuskab8a73b32019-09-10 13:38:391064 CommandType command_type;
kkinnunen0c2dee72015-11-09 11:13:581065 };
1066
Peng Huangb4ed1852018-12-05 03:35:291067 bool ValidateTexSubImage(ContextState* state,
1068 ErrorState* error_state,
1069 const char* function_name,
1070 const DoTexSubImageArguments& args,
1071 // Pointer to TextureRef filled in if validation
1072 // successful. Presumes the pointer is valid.
1073 TextureRef** texture_ref);
kkinnunen0c2dee72015-11-09 11:13:581074
Jonathan Backerc26060e2018-03-29 15:06:291075 void ValidateAndDoTexSubImage(DecoderContext* decoder,
kkinnunen0c2dee72015-11-09 11:13:581076 DecoderTextureState* texture_state,
1077 ContextState* state,
Peng Huangb4ed1852018-12-05 03:35:291078 ErrorState* error_state,
kkinnunen0c2dee72015-11-09 11:13:581079 DecoderFramebufferState* framebuffer_state,
1080 const char* function_name,
1081 const DoTexSubImageArguments& args);
1082
kloveless@chromium.orgc986af502013-08-14 01:04:441083 // TODO(kloveless): Make GetTexture* private once this is no longer called
1084 // from gles2_cmd_decoder.
1085 TextureRef* GetTextureInfoForTarget(ContextState* state, GLenum target);
1086 TextureRef* GetTextureInfoForTargetUnlessDefault(
1087 ContextState* state, GLenum target);
1088
yunchao.hef3130b42016-02-27 06:09:241089 // This function is used to validate TexImage2D and TexSubImage2D and their
1090 // variants. But internal_format only checked for callers of TexImage2D and
1091 // its variants (tex_image_call is true).
kloveless@chromium.orgc986af502013-08-14 01:04:441092 bool ValidateTextureParameters(
yunchao.hef3130b42016-02-27 06:09:241093 ErrorState* error_state, const char* function_name, bool tex_image_call,
qiankun.miaoa4d257012016-01-21 02:21:081094 GLenum format, GLenum type, GLint internal_format, GLint level);
kloveless@chromium.orgc986af502013-08-14 01:04:441095
ericrkf08855b42015-08-06 00:20:221096 // base::trace_event::MemoryDumpProvider implementation.
ssid90694aeec2015-08-06 13:01:301097 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
1098 base::trace_event::ProcessMemoryDump* pmd) override;
ericrkf08855b42015-08-06 00:20:221099
kkinnunen0c2dee72015-11-09 11:13:581100 // Returns the union of |rect1| and |rect2| if one of the rectangles is empty,
1101 // contains the other rectangle or shares an edge with the other rectangle.
1102 // Part of the public interface because texture pixel data rectangle
1103 // operations are also implemented in decoder at the moment.
1104 static bool CombineAdjacentRects(const gfx::Rect& rect1,
1105 const gfx::Rect& rect2,
1106 gfx::Rect* result);
1107
liberato774cc112016-01-15 16:20:491108 // Get / set the current generation number of this manager. This generation
1109 // number changes whenever the service_id of one or more Textures change.
1110 uint32_t GetServiceIdGeneration() const;
1111 void IncrementServiceIdGeneration();
1112
Antoine Laboura36c7232018-08-02 04:31:021113 static const Texture::CompatibilitySwizzle* GetCompatibilitySwizzle(
1114 const gles2::FeatureInfo* feature_info,
1115 GLenum format);
geofflangb205ab62016-06-13 21:24:441116 static GLenum AdjustTexInternalFormat(const gles2::FeatureInfo* feature_info,
James Darpiniand4882c02019-04-03 00:53:121117 GLenum format,
1118 GLenum type);
geofflangb205ab62016-06-13 21:24:441119 static GLenum AdjustTexFormat(const gles2::FeatureInfo* feature_info,
1120 GLenum format);
bajones2c9d7182016-03-11 18:16:281121
Sunny Sachanandani17c1754e2018-02-28 02:06:241122 static GLenum AdjustTexStorageFormat(const gles2::FeatureInfo* feature_info,
1123 GLenum format);
1124
Peng Huangb4ed1852018-12-05 03:35:291125 void WorkaroundCopyTexImageCubeMap(DecoderTextureState* texture_state,
1126 ContextState* state,
1127 ErrorState* error_state,
1128 DecoderFramebufferState* framebuffer_state,
1129 TextureRef* texture_ref,
1130 const char* function_name,
1131 const DoTexImageArguments& args) {
1132 DoCubeMapWorkaround(texture_state, state, error_state, framebuffer_state,
qiankun.miao45903b62016-09-23 04:28:581133 texture_ref, function_name, args);
1134 }
1135
gman@chromium.orga93bb842010-02-16 23:03:471136 private:
gman@chromium.orged9f9cd2013-02-27 21:12:351137 friend class Texture;
piman@chromium.org370eaf12013-05-18 09:19:491138 friend class TextureRef;
gman@chromium.orged9f9cd2013-02-27 21:12:351139
kbr@chromium.orge51bdf32011-11-23 22:21:461140 // Helper for Initialize().
piman@chromium.org370eaf12013-05-18 09:19:491141 scoped_refptr<TextureRef> CreateDefaultAndBlackTextures(
kbr@chromium.orge51bdf32011-11-23 22:21:461142 GLenum target,
1143 GLuint* black_texture);
1144
Peng Huangb4ed1852018-12-05 03:35:291145 void DoTexImage(DecoderTextureState* texture_state,
1146 ContextState* state,
1147 ErrorState* error_state,
1148 DecoderFramebufferState* framebuffer_state,
1149 const char* function_name,
1150 TextureRef* texture_ref,
1151 const DoTexImageArguments& args);
zmo1afe4c32016-03-14 23:37:041152
oetuaho0a557562016-05-10 11:36:441153 // Reserve memory for the texture and set its attributes so it can be filled
1154 // with TexSubImage. The image contents are undefined after this function,
1155 // so make sure it's subsequently filled in its entirety.
1156 void ReserveTexImageToBeFilled(DecoderTextureState* texture_state,
1157 ContextState* state,
Peng Huangb4ed1852018-12-05 03:35:291158 ErrorState* error_state,
oetuaho0a557562016-05-10 11:36:441159 DecoderFramebufferState* framebuffer_state,
1160 const char* function_name,
1161 TextureRef* texture_ref,
1162 const DoTexImageArguments& args);
1163
zmo1afe4c32016-03-14 23:37:041164 void DoTexSubImageWithAlignmentWorkaround(
1165 DecoderTextureState* texture_state,
1166 ContextState* state,
1167 const DoTexSubImageArguments& args);
kloveless@chromium.orgc986af502013-08-14 01:04:441168
oetuaho0a557562016-05-10 11:36:441169 void DoTexSubImageRowByRowWorkaround(DecoderTextureState* texture_state,
1170 ContextState* state,
1171 const DoTexSubImageArguments& args,
1172 const PixelStoreParams& unpack_params);
1173
jiajia.qina4598752016-10-18 02:04:191174 void DoTexSubImageLayerByLayerWorkaround(
1175 DecoderTextureState* texture_state,
1176 ContextState* state,
1177 const DoTexSubImageArguments& args,
1178 const PixelStoreParams& unpack_params);
1179
Peng Huangb4ed1852018-12-05 03:35:291180 void DoCubeMapWorkaround(DecoderTextureState* texture_state,
1181 ContextState* state,
1182 ErrorState* error_state,
1183 DecoderFramebufferState* framebuffer_state,
1184 TextureRef* texture_ref,
1185 const char* function_name,
1186 const DoTexImageArguments& args);
qiankun.miao45903b62016-09-23 04:28:581187
piman@chromium.org370eaf12013-05-18 09:19:491188 void StartTracking(TextureRef* texture);
1189 void StopTracking(TextureRef* texture);
1190
1191 void UpdateSafeToRenderFrom(int delta);
1192 void UpdateUnclearedMips(int delta);
1193 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition,
1194 Texture::CanRenderCondition new_condition);
reveman@chromium.org91c94eb2013-10-22 10:32:541195 void UpdateNumImages(int delta);
piman@chromium.org370eaf12013-05-18 09:19:491196 void IncFramebufferStateChangeCount();
gman@chromium.org80eb6b52012-01-19 00:14:411197
ericrkf08855b42015-08-06 00:20:221198 // Helper function called by OnMemoryDump.
1199 void DumpTextureRef(base::trace_event::ProcessMemoryDump* pmd,
1200 TextureRef* ref);
1201
ccamerondfb2f202015-10-09 23:17:591202 MemoryTypeTracker* GetMemTracker();
mostynb6682b1c42016-04-19 10:17:301203 std::unique_ptr<MemoryTypeTracker> memory_type_tracker_;
ccameron@chromium.org00b192572012-07-28 04:00:221204
gman@chromium.orged9f9cd2013-02-27 21:12:351205 scoped_refptr<FeatureInfo> feature_info_;
gman@chromium.org80eb6b52012-01-19 00:14:411206
Ali Hijazie63cbaf62023-12-20 19:29:351207 std::vector<raw_ptr<FramebufferManager, VectorExperimental>>
1208 framebuffer_managers_;
piman@chromium.org370eaf12013-05-18 09:19:491209
gman@chromium.orga93bb842010-02-16 23:03:471210 // Info for each texture in the system.
Takuto Ikutaadf31eb2019-01-05 00:32:481211 typedef std::unordered_map<GLuint, scoped_refptr<TextureRef>> TextureMap;
gman@chromium.org02965c22013-03-09 02:40:071212 TextureMap textures_;
gman@chromium.orga93bb842010-02-16 23:03:471213
1214 GLsizei max_texture_size_;
1215 GLsizei max_cube_map_texture_size_;
sandersd9d0bb832014-12-17 01:24:551216 GLsizei max_rectangle_texture_size_;
zmoea06a6f2015-04-30 01:15:461217 GLsizei max_3d_texture_size_;
zmo9bdab5d2016-05-05 04:35:271218 GLsizei max_array_texture_layers_;
gman@chromium.orga93bb842010-02-16 23:03:471219 GLint max_levels_;
1220 GLint max_cube_map_levels_;
zmoea06a6f2015-04-30 01:15:461221 GLint max_3d_levels_;
gman@chromium.orga93bb842010-02-16 23:03:471222
vmiura@chromium.org5ebf59f2014-04-08 03:51:571223 const bool use_default_textures_;
1224
gman@chromium.org0d6bfdc2011-11-02 01:32:201225 int num_unsafe_textures_;
1226 int num_uncleared_mips_;
gman@chromium.orgef526492010-06-02 23:12:251227
gman@chromium.org02965c22013-03-09 02:40:071228 // Counts the number of Textures allocated with 'this' as its manager.
gman@chromium.orged9f9cd2013-02-27 21:12:351229 // Allows to check no Texture will outlive this.
gman@chromium.org02965c22013-03-09 02:40:071230 unsigned int texture_count_;
piman@chromium.orgc826d732012-02-09 04:40:261231
gman@chromium.orgfe6f29f2012-04-05 20:17:411232 bool have_context_;
1233
gman@chromium.org00f893d2010-08-24 18:55:491234 // Black (0,0,0,1) textures for when non-renderable textures are used.
gman@chromium.orged9f9cd2013-02-27 21:12:351235 // NOTE: There is no corresponding Texture for these textures.
gman@chromium.org00f893d2010-08-24 18:55:491236 // TextureInfos are only for textures the client side can access.
Stephen Nuskof4e53402025-07-23 13:39:441237 std::array<GLuint, kNumDefaultTextures> black_texture_ids_;
gman@chromium.org00f893d2010-08-24 18:55:491238
gman@chromium.org1958e0e2010-04-22 05:17:151239 // The default textures for each target (texture name = 0)
Kalvin Lee9e2c2e82025-04-16 22:37:421240 std::array<scoped_refptr<TextureRef>, kNumDefaultTextures> default_textures_;
gman@chromium.org1958e0e2010-04-22 05:17:151241
Ali Hijazie63cbaf62023-12-20 19:29:351242 std::vector<raw_ptr<DestructionObserver, VectorExperimental>>
1243 destruction_observers_;
backer@chromium.org85a4ac22013-05-31 01:58:471244
liberato774cc112016-01-15 16:20:491245 uint32_t current_service_id_generation_;
1246
ericrk8767b2b2016-10-07 00:10:481247 // Used to notify the watchdog thread of progress during destruction,
1248 // preventing time-outs when destruction takes a long time. May be null when
1249 // using in-process command buffer.
Keishi Hattori0e45c022021-11-27 09:25:521250 raw_ptr<gl::ProgressReporter> progress_reporter_;
ericrk8767b2b2016-10-07 00:10:481251
Keishi Hattori0e45c022021-11-27 09:25:521252 raw_ptr<ServiceDiscardableManager> discardable_manager_;
gman@chromium.orga93bb842010-02-16 23:03:471253};
1254
1255} // namespace gles2
1256} // namespace gpu
1257
1258#endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_