LayerBlur.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  3. * Not a Contribution.
  4. *
  5. * Copyright (C) 2007 The Android Open Source Project
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #ifndef ANDROID_LAYER_BLUR_H
  20. #define ANDROID_LAYER_BLUR_H
  21. #include <stdlib.h>
  22. #include <stdint.h>
  23. #include <sys/types.h>
  24. #include "Layer.h"
  25. // ---------------------------------------------------------------------------
  26. namespace android {
  27. /**
  28. * Blur layer object.
  29. * Actual blurring logics are capsulated in libuiblur.so
  30. */
  31. class LayerBlur : public Layer
  32. {
  33. public:
  34. LayerBlur(SurfaceFlinger* flinger, const sp<Client>& client,
  35. const String8& name, uint32_t w, uint32_t h, uint32_t flags);
  36. virtual ~LayerBlur();
  37. virtual const char* getTypeId() const { return "LayerBlur"; }
  38. virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
  39. bool useIdentityTransform);
  40. virtual bool isOpaque(const Layer::State& /*s*/) const { return false; }
  41. virtual bool isSecure() const { return false; }
  42. virtual bool isFixedSize() const { return true; }
  43. virtual bool isVisible() const;
  44. virtual bool isBlurLayer() const { return true; }
  45. virtual bool setBlurMaskLayer(sp<Layer>& maskLayer);
  46. virtual bool setBlurMaskSampling(int32_t sampling) { mBlurMaskSampling = sampling; return true; }
  47. virtual bool setBlurMaskAlphaThreshold(float alpha) { mBlurMaskAlphaThreshold = alpha; return true; }
  48. private:
  49. class BlurImpl {
  50. public:
  51. BlurImpl();
  52. ~BlurImpl();
  53. status_t blur(int level, uint32_t inId, size_t inWidth, size_t inheight,
  54. uint32_t outId, size_t* outWidth, size_t* outHeight);
  55. protected:
  56. static status_t initBlurImpl();
  57. static void closeBlurImpl();
  58. static void* sLibHandle;
  59. static bool sUnsupported;
  60. typedef void* (*initBlurTokenFn)();
  61. typedef void* (*releaseBlurTokenFn)(void*);
  62. typedef void* (*blurFn)(void*, int, uint32_t, size_t, size_t, uint32_t, size_t*, size_t*);
  63. static initBlurTokenFn initBlurToken;
  64. static releaseBlurTokenFn releaseBlurToken;
  65. static blurFn doBlur;
  66. static Mutex sLock;
  67. private:
  68. void* mToken;
  69. };
  70. BlurImpl mBlurImpl;
  71. wp<Layer> mBlurMaskLayer;
  72. int32_t mBlurMaskSampling;
  73. float mBlurMaskAlphaThreshold;
  74. uint32_t mLastFrameSequence;
  75. class FBO {
  76. public:
  77. FBO() : fbo(0), width(0), height(0) {}
  78. int fbo;
  79. int width;
  80. int height;
  81. };
  82. void initFbo(FBO& fbo, int width, int height, int textureName);
  83. void releaseFbo(FBO& fbo);
  84. void ensureFbo(FBO& fbo, int width, int height, int textureName);
  85. FBO mFboCapture;
  86. Texture mTextureCapture;
  87. Texture mTextureBlur;
  88. FBO mFboMasking;
  89. Texture mTextureMasking;
  90. bool captureScreen(const sp<const DisplayDevice>& hw,
  91. FBO& fbo, Texture& texture, int width, int height);
  92. void doDrawFinal(const sp<const DisplayDevice>& hw,
  93. int savedViewportWidth, int savedViewportHeight,
  94. Rect savedProjectionSourceCrop, bool savedProjectionYSwap,
  95. Transform::orientation_flags savedRotation, bool useIdentityTransform,
  96. Texture* maskTexture);
  97. bool drawMaskLayer(sp<Layer>& maskLayer, const sp<const DisplayDevice>& hw,
  98. FBO& fbo, int width, int height, int sampling, Texture& texture);
  99. };
  100. // ---------------------------------------------------------------------------
  101. }; // namespace android
  102. #endif // ANDROID_LAYER_BLUR_H