File: skia_utils_win.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (127 lines) | stat: -rw-r--r-- 5,051 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2006-2008 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKIA_EXT_SKIA_UTILS_WIN_H_
#define SKIA_EXT_SKIA_UTILS_WIN_H_

#include <windows.h>

#include <vector>

#include "base/win/scoped_gdi_object.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkRefCnt.h"

struct SkIRect;
struct SkPoint;
struct SkRect;
class SkSurface;
typedef unsigned long DWORD;
typedef DWORD COLORREF;
typedef struct tagPOINT POINT;
typedef struct tagRECT RECT;

namespace skia {

// Converts a Skia point to a Windows POINT.
POINT SkPointToPOINT(const SkPoint& point);

// Converts a Windows RECT to a Skia rect.
SkRect RECTToSkRect(const RECT& rect);

// Converts a Windows RECT to a Skia rect.
// Both use same in-memory format. Verified by static_assert in
// skia_utils_win.cc.
inline const SkIRect& RECTToSkIRect(const RECT& rect) {
  return reinterpret_cast<const SkIRect&>(rect);
}

// Converts a Skia rect to a Windows RECT.
// Both use same in-memory format. Verified by static_assert in
// skia_utils_win.cc.
inline const RECT& SkIRectToRECT(const SkIRect& rect) {
  return reinterpret_cast<const RECT&>(rect);
}

// Converts COLORREFs (0BGR) to the ARGB layout Skia expects.
SK_API SkColor COLORREFToSkColor(COLORREF color);

// Converts ARGB to COLORREFs (0BGR).
SK_API COLORREF SkColorToCOLORREF(SkColor color);

// Initializes the default settings and colors in a device context.
SK_API void InitializeDC(HDC context);

// Converts scale, skew, and translation to Windows format and sets it on the
// HDC.
SK_API void LoadTransformToDC(HDC dc, const SkMatrix& matrix);

// Copies |src_rect| from source into destination.
//   Takes a potentially-slower path if |is_opaque| is false.
//   Sets |transform| on source afterwards!
SK_API void CopyHDC(HDC source, HDC destination, int x, int y, bool is_opaque,
                    const RECT& src_rect, const SkMatrix& transform);

// Creates a surface writing to the pixels backing |context|'s bitmap.
// Returns null on error.
SK_API sk_sp<SkSurface> MapPlatformSurface(HDC context);

// Creates a bitmap backed by the same pixels backing the HDC's bitmap.
// Returns an empty bitmap on error. The HDC's bitmap is assumed to be formatted
// as 32-bits-per-pixel XRGB8888, as created by CreateHBitmapXRGB8888().
SK_API SkBitmap MapPlatformBitmap(HDC context);

// Fills in a BITMAPINFOHEADER structure to hold the pixel data from |bitmap|.
// The |bitmap| must be have a color type of kN32_SkColorType, and the header
// will be for a bitmap with 32-bits-per-pixel RGB data (the high bits are
// unused in each pixel).
SK_API void CreateBitmapHeaderForN32SkBitmap(const SkBitmap& bitmap,
                                             BITMAPINFOHEADER* hdr);

// Creates a globally allocated memory containing the given byte array. The
// returned handle to the global memory is allocated by ::GlobalAlloc(), and
// must be explicitly freed by ::GlobalFree(), unless ownership is passed to the
// Win32 API. On failure, it returns null.
SK_API HGLOBAL
CreateHGlobalForByteArray(const std::vector<unsigned char>& byte_array);

// Creates an HBITMAP backed by 32-bits-per-pixel RGB data (the high bits are
// unused in each pixel), with dimensions and the RGBC pixel data from the
// SkBitmap. Any alpha channel values are copied into the HBITMAP but are not
// used. Can return a null HBITMAP on any failure to create the HBITMAP.
SK_API base::win::ScopedGDIObject<HBITMAP> CreateHBitmapFromN32SkBitmap(
    const SkBitmap& bitmap);

// Creates an image in the DIBV5 format. On success this function returns a
// handle to an allocated memory block containing a DIBV5 header followed by the
// pixel data. If the bitmap creation fails, it returns null. This is preferred
// in some cases over the HBITMAP format because it handles transparency better.
// The returned handle to the global memory is allocated by ::GlobalAlloc(), and
// must be explicitly freed by ::GlobalFree(), unless ownership is passed to the
// Win32 API.
SK_API HGLOBAL CreateDIBV5ImageDataFromN32SkBitmap(const SkBitmap& bitmap);

// Fills in a BITMAPINFOHEADER structure given the bitmap's size. The header
// will be for a bitmap with 32-bits-per-pixel RGB data (the high bits are
// unused in each pixel).
SK_API void CreateBitmapHeaderForXRGB888(int width,
                                         int height,
                                         BITMAPINFOHEADER* hdr);

// Creates an HBITMAP backed by 32-bits-per-pixel RGB data (the high bits are
// unused in each pixel).
SK_API base::win::ScopedGDIObject<HBITMAP> CreateHBitmapXRGB8888(
    int width,
    int height,
    HANDLE shared_section = nullptr,
    void** data = nullptr);

}  // namespace skia

#endif  // SKIA_EXT_SKIA_UTILS_WIN_H_