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

Unified Diff: skia/ext/bitmap_platform_device_mac.cc

Issue 11031055: Introduce PlatformBitmap, which is a minimal helper class that wraps an SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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
Index: skia/ext/bitmap_platform_device_mac.cc
===================================================================
--- skia/ext/bitmap_platform_device_mac.cc (revision 160846)
+++ skia/ext/bitmap_platform_device_mac.cc (working copy)
@@ -16,6 +16,8 @@
#include "third_party/skia/include/core/SkTypes.h"
#include "third_party/skia/include/core/SkUtils.h"
+#include "skia/ext/platform_canvas.h"
brettw 2012/10/09 20:40:12 This should go in the above block in order.
reed1 2012/10/09 21:06:43 Done.
+
namespace skia {
namespace {
@@ -254,4 +256,36 @@
return bitmap_device;
}
+// Port of PlatformBitmap to mac
+
+PlatformBitmap::~PlatformBitmap() {
+ if (surface_)
+ CGContextRelease(surface_);
+}
+
+bool PlatformBitmap::Allocate(int width, int height, bool isOpaque) {
+ if (RasterDeviceTooBigToAllocate(width, height))
+ return false;
+
+ bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4);
+ if (!bitmap_.allocPixels())
+ return false;
+
+ if (!isOpaque)
+ bitmap_.eraseColor(0);
+ bitmap_.setIsOpaque(isOpaque);
+ return true;
+}
+
+PlatformSurface PlatformBitmap::LockSurface() {
+ if (!surface_ && bitmap_.getPixels())
+ surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(),
+ bitmap_.height());
+ return surface_;
+}
+
+void PlatformBitmap::UnlockSurface() {
+ // nothing to do for our CGContext. It will be released in our destructor
+}
+
} // namespace skia

Powered by Google App Engine
This is Rietveld 408576698