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

Side by Side Diff: webkit/plugins/ppapi/ppb_image_data_impl.h

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_ 6 #define WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "ppapi/c/ppb_image_data.h" 10 #include "ppapi/c/ppb_image_data.h"
11 #include "webkit/glue/plugins/pepper_plugin_delegate.h" 11 #include "webkit/plugins/ppapi/plugin_delegate.h"
12 #include "webkit/glue/plugins/pepper_resource.h" 12 #include "webkit/plugins/ppapi/resource.h"
13 13
14 namespace skia { 14 namespace skia {
15 class PlatformCanvas; 15 class PlatformCanvas;
16 } 16 }
17 17
18 struct PPB_ImageDataTrusted; 18 struct PPB_ImageDataTrusted;
19 class SkBitmap; 19 class SkBitmap;
20 20
21 namespace pepper { 21 namespace webkit {
22 namespace plugins {
23 namespace ppapi {
22 24
23 class ImageData : public Resource { 25 class PPB_ImageData_Impl : public Resource {
24 public: 26 public:
25 explicit ImageData(PluginModule* module); 27 explicit PPB_ImageData_Impl(PluginModule* module);
26 virtual ~ImageData(); 28 virtual ~PPB_ImageData_Impl();
27 29
28 int width() const { return width_; } 30 int width() const { return width_; }
29 int height() const { return height_; } 31 int height() const { return height_; }
30 32
31 // Returns the image format. 33 // Returns the image format.
32 PP_ImageDataFormat format() const { return format_; } 34 PP_ImageDataFormat format() const { return format_; }
33 35
34 // Returns true if this image is mapped. False means that the image is either 36 // Returns true if this image is mapped. False means that the image is either
35 // invalid or not mapped. See ImageDataAutoMapper below. 37 // invalid or not mapped. See ImageDataAutoMapper below.
36 bool is_mapped() const { return !!mapped_canvas_.get(); } 38 bool is_mapped() const { return !!mapped_canvas_.get(); }
37 39
38 PluginDelegate::PlatformImage2D* platform_image() const { 40 PluginDelegate::PlatformImage2D* platform_image() const {
39 return platform_image_.get(); 41 return platform_image_.get();
40 } 42 }
41 43
42 // Returns a pointer to the interface implementing PPB_ImageData that is 44 // Returns a pointer to the interface implementing PPB_ImageData that is
43 // exposed to the plugin. 45 // exposed to the plugin.
44 static const PPB_ImageData* GetInterface(); 46 static const PPB_ImageData* GetInterface();
45 static const PPB_ImageDataTrusted* GetTrustedInterface(); 47 static const PPB_ImageDataTrusted* GetTrustedInterface();
46 48
47 // Returns the image data format used by the browser. If the plugin uses the 49 // Returns the image data format used by the browser. If the plugin uses the
48 // same format, there is no conversion. Otherwise the browser will be in 50 // same format, there is no conversion. Otherwise the browser will be in
49 // charge of converting from a supported format to its native format. 51 // charge of converting from a supported format to its native format.
50 static PP_ImageDataFormat GetNativeImageDataFormat(); 52 static PP_ImageDataFormat GetNativeImageDataFormat();
51 53
52 // Returns true if the format is supported by the browser. 54 // Returns true if the format is supported by the browser.
53 static bool IsImageDataFormatSupported(PP_ImageDataFormat format); 55 static bool IsImageDataFormatSupported(PP_ImageDataFormat format);
54 56
55 // Resource overrides. 57 // Resource overrides.
56 virtual ImageData* AsImageData() { return this; } 58 virtual PPB_ImageData_Impl* AsImageData();
57 59
58 // PPB_ImageData implementation. 60 // PPB_ImageData implementation.
59 bool Init(PP_ImageDataFormat format, 61 bool Init(PP_ImageDataFormat format,
60 int width, int height, 62 int width, int height,
61 bool init_to_zero); 63 bool init_to_zero);
62 void Describe(PP_ImageDataDesc* desc) const; 64 void Describe(PP_ImageDataDesc* desc) const;
63 void* Map(); 65 void* Map();
64 void Unmap(); 66 void Unmap();
65 67
66 // PPB_ImageDataTrusted implementation. 68 // PPB_ImageDataTrusted implementation.
67 int GetSharedMemoryHandle(uint32* byte_count) const; 69 int GetSharedMemoryHandle(uint32* byte_count) const;
68 70
69 // The mapped bitmap and canvas will be NULL if the image is not mapped. 71 // The mapped bitmap and canvas will be NULL if the image is not mapped.
70 skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); } 72 skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); }
71 const SkBitmap* GetMappedBitmap() const; 73 const SkBitmap* GetMappedBitmap() const;
72 74
73 // Swaps the guts of this image data with another. 75 // Swaps the guts of this image data with another.
74 void Swap(ImageData* other); 76 void Swap(PPB_ImageData_Impl* other);
75 77
76 private: 78 private:
77 // This will be NULL before initialization, and if this ImageData is 79 // This will be NULL before initialization, and if this PPB_ImageData_Impl is
78 // swapped with another. 80 // swapped with another.
79 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; 81 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_;
80 82
81 // When the device is mapped, this is the image. Null when umapped. 83 // When the device is mapped, this is the image. Null when umapped.
82 scoped_ptr<skia::PlatformCanvas> mapped_canvas_; 84 scoped_ptr<skia::PlatformCanvas> mapped_canvas_;
83 85
84 PP_ImageDataFormat format_; 86 PP_ImageDataFormat format_;
85 int width_; 87 int width_;
86 int height_; 88 int height_;
87 89
88 DISALLOW_COPY_AND_ASSIGN(ImageData); 90 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl);
89 }; 91 };
90 92
91 // Manages mapping an image resource if necessary. Use this to ensure the 93 // Manages mapping an image resource if necessary. Use this to ensure the
92 // image is mapped. The destructor will put the image back into the previous 94 // image is mapped. The destructor will put the image back into the previous
93 // state. You must check is_valid() to make sure the image was successfully 95 // state. You must check is_valid() to make sure the image was successfully
94 // mapped before using it. 96 // mapped before using it.
95 // 97 //
96 // Example: 98 // Example:
97 // ImageDataAutoMapper mapper(image_data); 99 // ImageDataAutoMapper mapper(image_data);
98 // if (!mapper.is_valid()) 100 // if (!mapper.is_valid())
99 // return utter_failure; 101 // return utter_failure;
100 // image_data->mapped_canvas()->blah(); // Guaranteed valid. 102 // image_data->mapped_canvas()->blah(); // Guaranteed valid.
101 class ImageDataAutoMapper { 103 class ImageDataAutoMapper {
102 public: 104 public:
103 ImageDataAutoMapper(ImageData* image_data) : image_data_(image_data) { 105 ImageDataAutoMapper(PPB_ImageData_Impl* image_data)
106 : image_data_(image_data) {
104 if (image_data_->is_mapped()) { 107 if (image_data_->is_mapped()) {
105 is_valid_ = true; 108 is_valid_ = true;
106 needs_unmap_ = false; 109 needs_unmap_ = false;
107 } else { 110 } else {
108 is_valid_ = needs_unmap_ = !!image_data_->Map(); 111 is_valid_ = needs_unmap_ = !!image_data_->Map();
109 } 112 }
110 } 113 }
111 114
112 ~ImageDataAutoMapper() { 115 ~ImageDataAutoMapper() {
113 if (needs_unmap_) 116 if (needs_unmap_)
114 image_data_->Unmap(); 117 image_data_->Unmap();
115 } 118 }
116 119
117 // Check this to see if the image was successfully mapped. If this is false, 120 // Check this to see if the image was successfully mapped. If this is false,
118 // the image could not be mapped and is unusable. 121 // the image could not be mapped and is unusable.
119 bool is_valid() const { return is_valid_; } 122 bool is_valid() const { return is_valid_; }
120 123
121 private: 124 private:
122 ImageData* image_data_; 125 PPB_ImageData_Impl* image_data_;
123 bool is_valid_; 126 bool is_valid_;
124 bool needs_unmap_; 127 bool needs_unmap_;
125 128
126 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); 129 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper);
127 }; 130 };
128 131
129 } // namespace pepper 132 } // namespace ppapi
133 } // namespace plugins
134 } // namespace webkit
130 135
131 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_ 136 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698