LayerDim.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2007 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 <stdlib.h>
  17. #include <stdint.h>
  18. #include <sys/types.h>
  19. #include <utils/Errors.h>
  20. #include <utils/Log.h>
  21. #include <ui/GraphicBuffer.h>
  22. #include "LayerDim.h"
  23. #include "SurfaceFlinger.h"
  24. #include "DisplayDevice.h"
  25. #include "RenderEngine/RenderEngine.h"
  26. namespace android {
  27. // ---------------------------------------------------------------------------
  28. LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client,
  29. const String8& name, uint32_t w, uint32_t h, uint32_t flags)
  30. : Layer(flinger, client, name, w, h, flags) {
  31. }
  32. LayerDim::~LayerDim() {
  33. }
  34. void LayerDim::onDraw(const sp<const DisplayDevice>& hw,
  35. const Region& /* clip */, bool useIdentityTransform)
  36. {
  37. const State& s(getDrawingState());
  38. if (s.alpha>0) {
  39. Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2);
  40. computeGeometry(hw, mesh, useIdentityTransform);
  41. RenderEngine& engine(mFlinger->getRenderEngine());
  42. engine.setupDimLayerBlending(s.alpha);
  43. engine.drawMesh(mesh);
  44. engine.disableBlending();
  45. }
  46. }
  47. bool LayerDim::isVisible() const {
  48. const Layer::State& s(getDrawingState());
  49. return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
  50. }
  51. void LayerDim::setPerFrameData(const sp<const DisplayDevice>& hw,
  52. HWComposer::HWCLayerInterface& layer) {
  53. HWComposer& hwc = mFlinger->getHwComposer();
  54. Layer::setPerFrameData(hw, layer);
  55. if (hwc.hasDimComposition()) {
  56. layer.setDim();
  57. }
  58. }
  59. // ---------------------------------------------------------------------------
  60. }; // namespace android