• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2016 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 #pragma once
18 
19 #include "aemu/base/files/Stream.h"
20 #include "GLcommon/NamedObject.h"
21 
22 #include <functional>
23 #include <memory>
24 
25 enum ObjectDataType {
26     SHADER_DATA,
27     PROGRAM_DATA,
28     TEXTURE_DATA,
29     BUFFER_DATA,
30     RENDERBUFFER_DATA,
31     FRAMEBUFFER_DATA,
32     SAMPLER_DATA,
33     TRANSFORMFEEDBACK_DATA,
34     UNDEFINED_DATA,
35 };
36 
37 class ObjectData;
38 typedef std::shared_ptr<ObjectData> ObjectDataPtr;
39 
40 extern NamedObjectType ObjectDataType2NamedObjectType(ObjectDataType objDataType);
41 
42 class ObjectData
43 {
44 public:
m_dataType(type)45     ObjectData(ObjectDataType type = UNDEFINED_DATA): m_dataType(type) {}
46     ObjectData(android::base::Stream* stream);
getDataType()47     ObjectDataType getDataType() { return m_dataType; };
48     virtual ~ObjectData() = default;
49     virtual void onSave(android::base::Stream* stream, unsigned int globalName) const = 0;
50     typedef std::function<ObjectDataPtr(NamedObjectType p_type,
51             ObjectLocalName p_localName, android::base::Stream* stream)>
52                 loadObject_t;
53     typedef std::function<const ObjectDataPtr(NamedObjectType,
54             ObjectLocalName)> const getObjDataPtr_t;
55     typedef std::function<int(NamedObjectType, ObjectLocalName)> const
56             getGlobalName_t;
57     // postLoad: setup references after loading all ObjectData from snapshot
58     // in one share group
59     virtual void postLoad(const getObjDataPtr_t& getObjDataPtr);
60     // restore: restore object data back to hardware GPU.
61     //          It must be called before restoring hardware context states,
62     //          because it messes up context object bindings.
63     virtual void restore(ObjectLocalName localName,
64                          const getGlobalName_t& getGlobalName) = 0;
65     virtual GenNameInfo getGenNameInfo() const;
66     bool needRestore() const;
67 private:
68     ObjectDataType m_dataType;
69     bool m_needRestore = false;
70 };
71 
72