WebGLActiveInfo.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef WEBGL_ACTIVE_INFO_H_
  6. #define WEBGL_ACTIVE_INFO_H_
  7. #include "GLDefs.h"
  8. #include "mozilla/Attributes.h"
  9. #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS
  10. #include "nsISupportsImpl.h" // NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING
  11. #include "nsString.h"
  12. #include "nsWrapperCache.h"
  13. namespace mozilla {
  14. class WebGLContext;
  15. class WebGLActiveInfo final
  16. : public nsWrapperCache
  17. {
  18. public:
  19. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLActiveInfo)
  20. NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLActiveInfo)
  21. virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
  22. WebGLContext* GetParentObject() const {
  23. return mWebGL;
  24. }
  25. WebGLContext* const mWebGL;
  26. // ActiveInfo state:
  27. const uint32_t mElemCount; // `size`
  28. const GLenum mElemType; // `type`
  29. const nsCString mBaseUserName; // `name`, but ASCII, and without any final "[0]".
  30. // Not actually part of ActiveInfo:
  31. const bool mIsArray;
  32. const uint8_t mElemSize;
  33. const nsCString mBaseMappedName; // Without any final "[0]".
  34. bool IsSampler() const;
  35. WebGLActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum elemType, bool isArray,
  36. const nsACString& baseUserName, const nsACString& baseMappedName);
  37. /* GLES 2.0.25, p33:
  38. * This command will return as much information about active
  39. * attributes as possible. If no information is available, length will
  40. * be set to zero and name will be an empty string. This situation
  41. * could arise if GetActiveAttrib is issued after a failed link.
  42. *
  43. * It's the same for GetActiveUniform.
  44. */
  45. static WebGLActiveInfo* CreateInvalid(WebGLContext* webgl) {
  46. return new WebGLActiveInfo(webgl);
  47. }
  48. // WebIDL attributes
  49. GLint Size() const {
  50. return mElemCount;
  51. }
  52. GLenum Type() const {
  53. return mElemType;
  54. }
  55. void GetName(nsString& retval) const {
  56. CopyASCIItoUTF16(mBaseUserName, retval);
  57. if (mIsArray)
  58. retval.AppendLiteral("[0]");
  59. }
  60. private:
  61. explicit WebGLActiveInfo(WebGLContext* webgl)
  62. : mWebGL(webgl)
  63. , mElemCount(0)
  64. , mElemType(0)
  65. , mBaseUserName("")
  66. , mIsArray(false)
  67. , mElemSize(0)
  68. , mBaseMappedName("")
  69. { }
  70. // Private destructor, to discourage deletion outside of Release():
  71. ~WebGLActiveInfo() { }
  72. };
  73. //////////
  74. bool IsElemTypeSampler(GLenum elemType);
  75. } // namespace mozilla
  76. #endif // WEBGL_ACTIVE_INFO_H_