ANativeObjectBase.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_ANDROID_NATIVES_H
  17. #define ANDROID_ANDROID_NATIVES_H
  18. #include <sys/types.h>
  19. #include <string.h>
  20. #include <hardware/gralloc.h>
  21. #include <system/window.h>
  22. // ---------------------------------------------------------------------------
  23. /* FIXME: this is legacy for pixmaps */
  24. typedef struct egl_native_pixmap_t
  25. {
  26. int32_t version; /* must be 32 */
  27. int32_t width;
  28. int32_t height;
  29. int32_t stride;
  30. uint8_t* data;
  31. uint8_t format;
  32. uint8_t rfu[3];
  33. union {
  34. uint32_t compressedFormat;
  35. int32_t vstride;
  36. };
  37. int32_t reserved;
  38. } egl_native_pixmap_t;
  39. /*****************************************************************************/
  40. #ifdef __cplusplus
  41. #include <utils/RefBase.h>
  42. namespace android {
  43. /*
  44. * This helper class turns a ANativeXXX object type into a C++
  45. * reference-counted object; with proper type conversions.
  46. */
  47. template <typename NATIVE_TYPE, typename TYPE, typename REF>
  48. class ANativeObjectBase : public NATIVE_TYPE, public REF
  49. {
  50. public:
  51. // Disambiguate between the incStrong in REF and NATIVE_TYPE
  52. void incStrong(const void* id) const {
  53. REF::incStrong(id);
  54. }
  55. void decStrong(const void* id) const {
  56. REF::decStrong(id);
  57. }
  58. protected:
  59. typedef ANativeObjectBase<NATIVE_TYPE, TYPE, REF> BASE;
  60. ANativeObjectBase() : NATIVE_TYPE(), REF() {
  61. NATIVE_TYPE::common.incRef = incRef;
  62. NATIVE_TYPE::common.decRef = decRef;
  63. }
  64. static inline TYPE* getSelf(NATIVE_TYPE* self) {
  65. return static_cast<TYPE*>(self);
  66. }
  67. static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
  68. return static_cast<TYPE const *>(self);
  69. }
  70. static inline TYPE* getSelf(android_native_base_t* base) {
  71. return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
  72. }
  73. static inline TYPE const * getSelf(android_native_base_t const* base) {
  74. return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
  75. }
  76. static void incRef(android_native_base_t* base) {
  77. ANativeObjectBase* self = getSelf(base);
  78. self->incStrong(self);
  79. }
  80. static void decRef(android_native_base_t* base) {
  81. ANativeObjectBase* self = getSelf(base);
  82. self->decStrong(self);
  83. }
  84. };
  85. } // namespace android
  86. #endif // __cplusplus
  87. /*****************************************************************************/
  88. #endif /* ANDROID_ANDROID_NATIVES_H */