rsAllocation.h revision fb6b614bcea88a587a7ea4530be45ff0ffa0210e
1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
2326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Copyright (C) 2009 The Android Open Source Project
3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License.
6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at
7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software
11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and
14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License.
15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */
16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
17326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#ifndef ANDROID_STRUCTURED_ALLOCATION_H
18326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#define ANDROID_STRUCTURED_ALLOCATION_H
19326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
20326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsType.h"
21326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
22326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams// ---------------------------------------------------------------------------
23326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
24326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
25326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
265c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Samsclass Program;
27326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
28326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsclass Allocation : public ObjectBase
29326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
30326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // The graphics equilivent of malloc.  The allocation contains a structure of elements.
31326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
32326e0ddf89e8df2837752fbfd7a014814b32082cJason Samspublic:
33326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // By policy this allocation will hold a pointer to the type
34326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // but will not destroy it on destruction.
35e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams    Allocation(Context *rsc, const Type *);
36fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    Allocation(Context *rsc, const Type *, void *bmp, void *callbackData, RsBitmapCallback_t callback);
37fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams
38326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    virtual ~Allocation();
39326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
40326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void setCpuWritable(bool);
41326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void setGpuWritable(bool);
42326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void setCpuReadable(bool);
43326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void setGpuReadable(bool);
44326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
45326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool fixAllocation();
46326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
47326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void * getPtr() const {return mPtr;}
48326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    const Type * getType() const {return mType.get();}
49326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
507fabe1a3bf8de37d86021bb7f744c791db81aed3Jason Sams    void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset);
51cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    void uploadToTexture(const Context *rsc);
52326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    uint32_t getTextureID() const {return mTextureID;}
53326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
54cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    void deferedUploadToBufferObject(const Context *rsc);
55cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    void uploadToBufferObject(const Context *rsc);
56326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    uint32_t getBufferObjectID() const {return mBufferID;}
57326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
58326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
599397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams    void data(const void *data, uint32_t sizeBytes);
609397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams    void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
61e5ffb879ae535a899a486285a23bea05e912480fJason Sams    void subData(uint32_t xoff, uint32_t yoff,
629397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams                 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
63326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
649397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams                 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
65326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
66e579df42e85d9e00f53c42ef1b78dbd209dba989Jason Sams    void read(void *data);
67e579df42e85d9e00f53c42ef1b78dbd209dba989Jason Sams
68e5ffb879ae535a899a486285a23bea05e912480fJason Sams    void enableGLVertexBuffers() const;
69e5ffb879ae535a899a486285a23bea05e912480fJason Sams    void setupGLIndexBuffers() const;
70e5ffb879ae535a899a486285a23bea05e912480fJason Sams
715c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    void addProgramToDirty(const Program *);
725c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    void removeProgramToDirty(const Program *);
73e5ffb879ae535a899a486285a23bea05e912480fJason Sams
743dd429cc32388ca0c3d7a9368ed2e348b8fdaab1Jason Sams    virtual void dumpLOGV(const char *prefix) const;
75fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    virtual void serialize(OStream *stream) const;
76fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    virtual A3DClassID getClassId() const { return A3D_CLASS_ID_ALLOCATION; }
77fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    static Allocation *createFromStream(Context *rsc, IStream *stream);
78e5ffb879ae535a899a486285a23bea05e912480fJason Sams
79cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    virtual void uploadCheck(const Context *rsc);
80cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams
81326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsprotected:
825c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    void sendDirty() const;
835c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams
84326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ObjectBaseRef<const Type> mType;
85326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void * mPtr;
86326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
875c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    Vector<const Program *> mToDirtyList;
885c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams
89fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    // Is we have a non-null user bitmap callback we do not own the bits and
90fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    // instead call this function to free the memort when its time.
91fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    RsBitmapCallback_t mUserBitmapCallback;
92fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    void *mUserBitmapCallbackData;
93fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams
94326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Usage restrictions
95326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mCpuWrite;
96326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mCpuRead;
97326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mGpuWrite;
98326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mGpuRead;
99326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
100326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // more usage hint data from the application
101326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // which can be used by a driver to pick the best memory type.
102326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Likely ignored for now
103326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    float mReadWriteRatio;
104326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    float mUpdateSize;
105326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
106326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
107326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Is this a legal structure to be used as a texture source.
108326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Initially this will require 1D or 2D and color data
109326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mIsTexture;
1107fabe1a3bf8de37d86021bb7f744c791db81aed3Jason Sams    bool mTextureGenMipmap;
111cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    uint32_t mTextureLOD;
112326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    uint32_t mTextureID;
113326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
114326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Is this a legal structure to be used as a vertex source.
115326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // Initially this will require 1D and x(yzw).  Additional per element data
116326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    // is allowed.
117326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mIsVertexBuffer;
118326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    uint32_t mBufferID;
119cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams
120cf4c7c9b2f513be77a5b9853319ca82ac2b128edJason Sams    bool mUploadDefered;
121fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams
122fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Samsprivate:
123fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams    void init(Context *rsc, const Type *);
124fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Sams
125326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams};
126326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
127326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
128326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
129326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#endif
130326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
131