1 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" 19#include "rsAdapter.h" 20 21using namespace android; 22using namespace android::renderscript; 23 24Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) { 25 reset(); 26} 27 28Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) { 29 reset(); 30 setAllocation(a); 31} 32 33void Adapter1D::reset() { 34 mY = 0; 35 mZ = 0; 36 mLOD = 0; 37 mFace = RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X; 38} 39 40void Adapter1D::data(Context *rsc, uint32_t x, uint32_t count, const void *data, size_t sizeBytes) { 41 mAllocation->data(rsc, x, mY, mLOD, mFace, count, 1, data, sizeBytes, 0); 42} 43 44void Adapter1D::serialize(Context *rsc, OStream *stream) const { 45} 46 47Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) { 48 return nullptr; 49} 50 51namespace android { 52namespace renderscript { 53 54RsAdapter1D rsi_Adapter1DCreate(Context *rsc) { 55 Adapter1D *a = new Adapter1D(rsc); 56 a->incUserRef(); 57 return a; 58} 59 60void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) { 61 Adapter1D * a = static_cast<Adapter1D *>(va); 62 Allocation * alloc = static_cast<Allocation *>(valloc); 63 a->setAllocation(alloc); 64} 65 66void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) { 67 Adapter1D * a = static_cast<Adapter1D *>(va); 68 switch (dim) { 69 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: 82 a->setFace((RsAllocationCubemapFace)value); 83 break; 84 default: 85 rsAssert(!"Unimplemented constraint"); 86 return; 87 } 88} 89 90} 91} 92 93////////////////////////// 94 95Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) { 96 reset(); 97} 98 99Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) { 100 reset(); 101 setAllocation(a); 102} 103 104void Adapter2D::reset() { 105 mZ = 0; 106 mLOD = 0; 107 mFace = RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X; 108} 109 110 111void Adapter2D::data(Context *rsc, uint32_t x, uint32_t y, uint32_t w, uint32_t h, 112 const void *data, size_t sizeBytes) { 113 mAllocation->data(rsc, x, y, mLOD, mFace, w, h, data, sizeBytes, 0); 114} 115 116 117void Adapter2D::serialize(Context *rsc, OStream *stream) const { 118} 119 120Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) { 121 return nullptr; 122} 123 124 125namespace android { 126namespace renderscript { 127 128RsAdapter2D rsi_Adapter2DCreate(Context *rsc) { 129 Adapter2D *a = new Adapter2D(rsc); 130 a->incUserRef(); 131 return a; 132} 133 134void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) { 135 Adapter2D * a = static_cast<Adapter2D *>(va); 136 Allocation * alloc = static_cast<Allocation *>(valloc); 137 a->setAllocation(alloc); 138} 139 140void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) { 141 Adapter2D * a = static_cast<Adapter2D *>(va); 142 switch (dim) { 143 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: 156 a->setFace((RsAllocationCubemapFace)value); 157 break; 158 default: 159 rsAssert(!"Unimplemented constraint"); 160 return; 161 } 162} 163 164 165} 166} 167