QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ppapi / cpp / compositor_layer.cc
blobd15a6731ba5b1abd4fc5ca5076e3973c83a1cd86
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.
5 #include "ppapi/cpp/compositor_layer.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/cpp/module_impl.h"
10 #include "ppapi/cpp/var.h"
12 namespace pp {
14 namespace {
16 template <> const char* interface_name<PPB_CompositorLayer_0_1>() {
17 return PPB_COMPOSITORLAYER_INTERFACE_0_1;
20 template <> const char* interface_name<PPB_CompositorLayer_0_2>() {
21 return PPB_COMPOSITORLAYER_INTERFACE_0_2;
24 } // namespace
26 CompositorLayer::CompositorLayer() {
29 CompositorLayer::CompositorLayer(
30 const CompositorLayer& other) : Resource(other) {
33 CompositorLayer::CompositorLayer(const Resource& resource)
34 : Resource(resource) {
35 PP_DCHECK(IsCompositorLayer(resource));
38 CompositorLayer::CompositorLayer(PassRef, PP_Resource resource)
39 : Resource(PASS_REF, resource) {
42 CompositorLayer::~CompositorLayer() {
45 int32_t CompositorLayer::SetColor(float red,
46 float green,
47 float blue,
48 float alpha,
49 const Size& size) {
50 if (has_interface<PPB_CompositorLayer_0_2>()) {
51 return get_interface<PPB_CompositorLayer_0_2>()->SetColor(
52 pp_resource(), red, green, blue, alpha, &size.pp_size());
54 if (has_interface<PPB_CompositorLayer_0_1>()) {
55 return get_interface<PPB_CompositorLayer_0_1>()->SetColor(
56 pp_resource(), red, green, blue, alpha, &size.pp_size());
58 return PP_ERROR_NOINTERFACE;
61 int32_t CompositorLayer::SetTexture(const Graphics3D& context,
62 uint32_t target,
63 uint32_t texture,
64 const Size& size,
65 const CompletionCallback& cc) {
66 if (has_interface<PPB_CompositorLayer_0_2>()) {
67 return get_interface<PPB_CompositorLayer_0_2>()->SetTexture(
68 pp_resource(), context.pp_resource(), target, texture, &size.pp_size(),
69 cc.pp_completion_callback());
71 if (has_interface<PPB_CompositorLayer_0_1>()) {
72 if (target != 0x0DE1) // 0x0DE1 GL_TEXTURE_2D
73 return cc.MayForce(PP_ERROR_NOTSUPPORTED);
74 return get_interface<PPB_CompositorLayer_0_1>()->SetTexture(
75 pp_resource(), context.pp_resource(), texture, &size.pp_size(),
76 cc.pp_completion_callback());
78 return cc.MayForce(PP_ERROR_NOINTERFACE);
81 int32_t CompositorLayer::SetImage(const ImageData& image,
82 const CompletionCallback& cc) {
83 if (has_interface<PPB_CompositorLayer_0_2>()) {
84 return get_interface<PPB_CompositorLayer_0_2>()->SetImage(
85 pp_resource(), image.pp_resource(), NULL,
86 cc.pp_completion_callback());
88 if (has_interface<PPB_CompositorLayer_0_1>()) {
89 return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
90 pp_resource(), image.pp_resource(), NULL,
91 cc.pp_completion_callback());
93 return cc.MayForce(PP_ERROR_NOINTERFACE);
96 int32_t CompositorLayer::SetImage(const ImageData& image,
97 const Size& size,
98 const CompletionCallback& cc) {
99 if (has_interface<PPB_CompositorLayer_0_2>()) {
100 return get_interface<PPB_CompositorLayer_0_2>()->SetImage(
101 pp_resource(), image.pp_resource(), &size.pp_size(),
102 cc.pp_completion_callback());
104 if (has_interface<PPB_CompositorLayer_0_1>()) {
105 return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
106 pp_resource(), image.pp_resource(), &size.pp_size(),
107 cc.pp_completion_callback());
109 return cc.MayForce(PP_ERROR_NOINTERFACE);
112 int32_t CompositorLayer::SetClipRect(const Rect& rect) {
113 if (has_interface<PPB_CompositorLayer_0_2>()) {
114 return get_interface<PPB_CompositorLayer_0_2>()->SetClipRect(
115 pp_resource(), &rect.pp_rect());
117 if (has_interface<PPB_CompositorLayer_0_1>()) {
118 return get_interface<PPB_CompositorLayer_0_1>()->SetClipRect(
119 pp_resource(), &rect.pp_rect());
121 return PP_ERROR_NOINTERFACE;
124 int32_t CompositorLayer::SetTransform(const float matrix[16]) {
125 if (has_interface<PPB_CompositorLayer_0_2>()) {
126 return get_interface<PPB_CompositorLayer_0_2>()->SetTransform(
127 pp_resource(), matrix);
129 if (has_interface<PPB_CompositorLayer_0_1>()) {
130 return get_interface<PPB_CompositorLayer_0_1>()->SetTransform(
131 pp_resource(), matrix);
133 return PP_ERROR_NOINTERFACE;
136 int32_t CompositorLayer::SetOpacity(float opacity) {
137 if (has_interface<PPB_CompositorLayer_0_2>()) {
138 return get_interface<PPB_CompositorLayer_0_2>()->SetOpacity(
139 pp_resource(), opacity);
141 if (has_interface<PPB_CompositorLayer_0_1>()) {
142 return get_interface<PPB_CompositorLayer_0_1>()->SetOpacity(
143 pp_resource(), opacity);
145 return PP_ERROR_NOINTERFACE;
148 int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) {
149 if (has_interface<PPB_CompositorLayer_0_2>()) {
150 return get_interface<PPB_CompositorLayer_0_2>()->SetBlendMode(
151 pp_resource(), mode);
153 if (has_interface<PPB_CompositorLayer_0_1>()) {
154 return get_interface<PPB_CompositorLayer_0_1>()->SetBlendMode(
155 pp_resource(), mode);
157 return PP_ERROR_NOINTERFACE;
160 int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) {
161 if (has_interface<PPB_CompositorLayer_0_2>()) {
162 return get_interface<PPB_CompositorLayer_0_2>()->SetSourceRect(
163 pp_resource(), &rect.pp_float_rect());
165 if (has_interface<PPB_CompositorLayer_0_1>()) {
166 return get_interface<PPB_CompositorLayer_0_1>()->SetSourceRect(
167 pp_resource(), &rect.pp_float_rect());
169 return PP_ERROR_NOINTERFACE;
172 int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) {
173 if (has_interface<PPB_CompositorLayer_0_2>()) {
174 return get_interface<PPB_CompositorLayer_0_2>()->SetPremultipliedAlpha(
175 pp_resource(), PP_FromBool(premult));
177 if (has_interface<PPB_CompositorLayer_0_1>()) {
178 return get_interface<PPB_CompositorLayer_0_1>()->SetPremultipliedAlpha(
179 pp_resource(), PP_FromBool(premult));
181 return PP_ERROR_NOINTERFACE;
184 bool CompositorLayer::IsCompositorLayer(const Resource& resource) {
185 if (has_interface<PPB_CompositorLayer_0_2>()) {
186 return PP_ToBool(get_interface<PPB_CompositorLayer_0_2>()->
187 IsCompositorLayer(resource.pp_resource()));
189 if (has_interface<PPB_CompositorLayer_0_1>()) {
190 return PP_ToBool(get_interface<PPB_CompositorLayer_0_1>()->
191 IsCompositorLayer(resource.pp_resource()));
193 return false;
196 } // namespace pp