Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2017 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 #ifndef GUEST_HALS_CAMERA_GRALLOCMODULE_H_
     17 #define GUEST_HALS_CAMERA_GRALLOCMODULE_H_
     18 
     19 #include <hardware/gralloc.h>
     20 
     21 class GrallocModule {
     22  public:
     23   static GrallocModule &getInstance() {
     24     static GrallocModule instance;
     25     return instance;
     26   }
     27 
     28   int lock(buffer_handle_t handle, int usage, int l, int t, int w, int h,
     29            void **vaddr) {
     30     return mModule->lock(mModule, handle, usage, l, t, w, h, vaddr);
     31   }
     32 
     33 #ifdef GRALLOC_MODULE_API_VERSION_0_2
     34   int lock_ycbcr(buffer_handle_t handle, int usage, int l, int t, int w, int h,
     35                  struct android_ycbcr *ycbcr) {
     36     return mModule->lock_ycbcr(mModule, handle, usage, l, t, w, h, ycbcr);
     37   }
     38 #endif
     39 
     40   int unlock(buffer_handle_t handle) {
     41     return mModule->unlock(mModule, handle);
     42   }
     43 
     44  private:
     45   GrallocModule() {
     46     const hw_module_t *module = NULL;
     47     int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
     48     if (ret) {
     49       ALOGE("%s: Failed to get gralloc module: %d", __FUNCTION__, ret);
     50     }
     51     mModule = reinterpret_cast<const gralloc_module_t *>(module);
     52   }
     53   const gralloc_module_t *mModule;
     54 };
     55 
     56 #endif  // GUEST_HALS_CAMERA_GRALLOCMODULE_H_
     57