rsSampler.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_RS_SAMPLER_H
  17. #define ANDROID_RS_SAMPLER_H
  18. #include "rsAllocation.h"
  19. #include <vector>
  20. // ---------------------------------------------------------------------------
  21. namespace android {
  22. namespace renderscript {
  23. const static uint32_t RS_MAX_SAMPLER_SLOT = 16;
  24. class SamplerState;
  25. /*****************************************************************************
  26. * CAUTION
  27. *
  28. * Any layout changes for this class may require a corresponding change to be
  29. * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
  30. * a partial copy of the information below.
  31. *
  32. *****************************************************************************/
  33. class Sampler : public ObjectBase {
  34. public:
  35. struct Hal {
  36. mutable void *drv;
  37. struct State {
  38. RsSamplerValue magFilter;
  39. RsSamplerValue minFilter;
  40. RsSamplerValue wrapS;
  41. RsSamplerValue wrapT;
  42. RsSamplerValue wrapR;
  43. float aniso;
  44. };
  45. State state;
  46. };
  47. Hal mHal;
  48. void operator delete(void* ptr);
  49. static ObjectBaseRef<Sampler> getSampler(Context *,
  50. RsSamplerValue magFilter,
  51. RsSamplerValue minFilter,
  52. RsSamplerValue wrapS,
  53. RsSamplerValue wrapT,
  54. RsSamplerValue wrapR,
  55. float aniso = 1.0f);
  56. void bindToContext(SamplerState *, uint32_t slot);
  57. void unbindFromContext(SamplerState *);
  58. virtual void serialize(Context *rsc, OStream *stream) const;
  59. virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
  60. static Sampler *createFromStream(Context *rsc, IStream *stream);
  61. protected:
  62. int32_t mBoundSlot;
  63. virtual void preDestroy() const;
  64. virtual ~Sampler();
  65. private:
  66. explicit Sampler(Context *);
  67. Sampler(Context *,
  68. RsSamplerValue magFilter,
  69. RsSamplerValue minFilter,
  70. RsSamplerValue wrapS,
  71. RsSamplerValue wrapT,
  72. RsSamplerValue wrapR,
  73. float aniso = 1.0f);
  74. };
  75. class SamplerState {
  76. public:
  77. ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
  78. void init(Context *rsc) {
  79. }
  80. void deinit(Context *rsc) {
  81. for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) {
  82. mSamplers[i].clear();
  83. }
  84. }
  85. // Cache of all existing raster programs.
  86. std::vector<Sampler *> mAllSamplers;
  87. };
  88. } // namespace renderscript
  89. } // namespace android
  90. #endif //ANDROID_RS_SAMPLER_H