blob: 9fd39f8798938e1da9f0feeeb2080d7eb8dc4ec1 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001
2/*
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "rsContext.h"
Alex Sakhartchouk4edf0302012-03-09 10:47:27 -080019#include "rsAdapter.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070020
21using namespace android;
22using namespace android::renderscript;
23
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080024Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070025 reset();
26}
27
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080028Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070029 reset();
30 setAllocation(a);
31}
32
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080033void Adapter1D::reset() {
Jason Sams326e0dd2009-05-22 14:03:28 -070034 mY = 0;
35 mZ = 0;
36 mLOD = 0;
Jason Samsa6dd8232012-07-25 19:33:43 -070037 mFace = RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X;
Jason Sams326e0dd2009-05-22 14:03:28 -070038}
39
Jason Samsa6dd8232012-07-25 19:33:43 -070040void Adapter1D::data(Context *rsc, uint32_t x, uint32_t count, const void *data, size_t sizeBytes) {
Tim Murray60c27962013-02-07 16:15:23 -080041 mAllocation->data(rsc, x, mY, mLOD, mFace, count, 1, data, sizeBytes, 0);
Jason Sams326e0dd2009-05-22 14:03:28 -070042}
43
Jason Samse3150cf2012-07-24 18:10:20 -070044void Adapter1D::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070045}
46
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080047Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070048 return NULL;
49}
50
Jason Sams326e0dd2009-05-22 14:03:28 -070051namespace android {
52namespace renderscript {
53
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080054RsAdapter1D rsi_Adapter1DCreate(Context *rsc) {
Jason Samse514b452009-09-25 14:51:22 -070055 Adapter1D *a = new Adapter1D(rsc);
Jason Sams9397e302009-08-27 20:23:34 -070056 a->incUserRef();
Jason Samsd3c8de22009-08-03 16:03:08 -070057 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -070058}
59
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080060void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070061 Adapter1D * a = static_cast<Adapter1D *>(va);
62 Allocation * alloc = static_cast<Allocation *>(valloc);
63 a->setAllocation(alloc);
64}
65
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080066void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) {
Jason Sams326e0dd2009-05-22 14:03:28 -070067 Adapter1D * a = static_cast<Adapter1D *>(va);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080068 switch (dim) {
Jason Sams326e0dd2009-05-22 14:03:28 -070069 case RS_DIMENSION_X:
70 rsAssert(!"Cannot contrain X in an 1D adapter");
71 return;
72 case RS_DIMENSION_Y:
73 a->setY(value);
74 break;
75 case RS_DIMENSION_Z:
76 a->setZ(value);
77 break;
78 case RS_DIMENSION_LOD:
79 a->setLOD(value);
80 break;
81 case RS_DIMENSION_FACE:
Jason Samsa6dd8232012-07-25 19:33:43 -070082 a->setFace((RsAllocationCubemapFace)value);
Jason Sams326e0dd2009-05-22 14:03:28 -070083 break;
84 default:
85 rsAssert(!"Unimplemented constraint");
86 return;
87 }
88}
89
Jason Sams326e0dd2009-05-22 14:03:28 -070090}
91}
92
93//////////////////////////
94
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080095Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070096 reset();
97}
98
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080099Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700100 reset();
101 setAllocation(a);
102}
103
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800104void Adapter2D::reset() {
Jason Sams326e0dd2009-05-22 14:03:28 -0700105 mZ = 0;
106 mLOD = 0;
Jason Samsa6dd8232012-07-25 19:33:43 -0700107 mFace = RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X;
Jason Sams326e0dd2009-05-22 14:03:28 -0700108}
109
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800110
Jason Samsa6dd8232012-07-25 19:33:43 -0700111void Adapter2D::data(Context *rsc, uint32_t x, uint32_t y, uint32_t w, uint32_t h,
112 const void *data, size_t sizeBytes) {
Tim Murray60c27962013-02-07 16:15:23 -0800113 mAllocation->data(rsc, x, y, mLOD, mFace, w, h, data, sizeBytes, 0);
Jason Sams326e0dd2009-05-22 14:03:28 -0700114}
115
Jason Sams326e0dd2009-05-22 14:03:28 -0700116
Jason Samse3150cf2012-07-24 18:10:20 -0700117void Adapter2D::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700118}
119
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800120Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700121 return NULL;
122}
Jason Sams326e0dd2009-05-22 14:03:28 -0700123
124
125namespace android {
126namespace renderscript {
127
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800128RsAdapter2D rsi_Adapter2DCreate(Context *rsc) {
Jason Samse514b452009-09-25 14:51:22 -0700129 Adapter2D *a = new Adapter2D(rsc);
Jason Sams9397e302009-08-27 20:23:34 -0700130 a->incUserRef();
Jason Samsd3c8de22009-08-03 16:03:08 -0700131 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -0700132}
133
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800134void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700135 Adapter2D * a = static_cast<Adapter2D *>(va);
136 Allocation * alloc = static_cast<Allocation *>(valloc);
137 a->setAllocation(alloc);
138}
139
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800140void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700141 Adapter2D * a = static_cast<Adapter2D *>(va);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800142 switch (dim) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700143 case RS_DIMENSION_X:
144 rsAssert(!"Cannot contrain X in an 2D adapter");
145 return;
146 case RS_DIMENSION_Y:
147 rsAssert(!"Cannot contrain Y in an 2D adapter");
148 break;
149 case RS_DIMENSION_Z:
150 a->setZ(value);
151 break;
152 case RS_DIMENSION_LOD:
153 a->setLOD(value);
154 break;
155 case RS_DIMENSION_FACE:
Jason Samsa6dd8232012-07-25 19:33:43 -0700156 a->setFace((RsAllocationCubemapFace)value);
Jason Sams326e0dd2009-05-22 14:03:28 -0700157 break;
158 default:
159 rsAssert(!"Unimplemented constraint");
160 return;
161 }
162}
163
Jason Sams326e0dd2009-05-22 14:03:28 -0700164
165}
166}