1/*
2 * Copyright (C) 2008 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 GRALLOC_QSD8K_GPU_H_
18#define GRALLOC_QSD8K_GPU_H_
19
20#include <errno.h>
21#include <pthread.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <cutils/log.h>
26#include <cutils/ashmem.h>
27
28#include "gralloc_priv.h"
29#include "pmemalloc.h"
30
31
32class gpu_context_t : public alloc_device_t {
33 public:
34
35    class Deps {
36     public:
37
38        virtual ~Deps();
39
40        // ashmem
41        virtual int ashmem_create_region(const char *name, size_t size) = 0;
42
43        // POSIX
44        virtual int close(int fd) = 0;
45
46        // Framebuffer (locally defined)
47        virtual int mapFrameBufferLocked(struct private_module_t* module) = 0;
48        virtual int terminateBuffer(gralloc_module_t const* module,
49            private_handle_t* hnd) = 0;
50    };
51
52    gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator,
53            PmemAllocator& pmemAdspAllocator, const private_module_t* module);
54
55    int gralloc_alloc_framebuffer_locked(size_t size, int usage,
56            buffer_handle_t* pHandle);
57    int gralloc_alloc_framebuffer(size_t size, int usage,
58            buffer_handle_t* pHandle);
59    int gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t* pHandle);
60    int free_impl(private_handle_t const* hnd);
61    int alloc_impl(int w, int h, int format, int usage,
62            buffer_handle_t* pHandle, int* pStride);
63
64    static int gralloc_alloc(alloc_device_t* dev, int w, int h, int format,
65            int usage, buffer_handle_t* pHandle, int* pStride);
66    static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
67    static int gralloc_close(struct hw_device_t *dev);
68
69 private:
70
71    Deps& deps;
72    PmemAllocator& pmemAllocator;
73    PmemAllocator& pmemAdspAllocator;
74};
75
76#endif  // GRALLOC_QSD8K_GPU_H
77