rsFBOCache.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2011 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 "rsFBOCache.h"
  17. #include "rsContext.h"
  18. #include "rsAllocation.h"
  19. namespace android {
  20. namespace renderscript {
  21. FBOCache::FBOCache() {
  22. mDirty = true;
  23. mHal.state.colorTargetsCount = 1;
  24. mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
  25. mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
  26. resetAll(nullptr);
  27. }
  28. FBOCache::~FBOCache() {
  29. delete[] mHal.state.colorTargets;
  30. delete[] mColorTargets;
  31. }
  32. void FBOCache::init(Context *rsc) {
  33. rsc->mHal.funcs.framebuffer.init(rsc, this);
  34. }
  35. void FBOCache::deinit(Context *rsc) {
  36. rsc->mHal.funcs.framebuffer.destroy(rsc, this);
  37. }
  38. void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
  39. if (slot >= mHal.state.colorTargetsCount) {
  40. ALOGE("Invalid render target index");
  41. return;
  42. }
  43. if (a != nullptr) {
  44. if (!(a->getIsTexture() || (a->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT))) {
  45. ALOGE("Invalid Color Target");
  46. return;
  47. }
  48. }
  49. mColorTargets[slot].set(a);
  50. mHal.state.colorTargets[slot] = a;
  51. mDirty = true;
  52. }
  53. void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
  54. if (a != nullptr) {
  55. if (!a->getIsRenderTarget()) {
  56. ALOGE("Invalid Depth Target");
  57. return;
  58. }
  59. }
  60. mDepthTarget.set(a);
  61. mHal.state.depthTarget = a;
  62. mDirty = true;
  63. }
  64. void FBOCache::resetAll(Context *) {
  65. for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
  66. mColorTargets[i].set(nullptr);
  67. mHal.state.colorTargets[i] = nullptr;
  68. }
  69. mDepthTarget.set(nullptr);
  70. mHal.state.depthTarget = nullptr;
  71. mDirty = true;
  72. }
  73. void FBOCache::setup(Context *rsc) {
  74. if (!mDirty) {
  75. return;
  76. }
  77. rsc->mHal.funcs.framebuffer.setActive(rsc, this);
  78. mDirty = false;
  79. }
  80. } // namespace renderscript
  81. } // namespace android