Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / skia / ext / bitmap_platform_device_win.h
blob4a8ad8fff559b048885c337dba00a61bb4dfe07e
1 // Copyright (c) 2012 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.
5 #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_
6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "skia/ext/platform_device.h"
11 #include "skia/ext/refptr.h"
13 namespace skia {
15 // A device is basically a wrapper around SkBitmap that provides a surface for
16 // SkCanvas to draw into. Our device provides a surface Windows can also write
17 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
18 // format that Skia supports and can then use this to draw ClearType into, etc.
19 // This pixel data is provided to the bitmap that the device contains so that it
20 // can be shared.
22 // The GDI bitmap created for drawing is actually owned by a
23 // PlatformBitmapPixelRef, and stored in an SkBitmap via the normal skia
24 // SkPixelRef refcounting mechanism. In this way, the GDI bitmap can outlive
25 // the device created to draw into it. So it is safe to call accessBitmap() on
26 // the device, and retain the returned SkBitmap.
27 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
28 public:
29 // Factory function. is_opaque should be set if the caller knows the bitmap
30 // will be completely opaque and allows some optimizations.
32 // The |shared_section| parameter is optional (pass NULL for default
33 // behavior). If |shared_section| is non-null, then it must be a handle to a
34 // file-mapping object returned by CreateFileMapping. See CreateDIBSection
35 // for details. If |shared_section| is null, the bitmap backing store is not
36 // initialized.
37 static BitmapPlatformDevice* Create(int width, int height,
38 bool is_opaque, HANDLE shared_section,
39 bool do_clear = false);
41 // Create a BitmapPlatformDevice with no shared section. The bitmap is not
42 // initialized to 0.
43 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque);
45 virtual ~BitmapPlatformDevice();
47 // PlatformDevice overrides
48 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
49 // bitmap DC is lazy created.
50 virtual PlatformSurface BeginPlatformPaint() override;
51 virtual void EndPlatformPaint() override;
53 // Loads the given transform and clipping region into the HDC. This is
54 // overridden from SkBaseDevice.
55 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
56 const SkClipStack&) override;
58 void DrawToHDC(HDC dc, int x, int y, const RECT* src_rect) override;
60 protected:
61 // Flushes the Windows device context so that the pixel data can be accessed
62 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia
63 // starts accessing pixel data.
64 virtual const SkBitmap& onAccessBitmap() override;
66 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
68 private:
69 // Private constructor.
70 BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap);
72 // Bitmap into which the drawing will be done. This bitmap not owned by this
73 // class, but by the BitmapPlatformPixelRef inside the device's SkBitmap.
74 // It's only stored here in order to lazy-create the DC (below).
75 HBITMAP hbitmap_;
77 // Previous bitmap held by the DC. This will be selected back before the
78 // DC is destroyed.
79 HBITMAP old_hbitmap_;
81 // Lazily-created DC used to draw into the bitmap; see GetBitmapDC().
82 HDC hdc_;
84 // True when there is a transform or clip that has not been set to the
85 // context. The context is retrieved for every text operation, and the
86 // transform and clip do not change as much. We can save time by not loading
87 // the clip and transform for every one.
88 bool config_dirty_;
90 // Translation assigned to the context: we need to keep track of this
91 // separately so it can be updated even if the context isn't created yet.
92 SkMatrix transform_;
94 // The current clipping region.
95 SkRegion clip_region_;
97 // Create/destroy hdc_, which is the memory DC for our bitmap data.
98 HDC GetBitmapDC();
99 void ReleaseBitmapDC();
100 bool IsBitmapDCCreated() const;
102 // Sets the transform and clip operations. This will not update the DC,
103 // but will mark the config as dirty. The next call of LoadConfig will
104 // pick up these changes.
105 void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
107 // Loads the current transform and clip into the context. Can be called even
108 // when |hbitmap_| is NULL (will be a NOP).
109 void LoadConfig();
111 #ifdef SK_DEBUG
112 int begin_paint_count_;
113 #endif
115 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
118 } // namespace skia
120 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_