• 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        : target(0),
82          sync_point(0),
83          source_rect(PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 1.0f, 1.0f)),
84          premult_alpha(true) {}
85 
86     gpu::Mailbox mailbox;
87     uint32_t target;
88     uint32_t sync_point;
89     PP_FloatRect source_rect;
90     bool premult_alpha;
91   };
92 
CompositorLayerDataCompositorLayerData93   CompositorLayerData() {}
94 
CompositorLayerDataCompositorLayerData95   CompositorLayerData(const CompositorLayerData& other) {
96     *this = other;
97   }
98 
is_nullCompositorLayerData99   bool is_null() const {
100     return !(color || texture || image);
101   }
102 
is_validCompositorLayerData103   bool is_valid() const {
104     int i = 0;
105     if (color) ++i;
106     if (texture) ++i;
107     if (image) ++i;
108     return i == 1;
109   }
110 
111   const CompositorLayerData& operator=(const CompositorLayerData& other);
112 
113   LayerCommon common;
114   scoped_ptr<ColorLayer> color;
115   scoped_ptr<TextureLayer> texture;
116   scoped_ptr<ImageLayer> image;
117 };
118 
119 }  // namespace ppapi
120 
121 #endif  // PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_
122