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