Home | History | Annotate | Download | only in client2
      1 /*
      2  * Copyright (C) 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 #ifndef ANDROiD_SERVERS_CAMERA_CAMERA2HEAP_H
     18 #define ANDROiD_SERVERS_CAMERA_CAMERA2HEAP_H
     19 
     20 #include <binder/MemoryBase.h>
     21 #include <binder/MemoryHeapBase.h>
     22 
     23 namespace android {
     24 namespace camera2 {
     25 
     26 // Utility class for managing a set of IMemory blocks
     27 class Camera2Heap : public RefBase {
     28   public:
     29     Camera2Heap(size_t buf_size, uint_t num_buffers = 1,
     30             const char *name = NULL) :
     31             mBufSize(buf_size),
     32             mNumBufs(num_buffers) {
     33         mHeap = new MemoryHeapBase(buf_size * num_buffers, 0, name);
     34         mBuffers = new sp<MemoryBase>[mNumBufs];
     35         for (uint_t i = 0; i < mNumBufs; i++)
     36             mBuffers[i] = new MemoryBase(mHeap,
     37                     i * mBufSize,
     38                     mBufSize);
     39     }
     40 
     41     virtual ~Camera2Heap()
     42     {
     43         delete [] mBuffers;
     44     }
     45 
     46     size_t mBufSize;
     47     uint_t mNumBufs;
     48     sp<MemoryHeapBase> mHeap;
     49     sp<MemoryBase> *mBuffers;
     50 };
     51 
     52 }; // namespace camera2
     53 }; // namespace android
     54 
     55 #endif
     56