[Telemetry] Add SurfaceFlingerStats to timeline_based_measurement
[chromium-blink-merge.git] / pdf / draw_utils.h
blobeedf24f27d8e47b70cfe1b5abbccf3ee1b6b1b77
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.
5 #ifndef PDF_DRAW_UTILS_H_
6 #define PDF_DRAW_UTILS_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "ppapi/cpp/image_data.h"
12 #include "ppapi/cpp/rect.h"
14 namespace chrome_pdf {
16 const uint8 kOpaqueAlpha = 0xFF;
17 const uint8 kTransparentAlpha = 0x00;
19 void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
20 pp::ImageData* dest, const pp::Point& dest_origin,
21 uint8 alpha_adjustment);
23 // Fill rectangle with gradient horizontally or vertically. Start is a color of
24 // top-left point of the rectangle, end color is a color of
25 // top-right (horizontal==true) or bottom-left (horizontal==false) point.
26 void GradientFill(pp::ImageData* image,
27 const pp::Rect& rc,
28 uint32 start_color,
29 uint32 end_color,
30 bool horizontal);
32 // Fill dirty rectangle with gradient, where gradient color set for corners of
33 // gradient rectangle. Parts of the dirty rect outside of gradient rect will
34 // be unchanged.
35 void GradientFill(pp::Instance* instance,
36 pp::ImageData* image,
37 const pp::Rect& dirty_rc,
38 const pp::Rect& gradient_rc,
39 uint32 start_color,
40 uint32 end_color,
41 bool horizontal,
42 uint8 transparency);
44 // Copy one image into another. If stretch is true, the result occupy the entire
45 // dest_rc. If stretch is false, dest_rc.point will be used as an origin of the
46 // result image. Copy will ignore all pixels with transparent alpha from the
47 // source image.
48 void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
49 pp::ImageData* dest, const pp::Rect& dest_rc,
50 bool stretch);
52 // Fill in rectangle with specified color.
53 void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color);
55 // Shadow Matrix contains matrix for shadow rendering. To reduce amount of
56 // calculations user may choose to cache matrix and reuse it if nothing changed.
57 class ShadowMatrix {
58 public:
59 // Matrix parameters.
60 // depth - how big matrix should be. Shadow will go smoothly across the
61 // entire matrix from black to background color.
62 // If factor == 1, smoothing will be linear from 0 to the end (depth),
63 // if 0 < factor < 1, smoothing will drop faster near 0.
64 // if factor > 1, smoothing will drop faster near the end (depth).
65 ShadowMatrix(uint32 depth, double factor, uint32 background);
67 ~ShadowMatrix();
69 uint32 GetValue(int32 x, int32 y) const { return matrix_[y * depth_ + x]; }
71 uint32 depth() const { return depth_; }
72 double factor() const { return factor_; }
73 uint32 background() const { return background_; }
75 private:
76 uint32 depth_;
77 double factor_;
78 uint32 background_;
79 std::vector<uint32> matrix_;
82 // Draw shadow on the image using provided ShadowMatrix.
83 // shadow_rc - rectangle occupied by shadow
84 // object_rc - rectangle that drops the shadow
85 // clip_rc - clipping region
86 void DrawShadow(pp::ImageData* image,
87 const pp::Rect& shadow_rc,
88 const pp::Rect& object_rc,
89 const pp::Rect& clip_rc,
90 const ShadowMatrix& matrix);
92 } // namespace chrome_pdf
94 #endif // PDF_DRAW_UTILS_H_