forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbitmap.cc
51 lines (39 loc) · 1.54 KB
/
bitmap.cc
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ppapi_migration/bitmap.h"
#include <stdint.h>
#include <memory>
#include "base/check_op.h"
#include "ppapi/cpp/image_data.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h"
namespace chrome_pdf {
namespace {
// Releases pp::ImageData associated with the SkPixelRef. The pp::ImageData acts
// like a shared pointer to memory provided by Pepper, and must be retained for
// the life of the SkPixelRef.
void ReleaseImageData(void* addr, void* context) {
pp::ImageData* image_data = static_cast<pp::ImageData*>(context);
DCHECK_EQ(addr, image_data->data());
delete image_data;
}
} // namespace
SkBitmap SkBitmapFromPPImageData(std::unique_ptr<pp::ImageData> image_data) {
if (image_data->is_null()) {
return SkBitmap();
}
// Note that we unconditionally use BGRA_PREMUL with PDFium.
DCHECK_EQ(image_data->format(), PP_IMAGEDATAFORMAT_BGRA_PREMUL);
SkImageInfo info =
SkImageInfo::Make(image_data->size().width(), image_data->size().height(),
kBGRA_8888_SkColorType, kPremul_SkAlphaType);
void* data = image_data->data();
int32_t stride = image_data->stride();
SkBitmap bitmap;
bool success = bitmap.installPixels(info, data, stride, ReleaseImageData,
image_data.release());
DCHECK(success);
return bitmap;
}
} // namespace chrome_pdf