| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 BASE_GFX_PLATFORM_DEVICE_MAC_H__ | 5 #ifndef BASE_GFX_PLATFORM_DEVICE_MAC_H__ |
| 6 #define BASE_GFX_PLATFORM_DEVICE_MAC_H__ | 6 #define BASE_GFX_PLATFORM_DEVICE_MAC_H__ |
| 7 | 7 |
| 8 #import <ApplicationServices/ApplicationServices.h> | 8 // TODO(brettw) this file should be removed and the includes changed to this |
| 9 #include "SkDevice.h" | 9 // new location. |
| 10 | 10 #include "webkit/port/platform/graphics/skia/public/PlatformDeviceMac.h" |
| 11 class SkMatrix; | |
| 12 class SkPath; | |
| 13 class SkRegion; | |
| 14 | |
| 15 namespace gfx { | |
| 16 | |
| 17 // A device is basically a wrapper around SkBitmap that provides a surface for | |
| 18 // SkCanvas to draw into. Our device provides a surface CoreGraphics can also | |
| 19 // write to. It also provides functionality to play well with CG drawing | |
| 20 // functions. | |
| 21 // This class is abstract and must be subclassed. It provides the basic | |
| 22 // interface to implement it either with or without a bitmap backend. | |
| 23 class PlatformDeviceMac : public SkDevice { | |
| 24 public: | |
| 25 // The CGContext that corresponds to the bitmap, used for CoreGraphics | |
| 26 // operations drawing into the bitmap. This is possibly heavyweight, so it | |
| 27 // should exist only during one pass of rendering. | |
| 28 virtual CGContextRef GetBitmapContext() = 0; | |
| 29 | |
| 30 // Draws to the given graphics context. If the bitmap context doesn't exist, | |
| 31 // this will temporarily create it. However, if you have created the bitmap | |
| 32 // context, it will be more efficient if you don't free it until after this | |
| 33 // call so it doesn't have to be created twice. If src_rect is null, then | |
| 34 // the entirety of the source device will be copied. | |
| 35 virtual void DrawToContext(CGContextRef context, int x, int y, | |
| 36 const CGRect* src_rect) = 0; | |
| 37 | |
| 38 // Sets the opacity of each pixel in the specified region to be opaque. | |
| 39 void makeOpaque(int x, int y, int width, int height); | |
| 40 | |
| 41 // Returns if the preferred rendering engine is vectorial or bitmap based. | |
| 42 virtual bool IsVectorial() = 0; | |
| 43 | |
| 44 // On platforms where the native rendering API does not support rendering | |
| 45 // into bitmaps with a premultiplied alpha channel, this call is responsible | |
| 46 // for doing any fixup necessary. It is not used on the Mac, since | |
| 47 // CoreGraphics can handle premultiplied alpha just fine. | |
| 48 virtual void fixupAlphaBeforeCompositing() = 0; | |
| 49 | |
| 50 // Initializes the default settings and colors in a device context. | |
| 51 static void InitializeCGContext(CGContextRef context); | |
| 52 | |
| 53 // Loads a SkPath into the CG context. The path can there after be used for | |
| 54 // clipping or as a stroke. | |
| 55 static void LoadPathToCGContext(CGContextRef context, const SkPath& path); | |
| 56 | |
| 57 // Loads a SkRegion into the CG context. | |
| 58 static void LoadClippingRegionToCGContext(CGContextRef context, | |
| 59 const SkRegion& region, | |
| 60 const SkMatrix& transformation); | |
| 61 | |
| 62 protected: | |
| 63 // Forwards |bitmap| to SkDevice's constructor. | |
| 64 PlatformDeviceMac(const SkBitmap& bitmap); | |
| 65 | |
| 66 // Loads the specified Skia transform into the device context | |
| 67 static void LoadTransformToCGContext(CGContextRef context, | |
| 68 const SkMatrix& matrix); | |
| 69 | |
| 70 // Function pointer used by the processPixels method for setting the alpha | |
| 71 // value of a particular pixel. | |
| 72 typedef void (*adjustAlpha)(uint32_t* pixel); | |
| 73 | |
| 74 // Loops through each of the pixels in the specified range, invoking | |
| 75 // adjustor for the alpha value of each pixel. | |
| 76 virtual void processPixels(int x, | |
| 77 int y, | |
| 78 int width, | |
| 79 int height, | |
| 80 adjustAlpha adjustor) = 0; | |
| 81 }; | |
| 82 | |
| 83 } // namespace gfx | |
| 84 | 11 |
| 85 #endif // BASE_GFX_PLATFORM_DEVICE_MAC_H__ | 12 #endif // BASE_GFX_PLATFORM_DEVICE_MAC_H__ |
| 86 | 13 |
| OLD | NEW |