Commit 55c7657c authored by vmpstr's avatar vmpstr Committed by Commit bot

Plumb PaintImage to the PictureImageLayer.

This patch ensures that we pass PaintImage with all of the proper flags
to PictureImageLayer.

R=khushalsagar@chromium.org, pdr@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2835373003
Cr-Commit-Position: refs/heads/master@{#468196}
parent 5ecf11b9
......@@ -22,11 +22,12 @@ blink::WebLayer* WebImageLayerImpl::Layer() {
return layer_.get();
}
void WebImageLayerImpl::SetImage(const SkImage* image) {
static_cast<cc::PictureImageLayer*>(layer_->layer())
->SetImage(sk_ref_sp(image));
void WebImageLayerImpl::SetImage(cc::PaintImage image) {
static_cast<WebLayerImplFixedBounds*>(layer_.get())
->SetFixedBounds(gfx::Size(image->width(), image->height()));
->SetFixedBounds(
gfx::Size(image.sk_image()->width(), image.sk_image()->height()));
static_cast<cc::PictureImageLayer*>(layer_->layer())
->SetImage(std::move(image));
}
void WebImageLayerImpl::SetNearestNeighbor(bool nearest_neighbor) {
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "cc/blink/cc_blink_export.h"
#include "cc/paint/paint_image.h"
#include "third_party/WebKit/public/platform/WebImageLayer.h"
namespace cc_blink {
......@@ -22,7 +23,7 @@ class WebImageLayerImpl : public blink::WebImageLayer {
// blink::WebImageLayer implementation.
blink::WebLayer* Layer() override;
void SetImage(const SkImage* image) override;
void SetImage(cc::PaintImage image) override;
void SetNearestNeighbor(bool nearest_neighbor) override;
private:
......
......@@ -33,15 +33,15 @@ std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
}
bool PictureImageLayer::HasDrawableContent() const {
return image_ && PictureLayer::HasDrawableContent();
return image_.sk_image() && PictureLayer::HasDrawableContent();
}
void PictureImageLayer::SetImage(sk_sp<const SkImage> image) {
void PictureImageLayer::SetImage(PaintImage image) {
// SetImage() currently gets called whenever there is any
// style change that affects the layer even if that change doesn't
// affect the actual contents of the image (e.g. a CSS animation).
// With this check in place we avoid unecessary texture uploads.
if (image_.get() == image.get())
if (image_ == image)
return;
image_ = std::move(image);
......@@ -55,9 +55,9 @@ gfx::Rect PictureImageLayer::PaintableRegion() {
scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
ContentLayerClient::PaintingControlSetting painting_control) {
DCHECK(image_);
DCHECK_GT(image_->width(), 0);
DCHECK_GT(image_->height(), 0);
DCHECK(image_.sk_image());
DCHECK_GT(image_.sk_image()->width(), 0);
DCHECK_GT(image_.sk_image()->height(), 0);
DCHECK(layer_tree_host());
auto display_list = make_scoped_refptr(new DisplayItemList);
......@@ -66,19 +66,16 @@ scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
PaintCanvas* canvas =
recorder.beginRecording(gfx::RectToSkRect(PaintableRegion()));
SkScalar content_to_layer_scale_x =
SkFloatToScalar(static_cast<float>(bounds().width()) / image_->width());
SkScalar content_to_layer_scale_y =
SkFloatToScalar(static_cast<float>(bounds().height()) / image_->height());
SkScalar content_to_layer_scale_x = SkFloatToScalar(
static_cast<float>(bounds().width()) / image_.sk_image()->width());
SkScalar content_to_layer_scale_y = SkFloatToScalar(
static_cast<float>(bounds().height()) / image_.sk_image()->height());
canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
// Because Android WebView resourceless software draw mode rasters directly
// to the root canvas, this draw must use the kSrcOver_Mode so that
// transparent images blend correctly.
// TODO(vmpstr): Plumb animation type and completion states to here.
canvas->drawImage(PaintImage(image_, PaintImage::AnimationType::UNKNOWN,
PaintImage::CompletionState::UNKNOWN),
0, 0);
canvas->drawImage(image_, 0, 0);
display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
PaintableRegion(), recorder.finishRecordingAsPicture());
......
......@@ -11,18 +11,17 @@
#include "cc/cc_export.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/picture_layer.h"
#include "cc/paint/paint_image.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/size.h"
class SkImage;
namespace cc {
class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
public:
static scoped_refptr<PictureImageLayer> Create();
void SetImage(sk_sp<const SkImage> image);
void SetImage(PaintImage image);
// Layer implementation.
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
......@@ -42,7 +41,7 @@ class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
PictureImageLayer();
~PictureImageLayer() override;
sk_sp<const SkImage> image_;
PaintImage image_;
DISALLOW_COPY_AND_ASSIGN(PictureImageLayer);
};
......
......@@ -40,7 +40,7 @@ TEST(PictureImageLayerTest, PaintContentsToDisplayList) {
image_canvas->drawRect(SkRect::MakeWH(100, 100), blue_paint);
image_canvas->drawRect(SkRect::MakeLTRB(100, 100, 200, 200), blue_paint);
layer->SetImage(image_surface->makeImageSnapshot());
layer->SetImage(PaintImage(image_surface->makeImageSnapshot()));
layer->SetBounds(gfx::Size(layer_rect.width(), layer_rect.height()));
scoped_refptr<DisplayItemList> display_list =
......
......@@ -6,12 +6,26 @@
namespace cc {
PaintImage::PaintImage() = default;
PaintImage::PaintImage(sk_sp<const SkImage> sk_image,
AnimationType animation_type,
CompletionState completion_state)
: sk_image_(std::move(sk_image)),
animation_type_(animation_type),
completion_state_(completion_state) {}
completion_state_(completion_state) {
DCHECK(sk_image_);
}
PaintImage::PaintImage(const PaintImage& other) = default;
PaintImage::PaintImage(PaintImage&& other) = default;
PaintImage::~PaintImage() = default;
PaintImage& PaintImage::operator=(const PaintImage& other) = default;
PaintImage& PaintImage::operator=(PaintImage&& other) = default;
bool PaintImage::operator==(const PaintImage& other) {
return sk_image_ == other.sk_image_ &&
animation_type_ == other.animation_type_ &&
completion_state_ == other.completion_state_;
}
} // namespace cc
......@@ -5,8 +5,8 @@
#ifndef CC_PAINT_PAINT_IMAGE_H_
#define CC_PAINT_PAINT_IMAGE_H_
#include "base/logging.h"
#include "cc/paint/paint_export.h"
#include "third_party/skia/include/core/SkImage.h"
namespace cc {
......@@ -20,19 +20,27 @@ class CC_PAINT_EXPORT PaintImage {
// TODO(vmpstr): Work towards removing "UNKNOWN" value.
enum class CompletionState { UNKNOWN, DONE, PARTIALLY_DONE };
PaintImage(sk_sp<const SkImage> sk_image,
AnimationType animation_type,
CompletionState completion_state);
PaintImage();
explicit PaintImage(sk_sp<const SkImage> sk_image,
AnimationType animation_type = AnimationType::STATIC,
CompletionState completion_state = CompletionState::DONE);
PaintImage(const PaintImage& other);
PaintImage(PaintImage&& other);
~PaintImage();
PaintImage& operator=(const PaintImage& other);
PaintImage& operator=(PaintImage&& other);
bool operator==(const PaintImage& other);
const sk_sp<const SkImage>& sk_image() const { return sk_image_; }
AnimationType animation_type() const { return animation_type_; }
CompletionState completion_state() const { return completion_state_; }
private:
sk_sp<const SkImage> sk_image_;
AnimationType animation_type_;
CompletionState completion_state_;
AnimationType animation_type_ = AnimationType::UNKNOWN;
CompletionState completion_state_ = CompletionState::UNKNOWN;
};
} // namespace cc
......
......@@ -71,9 +71,8 @@ FakeContentLayerClient::PaintContentsToDisplayList(
}
PaintCanvas* canvas =
recorder.beginRecording(it->image->width(), it->image->height());
canvas->drawImage(PaintImage(it->image, PaintImage::AnimationType::STATIC,
PaintImage::CompletionState::DONE),
it->point.x(), it->point.y(), &it->flags);
canvas->drawImage(PaintImage(it->image), it->point.x(), it->point.y(),
&it->flags);
display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
PaintableRegion(), recorder.finishRecordingAsPicture());
if (!it->transform.IsIdentity()) {
......
......@@ -6,6 +6,7 @@
#include "cc/layers/picture_image_layer.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/paint/paint_image.h"
#include "cc/test/layer_tree_pixel_resource_test.h"
#include "cc/test/pixel_comparator.h"
#include "third_party/skia/include/core/SkImage.h"
......@@ -145,7 +146,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
scoped_refptr<PictureImageLayer> layer = PictureImageLayer::Create();
layer->SetIsDrawable(true);
layer->SetBounds(gfx::Size(width, height));
layer->SetImage(backing_store->makeImageSnapshot());
layer->SetImage(PaintImage(backing_store->makeImageSnapshot()));
return layer;
}
......@@ -167,7 +168,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
bounds.width() - kMaskOffset * 2,
bounds.height() - kMaskOffset * 2),
paint);
mask->SetImage(surface->makeImageSnapshot());
mask->SetImage(PaintImage(surface->makeImageSnapshot()));
layer->SetMaskLayer(mask.get());
}
......
......@@ -11,6 +11,7 @@
#include "cc/layers/solid_color_layer.h"
#include "cc/paint/drawing_display_item.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_image.h"
#include "cc/paint/paint_recorder.h"
#include "cc/test/layer_tree_pixel_resource_test.h"
#include "cc/test/pixel_comparator.h"
......@@ -109,7 +110,7 @@ TEST_P(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
client.PaintContentsToDisplayList(
ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
mask_display_list->Raster(canvas, nullptr);
mask->SetImage(surface->makeImageSnapshot());
mask->SetImage(PaintImage(surface->makeImageSnapshot()));
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK);
......
......@@ -13,6 +13,7 @@
#include "cc/output/context_provider.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
#include "cc/paint/paint_image.h"
#include "cc/resources/single_release_callback.h"
#include "cc/surfaces/sequence_surface_reference_factory.h"
#include "content/child/thread_safe_sender.h"
......@@ -191,7 +192,7 @@ void ChildFrameCompositingHelper::ChildFrameGone() {
web_layer_->Bounds().height > sad_bitmap->height()) {
scoped_refptr<cc::PictureImageLayer> sad_layer =
cc::PictureImageLayer::Create();
sad_layer->SetImage(SkImage::MakeFromBitmap(*sad_bitmap));
sad_layer->SetImage(cc::PaintImage(SkImage::MakeFromBitmap(*sad_bitmap)));
sad_layer->SetBounds(
gfx::Size(sad_bitmap->width(), sad_bitmap->height()));
sad_layer->SetPosition(gfx::PointF(
......
......@@ -163,10 +163,7 @@ TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) {
PaintRecorder recorder;
PaintCanvas* temp_canvas = recorder.beginRecording(100, 100);
temp_canvas->drawImage(
PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
PaintImage::CompletionState::DONE),
0, 0);
temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0);
sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
EXPECT_EQ(0, decode_request_count_);
......@@ -196,10 +193,7 @@ TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) {
image = lazy_decoder_->CreateFrameAtIndex(0);
ASSERT_TRUE(image);
temp_canvas = recorder.beginRecording(100, 100);
temp_canvas->drawImage(
PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
PaintImage::CompletionState::DONE),
0, 0);
temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0);
canvas_->drawPicture(recorder.finishRecordingAsPicture());
EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0));
}
......@@ -217,10 +211,7 @@ TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) {
PaintRecorder recorder;
PaintCanvas* temp_canvas = recorder.beginRecording(100, 100);
temp_canvas->drawImage(
PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
PaintImage::CompletionState::DONE),
0, 0);
temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0);
sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
EXPECT_EQ(0, decode_request_count_);
......@@ -314,10 +305,7 @@ TEST_F(DeferredImageDecoderTest, decodedSize) {
// The following code should not fail any assert.
PaintRecorder recorder;
PaintCanvas* temp_canvas = recorder.beginRecording(100, 100);
temp_canvas->drawImage(
PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
PaintImage::CompletionState::DONE),
0, 0);
temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0);
sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
EXPECT_EQ(0, decode_request_count_);
canvas_->drawPicture(record);
......
......@@ -1051,7 +1051,19 @@ void GraphicsLayer::SetContentsRect(const IntRect& rect) {
void GraphicsLayer::SetContentsToImage(
Image* image,
RespectImageOrientationEnum respect_image_orientation) {
sk_sp<SkImage> sk_image = image ? image->ImageForCurrentFrame() : nullptr;
sk_sp<SkImage> sk_image;
PaintImage::AnimationType animation_type = PaintImage::AnimationType::UNKNOWN;
PaintImage::CompletionState completion_state =
PaintImage::CompletionState::UNKNOWN;
if (image) {
sk_image = image->ImageForCurrentFrame();
animation_type = image->MaybeAnimated()
? PaintImage::AnimationType::ANIMATED
: PaintImage::AnimationType::STATIC;
completion_state = image->CurrentFrameIsComplete()
? PaintImage::CompletionState::DONE
: PaintImage::CompletionState::PARTIALLY_DONE;
}
if (image && sk_image && image->IsBitmapImage()) {
if (respect_image_orientation == kRespectImageOrientation) {
......@@ -1068,7 +1080,8 @@ void GraphicsLayer::SetContentsToImage(
Platform::Current()->CompositorSupport()->CreateImageLayer();
RegisterContentsLayer(image_layer_->Layer());
}
image_layer_->SetImage(sk_image.get());
image_layer_->SetImage(
PaintImage(std::move(sk_image), animation_type, completion_state));
image_layer_->Layer()->SetOpaque(image->CurrentFrameKnownToBeOpaque());
UpdateContentsRect();
} else {
......
......@@ -29,7 +29,12 @@
#include "WebCommon.h"
#include "WebLayer.h"
class SkImage;
#if INSIDE_BLINK
#include "platform/graphics/paint/PaintImage.h"
#else
#include "cc/paint/paint_image.h"
using PaintImage = cc::PaintImage;
#endif
namespace blink {
......@@ -38,7 +43,7 @@ class WebImageLayer {
virtual ~WebImageLayer() {}
virtual WebLayer* Layer() = 0;
virtual void SetImage(const SkImage*) = 0;
virtual void SetImage(PaintImage) = 0;
virtual void SetNearestNeighbor(bool) = 0;
};
......
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