1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
2bc0ca6ba4e31239bf77060578d0bdf1a10e04168Jason Sams * Copyright (C) 2013 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
22ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
2316647800aaaf6c8a7f8259e97f2200bec2cc0a43Stephen Hines#include <ui/GraphicBuffer.h>
24ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#include "rsGrallocConsumer.h"
25ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#include "gui/CpuConsumer.h"
26ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#include "gui/GLConsumer.h"
2716647800aaaf6c8a7f8259e97f2200bec2cc0a43Stephen Hines#else
2816647800aaaf6c8a7f8259e97f2200bec2cc0a43Stephen Hinesstruct ANativeWindowBuffer;
29ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#endif
30ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams
31326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams// ---------------------------------------------------------------------------
32326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
333522f40418fdf877f5a136475dbf75e57a3b7c77Jason Sams
34326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
35326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
365c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Samsclass Program;
37326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
381e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines/*****************************************************************************
391e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines * CAUTION
401e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines *
411e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines * Any layout changes for this class may require a corresponding change to be
421e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
431e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines * a partial copy of the information below.
441e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines *
451e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines *****************************************************************************/
46afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukclass Allocation : public ObjectBase {
471e5149f5cd3e75a010b58b985b1151d955d227d1Stephen Hines    // The graphics equivalent of malloc.  The allocation contains a structure of elements.
48326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
49326e0ddf89e8df2837752fbfd7a014814b32082cJason Samspublic:
50807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams    const static int MAX_LOD = 16;
5147a5881b8f85d65c74f2471fe6261d4cdb3dce5eMiao Wang    // The mininum alignment requirement for RenderScript. Must be power of 2 and larger than 0.
5247a5881b8f85d65c74f2471fe6261d4cdb3dce5eMiao Wang    const static size_t kMinimumRSAlignment = 16;
53754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    // The maximun number of Allocations that can share a single BufferQueue;
54754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    const static uint32_t MAX_NUM_ALLOC = 16;
55807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams
56bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    struct Hal {
57bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        void * drv;
58bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
59bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        struct State {
60064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk            const Type * type;
61bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
62bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            uint32_t usageFlags;
63bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            RsAllocationMipmapControl mipmapControl;
64bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
65bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            // Cached fields from the Type and Element
66bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            // to prevent pointer chasing in critical loops.
67a572aca4eb4ddb32c10baa1f529431cfefd756b8Jason Sams            uint32_t yuv;
68bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            uint32_t elementSizeBytes;
69bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            bool hasMipmaps;
70bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            bool hasFaces;
71bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            bool hasReferences;
722e1a94df812f0caa42ff24eaefeba8f90fbdf1acTim Murray            void * userProvidedPtr;
73cf27eb46f97cff087ebfc5b81fe998eabe0569cfJason Sams            int32_t surfaceTextureID;
74ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams            ANativeWindowBuffer *nativeBuffer;
75ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams            int64_t timestamp;
76cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams
77cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            // Allocation adapter state
78cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            const Allocation *baseAlloc;
79cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originX;
80cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originY;
81cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originZ;
82cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originLOD;
83cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originFace;
84cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t originArray[Type::mMaxArrays];
85bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        };
86bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        State state;
87eb4fe18dd88634330f9566cbb9e785d8c7ec5813Jason Sams
88eb4fe18dd88634330f9566cbb9e785d8c7ec5813Jason Sams        struct DrvState {
89709a0978ae141198018ca9769f8d96292a8928e6Jason Sams            struct LodState {
90709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                void * mallocPtr;
91709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                size_t stride;
92709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                uint32_t dimX;
93709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                uint32_t dimY;
94709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                uint32_t dimZ;
95709a0978ae141198018ca9769f8d96292a8928e6Jason Sams            } lod[android::renderscript::Allocation::MAX_LOD];
96709a0978ae141198018ca9769f8d96292a8928e6Jason Sams            size_t faceOffset;
97709a0978ae141198018ca9769f8d96292a8928e6Jason Sams            uint32_t lodCount;
98709a0978ae141198018ca9769f8d96292a8928e6Jason Sams            uint32_t faceCount;
9961656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams
10061656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams            struct YuvState {
10161656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams                uint32_t shift;
10261656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams                uint32_t step;
10361656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams            } yuv;
104e49da13c33086cf23fb750568348d114c4a10ff8Jason Sams
105e49da13c33086cf23fb750568348d114c4a10ff8Jason Sams            int grallocFlags;
106cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams            uint32_t dimArray[Type::mMaxArrays];
107709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        };
108709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        mutable DrvState drvState;
109eb4fe18dd88634330f9566cbb9e785d8c7ec5813Jason Sams
110bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    };
111bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    Hal mHal;
112bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
11334689388556747b52c3c2f1c894929fb44580898Tim Murray    void operator delete(void* ptr);
11434689388556747b52c3c2f1c894929fb44580898Tim Murray
115eb4fe18dd88634330f9566cbb9e785d8c7ec5813Jason Sams    static Allocation * createAllocation(Context *rsc, const Type *, uint32_t usages,
116179e9a457095fea4c9e6d366c269754b882d05ddJason Sams                                         RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE,
117179e9a457095fea4c9e6d366c269754b882d05ddJason Sams                                         void *ptr = 0);
11847a5881b8f85d65c74f2471fe6261d4cdb3dce5eMiao Wang    static Allocation * createAllocationStrided(Context *rsc, const Type *, uint32_t usages,
11947a5881b8f85d65c74f2471fe6261d4cdb3dce5eMiao Wang                                                RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE,
12047a5881b8f85d65c74f2471fe6261d4cdb3dce5eMiao Wang                                                void *ptr = 0, size_t byteAligned = 16);
121cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams    static Allocation * createAdapter(Context *rsc, const Allocation *alloc, const Type *type);
122cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams
123cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams
124326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    virtual ~Allocation();
125bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    void updateCache();
126326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
127064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk    const Type * getType() const {return mHal.state.type;}
128326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
129366c9c85196675437a8dd74c1cf6b63ddbde3d6aJason Sams    void syncAll(Context *rsc, RsAllocationUsageType src);
130366c9c85196675437a8dd74c1cf6b63ddbde3d6aJason Sams
13196abf819e50b59ba8cf886c13f894633eb0a24baJason Sams    void copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len);
13296abf819e50b59ba8cf886c13f894633eb0a24baJason Sams
13396abf819e50b59ba8cf886c13f894633eb0a24baJason Sams    void resize1D(Context *rsc, uint32_t dimX);
13496abf819e50b59ba8cf886c13f894633eb0a24baJason Sams    void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY);
135326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
1366ae039baf797915d46f3b3901d1b7f5cc83feaceStephen Hines    void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, size_t sizeBytes);
1374b45b8998e0d7038efaea80c70d23c086640b4e3Jason Sams    void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
138358747a3118301c5faeee73c98dd5f839bbfb54aTim Murray              uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride);
1393bbc0fd40264ddae1592706d9023865b7b3e3195Jason Sams    void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
1403bbc0fd40264ddae1592706d9023865b7b3e3195Jason Sams              uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride);
141326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
142807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams    void read(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, void *data, size_t sizeBytes);
143358747a3118301c5faeee73c98dd5f839bbfb54aTim Murray    void read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
144358747a3118301c5faeee73c98dd5f839bbfb54aTim Murray              uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride);
1453bbc0fd40264ddae1592706d9023865b7b3e3195Jason Sams    void read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
1463bbc0fd40264ddae1592706d9023865b7b3e3195Jason Sams              uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride);
147807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams
148cc8cea7477352898921044483a6c803e25d02665Miao Wang    void elementData(Context *rsc, uint32_t x, uint32_t y, uint32_t z,
1496ae039baf797915d46f3b3901d1b7f5cc83feaceStephen Hines                     const void *data, uint32_t elementOff, size_t sizeBytes);
1505f0c84cf464dda719cef65fdc9b4d0980e86b98fJason Sams
151cc8cea7477352898921044483a6c803e25d02665Miao Wang    void elementRead(Context *rsc, uint32_t x, uint32_t y, uint32_t z,
152cc8cea7477352898921044483a6c803e25d02665Miao Wang                     void *data, uint32_t elementOff, size_t sizeBytes);
153cc8cea7477352898921044483a6c803e25d02665Miao Wang
1545c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    void addProgramToDirty(const Program *);
1555c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams    void removeProgramToDirty(const Program *);
156e5ffb879ae535a899a486285a23bea05e912480fJason Sams
1573dd429cc32388ca0c3d7a9368ed2e348b8fdaab1Jason Sams    virtual void dumpLOGV(const char *prefix) const;
158e3150cfb3edb028407669e4a65e087eae77e718cJason Sams    virtual void serialize(Context *rsc, OStream *stream) const;
159b825f67adb5d1e1751fe108e6dbf9c6f2555c283Alex Sakhartchouk    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ALLOCATION; }
160fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    static Allocation *createFromStream(Context *rsc, IStream *stream);
161e5ffb879ae535a899a486285a23bea05e912480fJason Sams
162b89b0b7dd8199967502c92fe5c8f57c3bc255e1cJason Sams    bool getIsScript() const {
163bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) != 0;
164b89b0b7dd8199967502c92fe5c8f57c3bc255e1cJason Sams    }
165ebc5019400a129b1f1e57bd1fe8200a21f8da00bJason Sams    bool getIsTexture() const {
166bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0;
167ebc5019400a129b1f1e57bd1fe8200a21f8da00bJason Sams    }
1687d9c5ffccb7a5e682860f752403e5a03aed587beAlex Sakhartchouk    bool getIsRenderTarget() const {
1697d9c5ffccb7a5e682860f752403e5a03aed587beAlex Sakhartchouk        return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) != 0;
1707d9c5ffccb7a5e682860f752403e5a03aed587beAlex Sakhartchouk    }
171ebc5019400a129b1f1e57bd1fe8200a21f8da00bJason Sams    bool getIsBufferObject() const {
172bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) != 0;
173ebc5019400a129b1f1e57bd1fe8200a21f8da00bJason Sams    }
174760f1f7335ad0c5aee59ca829a40bbf6e3328a1bJason Sams
17596abf819e50b59ba8cf886c13f894633eb0a24baJason Sams    void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
17696abf819e50b59ba8cf886c13f894633eb0a24baJason Sams    void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
177a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams    virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
178c7cec1e3577cc77a5a73d5bd5a82733b1b9936a1Jason Sams    virtual bool freeChildren();
179e3929c9bc6f3897e132304faf1b40c3cf1f47474Jason Sams
180eb4fe18dd88634330f9566cbb9e785d8c7ec5813Jason Sams    void sendDirty(const Context *rsc) const;
181b89b0b7dd8199967502c92fe5c8f57c3bc255e1cJason Sams    bool getHasGraphicsMipmaps() const {
182bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        return mHal.state.mipmapControl != RS_ALLOCATION_MIPMAP_NONE;
183b89b0b7dd8199967502c92fe5c8f57c3bc255e1cJason Sams    }
184b89b0b7dd8199967502c92fe5c8f57c3bc255e1cJason Sams
185754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    void setupGrallocConsumer(const Context *rsc, uint32_t numAlloc);
186754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    void shareBufferQueue(const Context *rsc, const Allocation *alloc);
187733396b67724162844ea2785c7495115dc5ee8d8Jason Sams    void * getSurface(const Context *rsc);
1887ac2a4dda4d20ca1f1b714e129a3a08f63178c18Jason Sams    void setSurface(const Context *rsc, RsNativeWindow sur);
1897ac2a4dda4d20ca1f1b714e129a3a08f63178c18Jason Sams    void ioSend(const Context *rsc);
1907ac2a4dda4d20ca1f1b714e129a3a08f63178c18Jason Sams    void ioReceive(const Context *rsc);
191754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    int64_t getTimeStamp() {return mHal.state.timestamp;}
1925c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams
193442b7ff3ca1dffd1555d34e0afc1bdbb6387e8e2Jason Sams    void adapterOffset(Context *rsc, const uint32_t *offsets, size_t len);
194442b7ff3ca1dffd1555d34e0afc1bdbb6387e8e2Jason Sams
195b8a94e26c0a5e8f58d5b6ed04e46b411e95b77a4Jason Sams    void * getPointer(const Context *rsc, uint32_t lod, RsAllocationCubemapFace face,
196b8a94e26c0a5e8f58d5b6ed04e46b411e95b77a4Jason Sams                      uint32_t z, uint32_t array, size_t *stride);
197b8a94e26c0a5e8f58d5b6ed04e46b411e95b77a4Jason Sams
198c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams    void * getPointerUnchecked(uint32_t x, uint32_t y,
199c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams                               uint32_t z = 0, uint32_t lod = 0,
200c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams                               RsAllocationCubemapFace face = RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
201c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams                               uint32_t a1 = 0, uint32_t a2 = 0, uint32_t a3 = 0, uint32_t a4 = 0) const {
202c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams
203c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        uint8_t * p = (uint8_t *) mHal.drvState.lod[lod].mallocPtr;
204c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        p += x * getType()->getElementSizeBytes();
205c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        p += y * mHal.drvState.lod[lod].stride;
206c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        p += z * mHal.drvState.lod[lod].stride * mHal.drvState.lod[lod].dimY;
207c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams
208c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        // Todo: arrays
209c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams
210c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams        return p;
211c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams    }
212c0d68470b978a79ce024fde56f23ea3690603ccdJason Sams
2134b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes    bool hasSameDims(const Allocation *Other) const;
2144b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes
2151e5168d113ccdcf9fe1b817dcbf2f7f476d36c74Alex Sakhartchoukprotected:
216b8353c5943f4038fd7f08db3d958390ce9418798Yang Ni    Vector<const Program *> mToDirtyList;
217064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk    ObjectBaseRef<const Type> mType;
218064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk    void setType(const Type *t) {
219064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk        mType.set(t);
220064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk        mHal.state.type = t;
221064aa7ed76db9564b041afcd4b75da5b3d12fabaAlex Sakhartchouk    }
2225c3e3bc8af6de6be5e6bd68e1d5168496f99e6cfJason Sams
223ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
224ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams    class NewBufferListener : public android::ConsumerBase::FrameAvailableListener {
225ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams    public:
226754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang        NewBufferListener(uint32_t numAlloc);
227754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang        virtual ~NewBufferListener();
228ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams        const android::renderscript::Context *rsc;
229754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang        const android::renderscript::Allocation **alloc;
230ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams
231f0d7aa28bd4620030d9c54d983f607e3b0051df0Dan Stoza        virtual void onFrameAvailable(const BufferItem& item);
232754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    private:
233754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang        uint32_t mNumAlloc;
234ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams    };
235ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams
236ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams    sp<NewBufferListener> mBufferListener;
237ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams    sp< GrallocConsumer > mGrallocConsumer;
238754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    sp<IGraphicBufferProducer> mGraphicBufferProducer;
239754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    bool mBufferQueueInited = false;
240754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang    uint32_t mCurrentIdx;
241ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#endif
242ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams
243ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams
244fa84da2cbc271f855b3b1ec75bb688abdf1d1d01Jason Samsprivate:
245c7cec1e3577cc77a5a73d5bd5a82733b1b9936a1Jason Sams    void freeChildrenUnlocked();
246179e9a457095fea4c9e6d366c269754b882d05ddJason Sams    Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc, void *ptr);
247cfea6c13075aa255712e5a09a54eccbc84b0b122Jason Sams    Allocation(Context *rsc, const Allocation *, const Type *);
2482d1220c27ae91f0b307f283fe66cb767b63dfe38Alex Sakhartchouk
2492d1220c27ae91f0b307f283fe66cb767b63dfe38Alex Sakhartchouk    uint32_t getPackedSize() const;
250807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams    static void writePackedData(Context *rsc, const Type *type, uint8_t *dst,
251807fdc4b6f3fb893015ee136565d6151bb2332d3Jason Sams                                const uint8_t *src, bool dstPadded);
252e3150cfb3edb028407669e4a65e087eae77e718cJason Sams    void unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize);
253e3150cfb3edb028407669e4a65e087eae77e718cJason Sams    void packVec3Allocation(Context *rsc, OStream *stream) const;
254326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams};
255326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
256326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
257326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
258326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#endif
259