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

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

Issue 7082036: Convert more interfaces to the new thunk system. (Closed) Base URL: svn://chrome-svn/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
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
8 namespace ppapi { 26 namespace ppapi {
9 27
28 // Forward declare all the resource APIs.
10 namespace thunk { 29 namespace thunk {
11 class PPB_Audio_API; 30 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
12 class PPB_AudioConfig_API; 31 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS)
13 class PPB_AudioTrusted_API; 32 #undef DECLARE_RESOURCE_CLASS
14 class PPB_Broker_API; 33 } // namespace thunk
15 class PPB_Buffer_API;
16 class PPB_Font_API;
17 class PPB_Graphics2D_API;
18 class PPB_ImageData_API;
19 }
20 34
21 class ResourceObjectBase { 35 class ResourceObjectBase {
22 public: 36 public:
37 virtual ~ResourceObjectBase();
23 38
24 virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; } 39 // Inheritance-based dynamic casting. Returns the pointer to the given type
25 virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; } 40 // if it's supported. Derived classes override these AsXXX methods to return
26 virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; } 41 // the ones they support.
27 virtual thunk::PPB_Buffer_API* AsBuffer_API() { return NULL; } 42 #define DEFINE_TYPE_GETTER(RESOURCE) \
28 virtual thunk::PPB_Broker_API* AsBroker_API() { return NULL; } 43 virtual thunk::RESOURCE* As##RESOURCE();
29 virtual thunk::PPB_Font_API* AsFont_API() { return NULL; } 44 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
30 virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; } 45 #undef DEFINE_TYPE_GETTER
31 virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; }
32 46
47 // Template-based dynamic casting. See specializations below.
33 template <typename T> T* GetAs() { return NULL; } 48 template <typename T> T* GetAs() { return NULL; }
34 }; 49 };
35 50
36 template<> 51 // Template-based dynamic casting. These specializatins forward to the
37 inline thunk::PPB_Audio_API* ResourceObjectBase::GetAs() { 52 // AsXXX virtual functions to return whether the given type is supported.
38 return AsAudio_API(); 53 #define DEFINE_RESOURCE_CAST(RESOURCE) \
39 } 54 template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \
40 template<> 55 return As##RESOURCE(); \
41 inline thunk::PPB_AudioConfig_API* ResourceObjectBase::GetAs() { 56 }
42 return AsAudioConfig_API(); 57 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST)
43 } 58 #undef DEFINE_RESOURCE_CAST
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 }
68 59
69 } // namespace ppapi 60 } // namespace ppapi
70 61
71 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ 62 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698