Commit 838d49c2 authored by K. Moon's avatar K. Moon Committed by Commit Bot

Reimplement chrome_pdf::Image using absl::variant

Now that we're allowed to use absl::variant, reimplement Image to use an
absl::variant<pp::ImageData, SkBitmap> internally. Behavior should
remain largely the same, with slightly less memory overhead.

Bug: 1099020
Change-Id: Ia4b2398ceae6156997be8904562778d47af97e32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333538Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794775}
parent 6ff4c74b
...@@ -196,6 +196,8 @@ if (enable_pdf) { ...@@ -196,6 +196,8 @@ if (enable_pdf) {
configs += [ ":pdf_common_config" ] configs += [ ":pdf_common_config" ]
public_deps = [ "//third_party/abseil-cpp:absl" ]
deps = [ deps = [
"//base", "//base",
"//ppapi/cpp:objects", "//ppapi/cpp:objects",
...@@ -214,6 +216,8 @@ if (enable_pdf) { ...@@ -214,6 +216,8 @@ if (enable_pdf) {
configs += [ ":pdf_common_config" ] configs += [ ":pdf_common_config" ]
public_deps = [ "//third_party/abseil-cpp:absl" ]
deps = [ deps = [
":features", ":features",
":internal", ":internal",
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
#include "pdf/ppapi_migration/image.h" #include "pdf/ppapi_migration/image.h"
#include "ppapi/cpp/image_data.h" #include "ppapi/cpp/image_data.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace chrome_pdf { namespace chrome_pdf {
Image::Image(const pp::ImageData& pepper_image) : pepper_image_(pepper_image) {} Image::Image(const pp::ImageData& pepper_image) : image_(pepper_image) {}
Image::Image(const SkBitmap& skia_image) : skia_image_(skia_image) {} Image::Image(const SkBitmap& skia_image) : image_(skia_image) {}
Image::Image(const Image& other) = default; Image::Image(const Image& other) = default;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#ifndef PDF_PPAPI_MIGRATION_IMAGE_H_ #ifndef PDF_PPAPI_MIGRATION_IMAGE_H_
#define PDF_PPAPI_MIGRATION_IMAGE_H_ #define PDF_PPAPI_MIGRATION_IMAGE_H_
#include "base/check.h"
#include "ppapi/cpp/image_data.h" #include "ppapi/cpp/image_data.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -24,18 +24,13 @@ class Image final { ...@@ -24,18 +24,13 @@ class Image final {
~Image(); ~Image();
const pp::ImageData& pepper_image() const { const pp::ImageData& pepper_image() const {
DCHECK(skia_image_.isNull()); return absl::get<pp::ImageData>(image_);
return pepper_image_;
} }
const SkBitmap& skia_image() const { const SkBitmap& skia_image() const { return absl::get<SkBitmap>(image_); }
DCHECK(pepper_image_.is_null());
return skia_image_;
}
private: private:
pp::ImageData pepper_image_; absl::variant<pp::ImageData, SkBitmap> image_;
SkBitmap skia_image_;
}; };
} // namespace chrome_pdf } // namespace chrome_pdf
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment