Skip to content

Commit

Permalink
Remove WebImage as a concrete type.
Browse files Browse the repository at this point in the history
WebImage is a wrapper for SkBitmap, which we can just use everywhere
so create and pass around SkBitmaps directly, instead of WebImages.

WebImage only has static methods left then, which are mostly used from
outside of blink, though FromData() is used internally as well, so
it seems it should stay in public/platform/ for now.

Image gains Image::AsSkBitmapForCurrentFrame() as a means to convert
the current frame to an SkBitmap without constructing a WebImage.

R=bauerb@chromium.org, haraken@chromium.org
TBR=jam

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ieb71bde672d1acd84ec36a0e991d9ee44adba718
Reviewed-on: https://chromium-review.googlesource.com/1128365
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573865}
  • Loading branch information
danakj authored and Commit Bot committed Jul 10, 2018
1 parent d7154fc commit 0c75ad8
Show file tree
Hide file tree
Showing 39 changed files with 165 additions and 224 deletions.
17 changes: 8 additions & 9 deletions chrome/renderer/chrome_render_frame_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ namespace {
// |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we
// scale down the image so that the width and height do not exceed
// |thumbnail_max_size_pixels|, preserving the original aspect ratio.
SkBitmap Downscale(const blink::WebImage& image,
SkBitmap Downscale(const SkBitmap& image,
int thumbnail_min_area_pixels,
const gfx::Size& thumbnail_max_size_pixels) {
if (image.IsNull())
if (image.isNull())
return SkBitmap();

gfx::Size image_size = image.Size();
gfx::Size image_size(image.width(), image.height());

if (image_size.GetArea() < thumbnail_min_area_pixels)
return image.GetSkBitmap();
return image;

if (image_size.width() <= thumbnail_max_size_pixels.width() &&
image_size.height() <= thumbnail_max_size_pixels.height())
return image.GetSkBitmap();
return image;

gfx::SizeF scaled_size = gfx::SizeF(image_size);

Expand All @@ -126,7 +126,7 @@ SkBitmap Downscale(const blink::WebImage& image,
thumbnail_max_size_pixels.height() / scaled_size.height());
}

return skia::ImageOperations::Resize(image.GetSkBitmap(),
return skia::ImageOperations::Resize(image,
skia::ImageOperations::RESIZE_GOOD,
static_cast<int>(scaled_size.width()),
static_cast<int>(scaled_size.height()));
Expand Down Expand Up @@ -222,9 +222,8 @@ void ChromeRenderFrameObserver::RequestThumbnailForContextNode(
SkBitmap thumbnail;
gfx::Size original_size;
if (!context_node.IsNull() && context_node.IsElementNode()) {
blink::WebImage image =
context_node.To<WebElement>().ImageContents();
original_size = image.Size();
SkBitmap image = context_node.To<WebElement>().ImageContents();
original_size = gfx::Size(image.width(), image.height());
thumbnail = Downscale(image,
thumbnail_min_area_pixels,
thumbnail_max_size_pixels);
Expand Down
3 changes: 1 addition & 2 deletions components/plugins/renderer/webview_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ using blink::WebCursorInfo;
using blink::WebDragData;
using blink::WebDragOperationsMask;
using blink::WebFrameWidget;
using blink::WebImage;
using blink::WebLocalFrame;
using blink::WebMouseEvent;
using blink::WebPlugin;
Expand Down Expand Up @@ -299,7 +298,7 @@ void WebViewPlugin::WebViewHelper::SetToolTipText(
void WebViewPlugin::WebViewHelper::StartDragging(blink::WebReferrerPolicy,
const WebDragData&,
WebDragOperationsMask,
const WebImage&,
const SkBitmap&,
const WebPoint&) {
// Immediately stop dragging.
main_frame()->FrameWidget()->DragSourceSystemDragEnded();
Expand Down
2 changes: 1 addition & 1 deletion components/plugins/renderer/webview_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class WebViewPlugin : public blink::WebPlugin,
void StartDragging(blink::WebReferrerPolicy,
const blink::WebDragData&,
blink::WebDragOperationsMask,
const blink::WebImage&,
const SkBitmap&,
const blink::WebPoint&) override;
// TODO(ojan): Remove this override and have this class use a non-null
// layerTreeView.
Expand Down
14 changes: 5 additions & 9 deletions content/child/image_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ ImageDecoder::~ImageDecoder() {
}

SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const {
const WebImage& image = WebImage::FromData(
WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_);
return image.GetSkBitmap();
return WebImage::FromData(WebData(reinterpret_cast<const char*>(data), size),
desired_icon_size_);
}

// static
std::vector<SkBitmap> ImageDecoder::DecodeAll(
const unsigned char* data, size_t size) {
const blink::WebVector<WebImage>& images = WebImage::FramesFromData(
WebData(reinterpret_cast<const char*>(data), size));
std::vector<SkBitmap> result;
for (size_t i = 0; i < images.size(); ++i)
result.push_back(images[i].GetSkBitmap());
return result;
return WebImage::FramesFromData(
WebData(reinterpret_cast<const char*>(data), size))
.ReleaseVector();
}

} // namespace content
2 changes: 1 addition & 1 deletion content/renderer/cursor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void InitializeCursorFromWebCursorInfo(WebCursor* cursor,
cursor_info.type = web_cursor_info.type;
cursor_info.image_scale_factor = web_cursor_info.image_scale_factor;
cursor_info.hotspot = web_cursor_info.hot_spot;
cursor_info.custom_image = web_cursor_info.custom_image.GetSkBitmap();
cursor_info.custom_image = web_cursor_info.custom_image;
cursor->InitFromCursorInfo(cursor_info);
}

Expand Down
2 changes: 1 addition & 1 deletion content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ PP_Bool PepperPluginInstanceImpl::SetCursor(PP_Instance instance,
SkBitmap bitmap(image_data->GetMappedBitmap());
// Make a deep copy, so that the cursor remains valid even after the original
// image data gets freed.
SkBitmap& dst = custom_cursor->custom_image.GetSkBitmap();
SkBitmap& dst = custom_cursor->custom_image;
if (!dst.tryAllocPixels(bitmap.info()) ||
!bitmap.readPixels(dst.info(), dst.getPixels(), dst.rowBytes(), 0, 0)) {
return PP_FALSE;
Expand Down
14 changes: 6 additions & 8 deletions content/renderer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ using blink::WebDragOperationsMask;
using blink::WebDragData;
using blink::WebFrameWidget;
using blink::WebGestureEvent;
using blink::WebImage;
using blink::WebInputEvent;
using blink::WebInputEventResult;
using blink::WebInputMethodController;
Expand Down Expand Up @@ -2912,16 +2911,15 @@ bool RenderWidget::IsPointerLocked() {
void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
const WebDragData& data,
WebDragOperationsMask mask,
const WebImage& image,
const WebPoint& webImageOffset) {
blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
const SkBitmap& drag_image,
const WebPoint& web_image_offset) {
blink::WebRect offset_in_window(web_image_offset.x, web_image_offset.y, 0, 0);
ConvertViewportToWindow(&offset_in_window);
DropData drop_data(DropDataBuilder::Build(data));
drop_data.referrer_policy = policy;
gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
image.GetSkBitmap(), imageOffset,
possible_drag_event_info_));
gfx::Vector2d image_offset(offset_in_window.x, offset_in_window.y);
Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, drag_image,
image_offset, possible_drag_event_info_));
}

uint32_t RenderWidget::GetContentSourceId() {
Expand Down
5 changes: 2 additions & 3 deletions content/renderer/render_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ struct WebDeviceEmulationParams;
class WebDragData;
class WebFrameWidget;
class WebGestureEvent;
class WebImage;
class WebInputMethodController;
class WebLocalFrame;
class WebMouseEvent;
Expand Down Expand Up @@ -333,8 +332,8 @@ class CONTENT_EXPORT RenderWidget
void StartDragging(blink::WebReferrerPolicy policy,
const blink::WebDragData& data,
blink::WebDragOperationsMask mask,
const blink::WebImage& image,
const blink::WebPoint& imageOffset) override;
const SkBitmap& drag_image,
const blink::WebPoint& image_offset) override;

// Override point to obtain that the current input method state and caret
// position.
Expand Down
10 changes: 5 additions & 5 deletions content/shell/test_runner/test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ void TestRunner::Reset() {
top_loading_frame_ = nullptr;
layout_test_runtime_flags_.Reset();
mock_screen_orientation_client_->ResetData();
drag_image_.Reset();
drag_image_.reset();

WebSecurityPolicy::ResetOriginAccessWhitelists();
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_FUCHSIA)
Expand Down Expand Up @@ -1638,7 +1638,7 @@ bool TestRunner::DumpPixelsAsync(
blink::WebLocalFrame* frame,
base::OnceCallback<void(const SkBitmap&)> callback) {
if (layout_test_runtime_flags_.dump_drag_image()) {
if (drag_image_.IsNull()) {
if (drag_image_.isNull()) {
// This means the test called dumpDragImage but did not initiate a drag.
// Return a blank image so that the test fails.
SkBitmap bitmap;
Expand All @@ -1648,7 +1648,7 @@ bool TestRunner::DumpPixelsAsync(
return false;
}

std::move(callback).Run(drag_image_.GetSkBitmap());
std::move(callback).Run(drag_image_);
return false;
}

Expand Down Expand Up @@ -1864,9 +1864,9 @@ void TestRunner::setToolTipText(const WebString& text) {
tooltip_text_ = text.Utf8();
}

void TestRunner::setDragImage(const blink::WebImage& drag_image) {
void TestRunner::setDragImage(const SkBitmap& drag_image) {
if (layout_test_runtime_flags_.dump_drag_image()) {
if (drag_image_.IsNull())
if (drag_image_.isNull())
drag_image_ = drag_image;
}
}
Expand Down
4 changes: 2 additions & 2 deletions content/shell/test_runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestRunner : public WebTestRunner {
bool policyDelegateIsPermissive() const;
bool policyDelegateShouldNotifyDone() const;
void setToolTipText(const blink::WebString&);
void setDragImage(const blink::WebImage& drag_image);
void setDragImage(const SkBitmap& drag_image);
bool shouldDumpNavigationPolicy() const;

midi::mojom::Result midiAccessorResult();
Expand Down Expand Up @@ -584,7 +584,7 @@ class TestRunner : public WebTestRunner {
int chooser_count_;

// Captured drag image.
blink::WebImage drag_image_;
SkBitmap drag_image_;

// View that was focused by a previous call to TestRunner::SetFocus method.
// Note - this can be a dangling pointer to an already destroyed WebView (this
Expand Down
8 changes: 4 additions & 4 deletions content/shell/test_runner/web_view_test_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace blink {
class WebDragData;
class WebImage;
class WebLocalFrame;
class WebString;
class WebView;
Expand Down Expand Up @@ -175,9 +174,10 @@ class WebViewTestProxy : public Base, public WebViewTestProxyBase {
void StartDragging(blink::WebReferrerPolicy policy,
const blink::WebDragData& data,
blink::WebDragOperationsMask mask,
const blink::WebImage& image,
const blink::WebPoint& point) override {
widget_test_client()->StartDragging(policy, data, mask, image, point);
const SkBitmap& drag_image,
const blink::WebPoint& image_offset) override {
widget_test_client()->StartDragging(policy, data, mask, drag_image,
image_offset);
// Don't forward this call to Base because we don't want to do a real
// drag-and-drop.
}
Expand Down
6 changes: 3 additions & 3 deletions content/shell/test_runner/web_widget_test_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void WebWidgetTestClient::SetToolTipText(const blink::WebString& text,
void WebWidgetTestClient::StartDragging(blink::WebReferrerPolicy policy,
const blink::WebDragData& data,
blink::WebDragOperationsMask mask,
const blink::WebImage& image,
const blink::WebPoint& point) {
test_runner()->setDragImage(image);
const SkBitmap& drag_image,
const blink::WebPoint& image_offset) {
test_runner()->setDragImage(drag_image);

// When running a test, we need to fake a drag drop operation otherwise
// Windows waits for real mouse events to know when the drag is over.
Expand Down
4 changes: 2 additions & 2 deletions content/shell/test_runner/web_widget_test_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class WebWidgetTestClient : public blink::WebWidgetClient {
void StartDragging(blink::WebReferrerPolicy policy,
const blink::WebDragData& data,
blink::WebDragOperationsMask mask,
const blink::WebImage& image,
const blink::WebPoint& point) override;
const SkBitmap& drag_image,
const blink::WebPoint& image_offset) override;

private:
void AnimateNow();
Expand Down
7 changes: 4 additions & 3 deletions content/shell/test_runner/web_widget_test_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ class WebWidgetTestProxy : public Base, public WebWidgetTestProxyBase {
void StartDragging(blink::WebReferrerPolicy policy,
const blink::WebDragData& data,
blink::WebDragOperationsMask mask,
const blink::WebImage& image,
const blink::WebPoint& point) override {
widget_test_client()->StartDragging(policy, data, mask, image, point);
const SkBitmap& drag_image,
const blink::WebPoint& image_offset) override {
widget_test_client()->StartDragging(policy, data, mask, drag_image,
image_offset);
// Don't forward this call to Base because we don't want to do a real
// drag-and-drop.
}
Expand Down
7 changes: 3 additions & 4 deletions content/test/image_decoder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ void VerifyImage(const blink::WebImageDecoder& decoder,

// Calculate MD5 sum.
base::MD5Digest actual_digest;
blink::WebImage web_image = decoder.GetFrameAtIndex(frame_index);
base::MD5Sum(web_image.GetSkBitmap().getPixels(),
web_image.GetSkBitmap().width() *
web_image.GetSkBitmap().height() * sizeof(uint32_t),
SkBitmap bitmap = decoder.GetFrameAtIndex(frame_index);
base::MD5Sum(bitmap.getPixels(),
bitmap.width() * bitmap.height() * sizeof(uint32_t),
&actual_digest);

// Read the MD5 sum off disk.
Expand Down
10 changes: 4 additions & 6 deletions services/data_decoder/image_decoder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ void ImageDecoderImpl::DecodeImage(const std::vector<uint8_t>& encoded_data,
}
#endif // defined(OS_CHROMEOS)
if (codec == mojom::ImageCodec::DEFAULT) {
decoded_image =
blink::WebImage::FromData(
blink::WebData(reinterpret_cast<const char*>(encoded_data.data()),
encoded_data.size()),
desired_image_frame_size)
.GetSkBitmap();
decoded_image = blink::WebImage::FromData(
blink::WebData(reinterpret_cast<const char*>(encoded_data.data()),
encoded_data.size()),
desired_image_frame_size);
}

if (!decoded_image.isNull())
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/public/platform/web_cursor_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_CURSOR_INFO_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_CURSOR_INFO_H_

#include "third_party/blink/public/platform/web_image.h"
#include "third_party/blink/public/platform/web_point.h"
#include "third_party/skia/include/core/SkBitmap.h"

#ifdef WIN32
typedef struct HICON__* HICON;
Expand Down Expand Up @@ -97,7 +97,7 @@ struct WebCursorInfo {
Type type;
WebPoint hot_spot;
float image_scale_factor;
WebImage custom_image;
SkBitmap custom_image;

#ifdef WIN32
// On Windows, kTypeCustom may alternatively reference an externally
Expand Down
Loading

0 comments on commit 0c75ad8

Please sign in to comment.