blob: 1079e1caff14497d5fdf394134423f8c6983f1df [file] [log] [blame]
Tim Murray729b6fe2013-07-23 16:20:42 -07001/*
2 * Copyright (C) 2008-2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "RenderScript.h"
Jason Sams66f0a162014-11-11 13:46:38 -080018#include "rsCppInternal.h"
Tim Murray729b6fe2013-07-23 16:20:42 -070019
Chih-Hung Hsiehdfcfabf2016-11-04 15:55:18 -070020using android::RSC::Sampler;
21using android::RSC::sp;
Tim Murray729b6fe2013-07-23 16:20:42 -070022
23Sampler::Sampler(sp<RS> rs, void* id):
24 BaseObj(id, rs)
25{
26 RsSamplerValue mMin = RS_SAMPLER_INVALID;
27 RsSamplerValue mMag = RS_SAMPLER_INVALID;
Miao Wange5428e62015-03-10 15:29:40 -070028 RsSamplerValue mWrapS = RS_SAMPLER_INVALID;
29 RsSamplerValue mWrapT = RS_SAMPLER_INVALID;
Tim Murray729b6fe2013-07-23 16:20:42 -070030 float mAniso = 0.f;
31}
32
Miao Wange5428e62015-03-10 15:29:40 -070033Sampler::Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
34 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy):
35 BaseObj(id, rs)
36{
37 RsSamplerValue mMin = min;
38 RsSamplerValue mMag = mag;
39 RsSamplerValue mWrapS = wrapS;
40 RsSamplerValue mWrapT = wrapT;
41 float mAniso = anisotropy;
42}
43
Tim Murray729b6fe2013-07-23 16:20:42 -070044RsSamplerValue Sampler::getMinification() {
45 return mMin;
46}
47
48RsSamplerValue Sampler::getMagnification() {
49 return mMag;
50}
51
52RsSamplerValue Sampler::getWrapS() {
53 return mWrapS;
54}
55
56RsSamplerValue Sampler::getWrapT() {
57 return mWrapT;
58}
59
60float Sampler::getAnisotropy() {
61 return mAniso;
62}
63
Chih-Hung Hsieh45768e12016-08-10 12:32:11 -070064sp<Sampler> Sampler::create(const sp<RS>& rs, RsSamplerValue min, RsSamplerValue mag,
Miao Wange5428e62015-03-10 15:29:40 -070065 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) {
Miao Wangcf067b82015-09-14 18:27:17 -070066 // We aren't supporting wrapR in C++ API atm, so always pass wrap for that.
Miao Wange5428e62015-03-10 15:29:40 -070067 void* id = RS::dispatch->SamplerCreate(rs->getContext(), min, mag, wrapS, wrapT,
68 RS_SAMPLER_WRAP, anisotropy);
69 return new Sampler(rs, id, min, mag, wrapS, wrapT, anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -070070}
71
Chih-Hung Hsieh45768e12016-08-10 12:32:11 -070072#define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(const sp<RS> &rs) { \
Chris Wailes44bef6f2014-08-12 13:51:10 -070073 if (rs->mSamplers.N == nullptr) { \
Tim Murray89daad62013-07-29 14:30:02 -070074 rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)); \
Chris Wailes44bef6f2014-08-12 13:51:10 -070075 } \
76 return rs->mSamplers.N; \
Tim Murray729b6fe2013-07-23 16:20:42 -070077 }
78
Miao Wang7fbf6e42015-04-03 10:48:48 -070079CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
80CREATE_SAMPLER(CLAMP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
81CREATE_SAMPLER(CLAMP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
82CREATE_SAMPLER(WRAP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
83CREATE_SAMPLER(WRAP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
84CREATE_SAMPLER(WRAP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
85CREATE_SAMPLER(MIRRORED_REPEAT_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);
86CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);
87CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);