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

Unified Diff: webkit/glue/plugins/pepper_image_data.h

Issue 2080021: Chrome-side of tests for Pepper Device2D. This includes some bugfixes and min... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/plugins/pepper_device_context_2d.cc ('k') | webkit/glue/plugins/pepper_image_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/plugins/pepper_image_data.h
===================================================================
--- webkit/glue/plugins/pepper_image_data.h (revision 48097)
+++ webkit/glue/plugins/pepper_image_data.h (working copy)
@@ -5,13 +5,12 @@
#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_
+#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "third_party/ppapi/c/ppb_image_data.h"
#include "webkit/glue/plugins/pepper_plugin_delegate.h"
#include "webkit/glue/plugins/pepper_resource.h"
-typedef struct _ppb_ImageData PPB_ImageData;
-
namespace skia {
class PlatformCanvas;
}
@@ -30,10 +29,16 @@
int width() const { return width_; }
int height() const { return height_; }
- // Returns true if this image is valid and can be used. False means that the
- // image is invalid and can't be used.
- bool is_valid() const { return !!platform_image_.get(); }
+ // Returns the image format. Currently there is only one format so this
+ // always returns the same thing. But if you care about the formation, you
+ // should probably check this so when we support multiple formats, we can't
+ // forget to update your code.
+ PP_ImageDataFormat format() const { return PP_IMAGEDATAFORMAT_BGRA_PREMUL; }
+ // Returns true if this image is mapped. False means that the image is either
+ // invalid or not mapped. See ImageDataAutoMapper below.
+ bool is_mapped() const { return !!mapped_canvas_.get(); }
+
// Returns a pointer to the interface implementing PPB_ImageData that is
// exposed to the plugin.
static const PPB_ImageData* GetInterface();
@@ -49,10 +54,10 @@
void* Map();
void Unmap();
+ // The mapped bitmap and canvas will be NULL if the image is not mapped.
skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); }
+ const SkBitmap* GetMappedBitmap() const;
- const SkBitmap& GetMappedBitmap() const;
-
// Swaps the guts of this image data with another.
void Swap(ImageData* other);
@@ -70,6 +75,44 @@
DISALLOW_COPY_AND_ASSIGN(ImageData);
};
+// Manages mapping an image resource if necessary. Use this to ensure the
+// image is mapped. The destructor will put the image back into the previous
+// state. You must check is_valid() to make sure the image was successfully
+// mapped before using it.
+//
+// Example:
+// ImageDataAutoMapper mapper(image_data);
+// if (!mapper.is_valid())
+// return utter_failure;
+// image_data->mapped_canvas()->blah(); // Guaranteed valid.
+class ImageDataAutoMapper {
+ public:
+ ImageDataAutoMapper(ImageData* image_data) : image_data_(image_data) {
+ if (image_data_->is_mapped()) {
+ is_valid_ = true;
+ needs_unmap_ = false;
+ } else {
+ is_valid_ = needs_unmap_ = !!image_data_->Map();
+ }
+ }
+
+ ~ImageDataAutoMapper() {
+ if (needs_unmap_)
+ image_data_->Unmap();
+ }
+
+ // Check this to see if the image was successfully mapped. If this is false,
+ // the image could not be mapped and is unusable.
+ bool is_valid() const { return is_valid_; }
+
+ private:
+ ImageData* image_data_;
+ bool is_valid_;
+ bool needs_unmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper);
+};
+
} // namespace pepper
#endif // WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_
« no previous file with comments | « webkit/glue/plugins/pepper_device_context_2d.cc ('k') | webkit/glue/plugins/pepper_image_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698