• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_
6 #define PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_
7 
8 #include <string.h>
9 
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/common/mailbox.h"
13 #include "ppapi/c/ppb_compositor_layer.h"
14 #include "ppapi/shared_impl/host_resource.h"
15 #include "ppapi/shared_impl/ppapi_shared_export.h"
16 
17 namespace ppapi {
18 
19 struct PPAPI_SHARED_EXPORT CompositorLayerData {
20 
21   struct Transform {
TransformCompositorLayerData::Transform22     Transform() {
23       matrix[0] = 1.0f;
24       matrix[1] = 0.0f;
25       matrix[2] = 0.0f;
26       matrix[3] = 0.0f;
27       matrix[4] = 0.0f;
28       matrix[5] = 1.0f;
29       matrix[6] = 0.0f;
30       matrix[7] = 0.0f;
31       matrix[8] = 0.0f;
32       matrix[9] = 0.0f;
33       matrix[10] = 1.0f;
34       matrix[11] = 0.0f;
35       matrix[12] = 0.0f;
36       matrix[13] = 0.0f;
37       matrix[14] = 0.0f;
38       matrix[15] = 1.0f;
39     }
40 
41     float matrix[16];
42   };
43 
44   struct LayerCommon {
LayerCommonCompositorLayerData::LayerCommon45     LayerCommon()
46        : size(PP_MakeSize(0, 0)),
47          clip_rect(PP_MakeRectFromXYWH(0, 0, 0, 0)),
48          blend_mode(PP_BLENDMODE_SRC_OVER),
49          opacity(1.0f),
50          resource_id(0) {
51     }
52 
53     PP_Size size;
54     PP_Rect clip_rect;
55     Transform transform;
56     PP_BlendMode blend_mode;
57     float opacity;
58     uint32_t resource_id;
59   };
60 
61   struct ColorLayer {
ColorLayerCompositorLayerData::ColorLayer62     ColorLayer() : red(0.0f), green(0.0f), blue(0.0f), alpha(0.0f) {}
63 
64     float red;
65     float green;
66     float blue;
67     float alpha;
68   };
69 
70   struct ImageLayer {
ImageLayerCompositorLayerData::ImageLayer71     ImageLayer()
72        : resource(0),
73          source_rect(PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f)) {}
74 
75     PP_Resource resource;
76     PP_FloatRect source_rect;
77   };
78 
79   struct TextureLayer {
TextureLayerCompositorLayerData::TextureLayer80     TextureLayer()
81        : sync_point(0),
82          source_rect(PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 1.0f, 1.0f)),
83          premult_alpha(true) {}
84 
85     gpu::Mailbox mailbox;
86     uint32_t sync_point;
87     PP_FloatRect source_rect;
88     bool premult_alpha;
89   };
90 
CompositorLayerDataCompositorLayerData91   CompositorLayerData() {}
92 
CompositorLayerDataCompositorLayerData93   CompositorLayerData(const CompositorLayerData& other) {
94     *this = other;
95   }
96 
is_nullCompositorLayerData97   bool is_null() const {
98     return !(color || texture || image);
99   }
100 
is_validCompositorLayerData101   bool is_valid() const {
102     int i = 0;
103     if (color) ++i;
104     if (texture) ++i;
105     if (image) ++i;
106     return i == 1;
107   }
108 
109   const CompositorLayerData& operator=(const CompositorLayerData& other);
110 
111   LayerCommon common;
112   scoped_ptr<ColorLayer> color;
113   scoped_ptr<TextureLayer> texture;
114   scoped_ptr<ImageLayer> image;
115 };
116 
117 }  // namespace ppapi
118 
119 #endif  // PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_
120