shadow.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PDF_DRAW_UTILS_SHADOW_H_
  5. #define PDF_DRAW_UTILS_SHADOW_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. class SkBitmap;
  9. namespace gfx {
  10. class Rect;
  11. } // namespace gfx
  12. namespace chrome_pdf {
  13. namespace draw_utils {
  14. // Shadow Matrix contains matrix for shadow rendering. To reduce amount of
  15. // calculations user may choose to cache matrix and reuse it if nothing changed.
  16. class ShadowMatrix {
  17. public:
  18. // Matrix parameters.
  19. // depth - how big matrix should be. Shadow will go smoothly across the
  20. // entire matrix from black to background color.
  21. // If factor == 1, smoothing will be linear from 0 to the end (depth),
  22. // if 0 < factor < 1, smoothing will drop faster near 0.
  23. // if factor > 1, smoothing will drop faster near the end (depth).
  24. ShadowMatrix(uint32_t depth, double factor, uint32_t background);
  25. ~ShadowMatrix();
  26. uint32_t GetValue(int32_t x, int32_t y) const {
  27. return matrix_[y * depth_ + x];
  28. }
  29. uint32_t depth() const { return depth_; }
  30. private:
  31. const uint32_t depth_;
  32. std::vector<uint32_t> matrix_;
  33. };
  34. // Draw shadow on the image using provided ShadowMatrix.
  35. // shadow_rc - rectangle occupied by shadow
  36. // object_rc - rectangle that drops the shadow
  37. // clip_rc - clipping region
  38. void DrawShadow(SkBitmap& image,
  39. const gfx::Rect& shadow_rc,
  40. const gfx::Rect& object_rc,
  41. const gfx::Rect& clip_rc,
  42. const ShadowMatrix& matrix);
  43. } // namespace draw_utils
  44. } // namespace chrome_pdf
  45. #endif // PDF_DRAW_UTILS_SHADOW_H_