summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/compositor_layer_data.h
blob: 8cf096ea49b690caaafe97477b9beec66a01a333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_
#define PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_

#include <string.h>

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "ppapi/c/ppb_compositor_layer.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/ppapi_shared_export.h"

namespace ppapi {

struct PPAPI_SHARED_EXPORT CompositorLayerData {

  struct Transform {
    Transform() {
      matrix[0] = 1.0f;
      matrix[1] = 0.0f;
      matrix[2] = 0.0f;
      matrix[3] = 0.0f;
      matrix[4] = 0.0f;
      matrix[5] = 1.0f;
      matrix[6] = 0.0f;
      matrix[7] = 0.0f;
      matrix[8] = 0.0f;
      matrix[9] = 0.0f;
      matrix[10] = 1.0f;
      matrix[11] = 0.0f;
      matrix[12] = 0.0f;
      matrix[13] = 0.0f;
      matrix[14] = 0.0f;
      matrix[15] = 1.0f;
    }

    float matrix[16];
  };

  struct LayerCommon {
    LayerCommon()
       : size(PP_MakeSize(0, 0)),
         clip_rect(PP_MakeRectFromXYWH(0, 0, 0, 0)),
         blend_mode(PP_BLENDMODE_SRC_OVER),
         opacity(1.0f),
         resource_id(0) {
    }

    PP_Size size;
    PP_Rect clip_rect;
    Transform transform;
    PP_BlendMode blend_mode;
    float opacity;
    uint32_t resource_id;
  };

  struct ColorLayer {
    ColorLayer() : red(0.0f), green(0.0f), blue(0.0f), alpha(0.0f) {}

    float red;
    float green;
    float blue;
    float alpha;
  };

  struct ImageLayer {
    ImageLayer()
       : resource(0),
         source_rect(PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 0.0f, 0.0f)) {}

    PP_Resource resource;
    PP_FloatRect source_rect;
  };

  struct TextureLayer {
    TextureLayer()
       : target(0),
         sync_point(0),
         source_rect(PP_MakeFloatRectFromXYWH(0.0f, 0.0f, 1.0f, 1.0f)),
         premult_alpha(true) {}

    gpu::Mailbox mailbox;
    uint32_t target;
    uint32_t sync_point;
    PP_FloatRect source_rect;
    bool premult_alpha;
  };

  CompositorLayerData() {}

  CompositorLayerData(const CompositorLayerData& other) {
    *this = other;
  }

  bool is_null() const {
    return !(color || texture || image);
  }

  bool is_valid() const {
    int i = 0;
    if (color) ++i;
    if (texture) ++i;
    if (image) ++i;
    return i == 1;
  }

  const CompositorLayerData& operator=(const CompositorLayerData& other);

  LayerCommon common;
  scoped_ptr<ColorLayer> color;
  scoped_ptr<TextureLayer> texture;
  scoped_ptr<ImageLayer> image;
};

}  // namespace ppapi

#endif  // PPAPI_SHARED_IMPL_COMPOSITOR_LAYER_DATA_H_