Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / pdf / draw_utils.h
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
5 #ifndef PDF_DRAW_UTILS_H_
6 #define PDF_DRAW_UTILS_H_
7
8 #include <stdint.h>
9
10 #include <vector>
11
12 #include "ppapi/cpp/image_data.h"
13 #include "ppapi/cpp/rect.h"
14
15 namespace chrome_pdf {
16
17 const uint8_t kOpaqueAlpha = 0xFF;
18 const uint8_t kTransparentAlpha = 0x00;
19
20 // Shadow Matrix contains matrix for shadow rendering. To reduce amount of
21 // calculations user may choose to cache matrix and reuse it if nothing changed.
22 class ShadowMatrix {
23  public:
24   // Matrix parameters.
25   // depth - how big matrix should be. Shadow will go smoothly across the
26   // entire matrix from black to background color.
27   // If factor == 1, smoothing will be linear from 0 to the end (depth),
28   // if 0 < factor < 1, smoothing will drop faster near 0.
29   // if factor > 1, smoothing will drop faster near the end (depth).
30   ShadowMatrix(uint32_t depth, double factor, uint32_t background);
31
32   ~ShadowMatrix();
33
34   uint32_t GetValue(int32_t x, int32_t y) const {
35     return matrix_[y * depth_ + x];
36   }
37
38   uint32_t depth() const { return depth_; }
39
40  private:
41   const uint32_t depth_;
42   std::vector<uint32_t> matrix_;
43 };
44
45 // Draw shadow on the image using provided ShadowMatrix.
46 // shadow_rc - rectangle occupied by shadow
47 // object_rc - rectangle that drops the shadow
48 // clip_rc - clipping region
49 void DrawShadow(pp::ImageData* image,
50                 const pp::Rect& shadow_rc,
51                 const pp::Rect& object_rc,
52                 const pp::Rect& clip_rc,
53                 const ShadowMatrix& matrix);
54
55 }  // namespace chrome_pdf
56
57 #endif  // PDF_DRAW_UTILS_H_