| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/gfx/platform_canvas_mac.h" | |
| 6 | |
| 7 #include "base/gfx/bitmap_platform_device_mac.h" | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace gfx { | |
| 11 | |
| 12 PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() { | |
| 13 } | |
| 14 | |
| 15 PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque) | |
| 16 : SkCanvas() { | |
| 17 initialize(width, height, is_opaque); | |
| 18 } | |
| 19 | |
| 20 PlatformCanvasMac::PlatformCanvasMac(int width, | |
| 21 int height, | |
| 22 bool is_opaque, | |
| 23 CGContextRef context) | |
| 24 : SkCanvas() { | |
| 25 initialize(width, height, is_opaque); | |
| 26 } | |
| 27 | |
| 28 PlatformCanvasMac::~PlatformCanvasMac() { | |
| 29 } | |
| 30 | |
| 31 bool PlatformCanvasMac::initialize(int width, | |
| 32 int height, | |
| 33 bool is_opaque) { | |
| 34 SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL); | |
| 35 if (!device) | |
| 36 return false; | |
| 37 | |
| 38 setDevice(device); | |
| 39 device->unref(); // was created with refcount 1, and setDevice also refs | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 CGContextRef PlatformCanvasMac::beginPlatformPaint() { | |
| 44 return getTopPlatformDevice().GetBitmapContext(); | |
| 45 } | |
| 46 | |
| 47 void PlatformCanvasMac::endPlatformPaint() { | |
| 48 // flushing will be done in onAccessBitmap | |
| 49 } | |
| 50 | |
| 51 PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const { | |
| 52 // All of our devices should be our special PlatformDeviceMac. | |
| 53 SkCanvas::LayerIter iter(const_cast<PlatformCanvasMac*>(this), false); | |
| 54 return *static_cast<PlatformDeviceMac*>(iter.device()); | |
| 55 } | |
| 56 | |
| 57 SkDevice* PlatformCanvasMac::createDevice(SkBitmap::Config config, | |
| 58 int width, | |
| 59 int height, | |
| 60 bool is_opaque, bool isForLayer) { | |
| 61 DCHECK(config == SkBitmap::kARGB_8888_Config); | |
| 62 return createPlatformDevice(width, height, is_opaque, NULL); | |
| 63 } | |
| 64 | |
| 65 SkDevice* PlatformCanvasMac::createPlatformDevice(int width, | |
| 66 int height, | |
| 67 bool is_opaque, | |
| 68 CGContextRef context) { | |
| 69 SkDevice* device = BitmapPlatformDeviceMac::Create(context, width, height, | |
| 70 is_opaque); | |
| 71 return device; | |
| 72 } | |
| 73 | |
| 74 SkDevice* PlatformCanvasMac::setBitmapDevice(const SkBitmap&) { | |
| 75 NOTREACHED(); | |
| 76 return NULL; | |
| 77 } | |
| 78 | |
| 79 } // namespace gfx | |
| 80 | |
| OLD | NEW |