Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: ppapi/shared_impl/resource_object_base.h

Issue 7006022: Revert 87415 - Convert more interfaces to the new thunk system. This goes up to and including (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/function_group_base.cc ('k') | ppapi/shared_impl/resource_object_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ 6 #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
7 7
8 #include <stddef.h> // For NULL.
9
10 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \
11 F(PPB_Audio_API) \
12 F(PPB_AudioConfig_API) \
13 F(PPB_AudioTrusted_API) \
14 F(PPB_Broker_API) \
15 F(PPB_Buffer_API) \
16 F(PPB_DirectoryReader_API) \
17 F(PPB_FileChooser_API) \
18 F(PPB_FileIO_API) \
19 F(PPB_FileRef_API) \
20 F(PPB_FileSystem_API) \
21 F(PPB_Find_API) \
22 F(PPB_Font_API) \
23 F(PPB_Graphics2D_API) \
24 F(PPB_ImageData_API)
25
26 namespace ppapi { 8 namespace ppapi {
27 9
28 // Forward declare all the resource APIs.
29 namespace thunk { 10 namespace thunk {
30 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; 11 class PPB_Audio_API;
31 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) 12 class PPB_AudioConfig_API;
32 #undef DECLARE_RESOURCE_CLASS 13 class PPB_AudioTrusted_API;
33 } // namespace thunk 14 class PPB_Broker_API;
15 class PPB_Buffer_API;
16 class PPB_Font_API;
17 class PPB_Graphics2D_API;
18 class PPB_ImageData_API;
19 }
34 20
35 class ResourceObjectBase { 21 class ResourceObjectBase {
36 public: 22 public:
37 virtual ~ResourceObjectBase();
38 23
39 // Dynamic casting for this object. Returns the pointer to the given type if 24 virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; }
40 // Inheritance-based dynamic casting for this object. Returns the pointer to 25 virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; }
41 // the given type if it's supported. Derived classes override the functions 26 virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; }
42 // they support to return the interface. 27 virtual thunk::PPB_Buffer_API* AsBuffer_API() { return NULL; }
43 #define DEFINE_TYPE_GETTER(RESOURCE) \ 28 virtual thunk::PPB_Broker_API* AsBroker_API() { return NULL; }
44 virtual thunk::RESOURCE* As##RESOURCE(); 29 virtual thunk::PPB_Font_API* AsFont_API() { return NULL; }
45 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) 30 virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; }
46 #undef DEFINE_TYPE_GETTER 31 virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; }
47 32
48 // Template-based dynamic casting. See specializations below.
49 template <typename T> T* GetAs() { return NULL; } 33 template <typename T> T* GetAs() { return NULL; }
50 }; 34 };
51 35
52 // Template-based dynamic casting. These specializations forward to the 36 template<>
53 // AsXXX virtual functions to return whether the given type is supported. 37 inline thunk::PPB_Audio_API* ResourceObjectBase::GetAs() {
54 #define DEFINE_RESOURCE_CAST(RESOURCE) \ 38 return AsAudio_API();
55 template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \ 39 }
56 return As##RESOURCE(); \ 40 template<>
57 } 41 inline thunk::PPB_AudioConfig_API* ResourceObjectBase::GetAs() {
58 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) 42 return AsAudioConfig_API();
59 #undef DEFINE_RESOURCE_CAST 43 }
44 template<>
45 inline thunk::PPB_AudioTrusted_API* ResourceObjectBase::GetAs() {
46 return AsAudioTrusted_API();
47 }
48 template<>
49 inline thunk::PPB_Broker_API* ResourceObjectBase::GetAs() {
50 return AsBroker_API();
51 }
52 template<>
53 inline thunk::PPB_Buffer_API* ResourceObjectBase::GetAs() {
54 return AsBuffer_API();
55 }
56 template<>
57 inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() {
58 return AsFont_API();
59 }
60 template<>
61 inline thunk::PPB_Graphics2D_API* ResourceObjectBase::GetAs() {
62 return AsGraphics2D_API();
63 }
64 template<>
65 inline thunk::PPB_ImageData_API* ResourceObjectBase::GetAs() {
66 return AsImageData_API();
67 }
60 68
61 } // namespace ppapi 69 } // namespace ppapi
62 70
63 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ 71 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/function_group_base.cc ('k') | ppapi/shared_impl/resource_object_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698