rsProgramRaster.cpp revision 7f126c78a107257090c6675ea40ffac41516a9dc
1/*
2 * Copyright (C) 2009 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 "rsContext.h"
18#include "rsProgramRaster.h"
19
20using namespace android;
21using namespace android::renderscript;
22
23
24ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth,
25                             bool lineSmooth, bool pointSprite,
26                             float lineWidth, RsCullMode cull)
27    : ProgramBase(rsc) {
28
29    memset(&mHal, 0, sizeof(mHal));
30
31    mHal.state.pointSmooth = pointSmooth;
32    mHal.state.lineSmooth = lineSmooth;
33    mHal.state.pointSprite = pointSprite;
34    mHal.state.lineWidth = lineWidth;
35    mHal.state.cull = cull;
36
37    rsc->mHal.funcs.raster.init(rsc, this);
38}
39
40ProgramRaster::~ProgramRaster() {
41    mRSC->mHal.funcs.raster.destroy(mRSC, this);
42}
43
44void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
45    if (state->mLast.get() == this && !mDirty) {
46        return;
47    }
48    state->mLast.set(this);
49    mDirty = false;
50
51    rsc->mHal.funcs.raster.setActive(rsc, this);
52}
53
54void ProgramRaster::serialize(OStream *stream) const {
55}
56
57ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
58    return NULL;
59}
60
61ProgramRasterState::ProgramRasterState() {
62}
63
64ProgramRasterState::~ProgramRasterState() {
65}
66
67void ProgramRasterState::init(Context *rsc) {
68    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false, 1.f, RS_CULL_BACK);
69    mDefault.set(pr);
70}
71
72void ProgramRasterState::deinit(Context *rsc) {
73    mDefault.clear();
74    mLast.clear();
75}
76
77namespace android {
78namespace renderscript {
79
80RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
81                                      bool pointSmooth,
82                                      bool lineSmooth,
83                                      bool pointSprite,
84                                      float lineWidth,
85                                      RsCullMode cull) {
86    ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth,
87                                          lineSmooth, pointSprite, lineWidth, cull);
88    pr->incUserRef();
89    return pr;
90}
91
92}
93}
94
95