rsProgramRaster.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "rsContext.h"
  17. #include "rsProgramRaster.h"
  18. namespace android {
  19. namespace renderscript {
  20. ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull)
  21. : ProgramBase(rsc) {
  22. memset(&mHal, 0, sizeof(mHal));
  23. mHal.state.pointSprite = pointSprite;
  24. mHal.state.cull = cull;
  25. rsc->mHal.funcs.raster.init(rsc, this);
  26. }
  27. void ProgramRaster::preDestroy() const {
  28. auto& rasterPrograms = mRSC->mStateRaster.mRasterPrograms;
  29. for (uint32_t ct = 0; ct < rasterPrograms.size(); ct++) {
  30. if (rasterPrograms[ct] == this) {
  31. rasterPrograms.erase(rasterPrograms.begin() + ct);
  32. break;
  33. }
  34. }
  35. }
  36. ProgramRaster::~ProgramRaster() {
  37. mRSC->mHal.funcs.raster.destroy(mRSC, this);
  38. }
  39. void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
  40. if (state->mLast.get() == this && !mDirty) {
  41. return;
  42. }
  43. state->mLast.set(this);
  44. mDirty = false;
  45. rsc->mHal.funcs.raster.setActive(rsc, this);
  46. }
  47. void ProgramRaster::serialize(Context *rsc, OStream *stream) const {
  48. }
  49. ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
  50. return nullptr;
  51. }
  52. ProgramRasterState::ProgramRasterState() {
  53. }
  54. ProgramRasterState::~ProgramRasterState() {
  55. }
  56. void ProgramRasterState::init(Context *rsc) {
  57. mDefault.set(ProgramRaster::getProgramRaster(rsc, false, RS_CULL_BACK).get());
  58. }
  59. void ProgramRasterState::deinit(Context *rsc) {
  60. mDefault.clear();
  61. mLast.clear();
  62. }
  63. ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc,
  64. bool pointSprite,
  65. RsCullMode cull) {
  66. ObjectBaseRef<ProgramRaster> returnRef;
  67. ObjectBase::asyncLock();
  68. for (uint32_t ct = 0; ct < rsc->mStateRaster.mRasterPrograms.size(); ct++) {
  69. ProgramRaster *existing = rsc->mStateRaster.mRasterPrograms[ct];
  70. if (existing->mHal.state.pointSprite != pointSprite) continue;
  71. if (existing->mHal.state.cull != cull) continue;
  72. returnRef.set(existing);
  73. ObjectBase::asyncUnlock();
  74. return returnRef;
  75. }
  76. ObjectBase::asyncUnlock();
  77. ProgramRaster *pr = new ProgramRaster(rsc, pointSprite, cull);
  78. returnRef.set(pr);
  79. ObjectBase::asyncLock();
  80. rsc->mStateRaster.mRasterPrograms.push_back(pr);
  81. ObjectBase::asyncUnlock();
  82. return returnRef;
  83. }
  84. RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullMode cull) {
  85. ObjectBaseRef<ProgramRaster> pr = ProgramRaster::getProgramRaster(rsc, pointSprite, cull);
  86. pr->incUserRef();
  87. return pr.get();
  88. }
  89. } // namespace renderscript
  90. } // namespace android