Skip to content

Commit

Permalink
Revert "Change call-sites now that SkCanvas is not ref-counted"
Browse files Browse the repository at this point in the history
This reverts commit 60c148e.
https://codereview.chromium.org/2476113002/

BUG=666154
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

TBR=esprehn@chromium.org,blundell@chromium.org,ccameron@chromium.org,danakj@chromium.org,fmalita@chromium.org,khushalsagar@chromium.org,raymes@chromium.org,sky@chromium.org,tobiasjs@chromium.org

Review-Url: https://codereview.chromium.org/2509983004
Cr-Commit-Position: refs/heads/master@{#433136}
  • Loading branch information
reed-at-google authored and Commit bot committed Nov 18, 2016
1 parent b302883 commit c5afa23
Show file tree
Hide file tree
Showing 49 changed files with 199 additions and 211 deletions.
10 changes: 5 additions & 5 deletions android_webview/native/java_browser_view_renderer_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "android_webview/public/browser/draw_sw.h"
#include "base/android/scoped_java_ref.h"
#include "base/memory/ptr_util.h"
#include "base/trace_event/trace_event.h"
#include "jni/JavaBrowserViewRendererHelper_jni.h"
#include "third_party/skia/include/core/SkBitmap.h"
Expand Down Expand Up @@ -36,7 +35,7 @@ class JavaCanvasHolder : public SoftwareCanvasHolder {

private:
AwPixelInfo* pixels_;
std::unique_ptr<SkCanvas> canvas_;
sk_sp<SkCanvas> canvas_;
DISALLOW_COPY_AND_ASSIGN(JavaCanvasHolder);
};

Expand All @@ -50,7 +49,8 @@ JavaCanvasHolder::JavaCanvasHolder(JNIEnv* env,
if (!pixels_ || !pixels_->state)
return;

canvas_ = SkCanvasStateUtils::MakeFromCanvasState(pixels_->state);
canvas_ = sk_sp<SkCanvas>(
SkCanvasStateUtils::CreateFromCanvasState(pixels_->state));
// Workarounds for http://crbug.com/271096: SW draw only supports
// translate & scale transforms, and a simple rectangular clip.
if (canvas_ && (!canvas_->isClipRect() ||
Expand Down Expand Up @@ -88,7 +88,7 @@ class AuxiliaryCanvasHolder : public SoftwareCanvasHolder {
ScopedJavaLocalRef<jobject> jbitmap_;
gfx::Vector2d scroll_;
std::unique_ptr<SkBitmap> bitmap_;
std::unique_ptr<SkCanvas> canvas_;
sk_sp<SkCanvas> canvas_;
DISALLOW_COPY_AND_ASSIGN(AuxiliaryCanvasHolder);
};

Expand Down Expand Up @@ -121,7 +121,7 @@ AuxiliaryCanvasHolder::AuxiliaryCanvasHolder(
SkImageInfo::MakeN32Premul(bitmap_info.width, bitmap_info.height);
bitmap_.reset(new SkBitmap);
bitmap_->installPixels(info, pixels, bitmap_info.stride);
canvas_ = base::MakeUnique<SkCanvas>(*bitmap_);
canvas_ = sk_make_sp<SkCanvas>(*bitmap_);
}

AuxiliaryCanvasHolder::~AuxiliaryCanvasHolder() {
Expand Down
3 changes: 2 additions & 1 deletion blimp/test/support/compositor/picture_cache_test_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace blimp {

sk_sp<const SkPicture> CreateSkPicture(SkColor color) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(1, 1));
sk_sp<SkCanvas> canvas =
sk_ref_sp(recorder.beginRecording(SkRect::MakeWH(1, 1)));
canvas->drawColor(color);
return recorder.finishRecordingAsPicture();
}
Expand Down
6 changes: 3 additions & 3 deletions cc/blimp/compositor_state_deserializer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ TEST_F(CompositorStateDeserializerTest, PictureLayer) {

gfx::PointF offset(2.f, 3.f);
SkPictureRecorder recorder;
SkCanvas* canvas;
sk_sp<SkCanvas> canvas;
SkPaint red_paint;
red_paint.setColor(SK_ColorRED);
canvas = recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height()));
canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height())));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
sk_sp<SkPicture> test_picture = recorder.finishRecordingAsPicture();
Expand Down
4 changes: 3 additions & 1 deletion cc/blimp/picture_data_conversions_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace cc {
namespace {
sk_sp<const SkPicture> CreateSkPicture(SkColor color) {
SkPictureRecorder recorder;
recorder.beginRecording(SkRect::MakeWH(1, 1))->drawColor(color);
sk_sp<SkCanvas> canvas =
sk_ref_sp(recorder.beginRecording(SkRect::MakeWH(1, 1)));
canvas->drawColor(color);
return recorder.finishRecordingAsPicture();
}

Expand Down
2 changes: 1 addition & 1 deletion cc/output/software_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool SoftwareRenderer::BindFramebufferToTexture(
base::MakeUnique<ResourceProvider::ScopedWriteLockSoftware>(
resource_provider_, texture->id());
current_framebuffer_canvas_ =
base::MakeUnique<SkCanvas>(current_framebuffer_lock_->sk_bitmap());
sk_make_sp<SkCanvas>(current_framebuffer_lock_->sk_bitmap());
current_canvas_ = current_framebuffer_canvas_.get();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion cc/output/software_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer {
SkPaint current_paint_;
std::unique_ptr<ResourceProvider::ScopedWriteLockSoftware>
current_framebuffer_lock_;
std::unique_ptr<SkCanvas> current_framebuffer_canvas_;
sk_sp<SkCanvas> current_framebuffer_canvas_;

DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer);
};
Expand Down
5 changes: 2 additions & 3 deletions cc/playback/discardable_image_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <limits>

#include "base/containers/adapters.h"
#include "base/memory/ptr_util.h"
#include "cc/base/math_util.h"
#include "cc/playback/display_item_list.h"
#include "third_party/skia/include/utils/SkNWayCanvas.h"
Expand Down Expand Up @@ -198,10 +197,10 @@ DiscardableImageMap::DiscardableImageMap() {}

DiscardableImageMap::~DiscardableImageMap() {}

std::unique_ptr<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata(
sk_sp<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata(
const gfx::Size& bounds) {
DCHECK(all_images_.empty());
return base::MakeUnique<DiscardableImagesMetadataCanvas>(
return sk_make_sp<DiscardableImagesMetadataCanvas>(
bounds.width(), bounds.height(), &all_images_, &image_id_to_region_);
}

Expand Down
4 changes: 2 additions & 2 deletions cc/playback/discardable_image_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CC_EXPORT DiscardableImageMap {

private:
DiscardableImageMap* image_map_;
std::unique_ptr<SkCanvas> metadata_canvas_;
sk_sp<SkCanvas> metadata_canvas_;
};

DiscardableImageMap();
Expand All @@ -57,7 +57,7 @@ class CC_EXPORT DiscardableImageMap {
friend class ScopedMetadataGenerator;
friend class DiscardableImageMapTest;

std::unique_ptr<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds);
sk_sp<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds);
void EndGeneratingMetadata();

std::vector<std::pair<DrawImage, gfx::Rect>> all_images_;
Expand Down
45 changes: 28 additions & 17 deletions cc/playback/display_item_list_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ scoped_refptr<DisplayItemList> CreateDefaultList() {

sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height());
sk_sp<SkCanvas> canvas;

canvas = sk_ref_sp(recorder.beginRecording(bounds.width(), bounds.height()));
canvas->drawRect(
SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
SkPaint());
Expand All @@ -63,12 +65,13 @@ void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list,
const gfx::Size& layer_size) {
gfx::PointF offset(2.f, 3.f);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;

SkPaint red_paint;
red_paint.setColor(SK_ColorRED);

SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height()));
canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height())));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand All @@ -79,12 +82,13 @@ void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list,
const gfx::Size& layer_size) {
gfx::PointF offset(2.f, 2.f);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;

SkPaint blue_paint;
blue_paint.setColor(SK_ColorBLUE);

SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height()));
canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
offset.x(), offset.y(), layer_size.width(), layer_size.height())));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand Down Expand Up @@ -291,6 +295,7 @@ TEST(DisplayItemListTest, SerializeTransformItem) {
TEST(DisplayItemListTest, SingleDrawingItem) {
gfx::Rect layer_rect(100, 100);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;
SkPaint blue_paint;
blue_paint.setColor(SK_ColorBLUE);
SkPaint red_paint;
Expand All @@ -302,8 +307,8 @@ TEST(DisplayItemListTest, SingleDrawingItem) {

gfx::PointF offset(8.f, 9.f);
gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
SkCanvas* canvas =
recorder.beginRecording(gfx::RectFToSkRect(recording_rect));
canvas =
sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
Expand Down Expand Up @@ -332,6 +337,7 @@ TEST(DisplayItemListTest, SingleDrawingItem) {
TEST(DisplayItemListTest, ClipItem) {
gfx::Rect layer_rect(100, 100);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;
SkPaint blue_paint;
blue_paint.setColor(SK_ColorBLUE);
SkPaint red_paint;
Expand All @@ -343,8 +349,8 @@ TEST(DisplayItemListTest, ClipItem) {

gfx::PointF first_offset(8.f, 9.f);
gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
SkCanvas* canvas =
recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
canvas->translate(first_offset.x(), first_offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand All @@ -357,7 +363,8 @@ TEST(DisplayItemListTest, ClipItem) {
gfx::PointF second_offset(2.f, 3.f);
gfx::RectF second_recording_rect(second_offset,
gfx::SizeF(layer_rect.size()));
canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect));
canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
canvas->translate(second_offset.x(), second_offset.y());
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand Down Expand Up @@ -389,6 +396,7 @@ TEST(DisplayItemListTest, ClipItem) {
TEST(DisplayItemListTest, TransformItem) {
gfx::Rect layer_rect(100, 100);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;
SkPaint blue_paint;
blue_paint.setColor(SK_ColorBLUE);
SkPaint red_paint;
Expand All @@ -400,8 +408,8 @@ TEST(DisplayItemListTest, TransformItem) {

gfx::PointF first_offset(8.f, 9.f);
gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
SkCanvas* canvas =
recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
canvas->translate(first_offset.x(), first_offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand All @@ -414,7 +422,8 @@ TEST(DisplayItemListTest, TransformItem) {
gfx::PointF second_offset(2.f, 3.f);
gfx::RectF second_recording_rect(second_offset,
gfx::SizeF(layer_rect.size()));
canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect));
canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
canvas->translate(second_offset.x(), second_offset.y());
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand Down Expand Up @@ -476,12 +485,13 @@ TEST(DisplayItemListTest, FilterItem) {
// Include a rect drawing so that filter is actually applied to something.
{
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;

SkPaint red_paint;
red_paint.setColor(SK_ColorRED);

SkCanvas* canvas = recorder.beginRecording(
SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height()));
canvas = sk_ref_sp(recorder.beginRecording(
SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())));
canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(),
filter_bounds.right(), filter_bounds.bottom(),
red_paint);
Expand Down Expand Up @@ -510,6 +520,7 @@ TEST(DisplayItemListTest, FilterItem) {
TEST(DisplayItemListTest, CompactingItems) {
gfx::Rect layer_rect(100, 100);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;
SkPaint blue_paint;
blue_paint.setColor(SK_ColorBLUE);
SkPaint red_paint;
Expand All @@ -523,8 +534,8 @@ TEST(DisplayItemListTest, CompactingItems) {
scoped_refptr<DisplayItemList> list_without_caching =
DisplayItemList::Create(no_caching_settings);

SkCanvas* canvas =
recorder.beginRecording(gfx::RectFToSkRect(recording_rect));
canvas =
sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
Expand Down
6 changes: 3 additions & 3 deletions cc/raster/gpu_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static sk_sp<SkPicture> PlaybackToPicture(

// Play back raster_source into temp SkPicture.
SkPictureRecorder recorder;
SkCanvas* canvas =
recorder.beginRecording(resource_size.width(), resource_size.height());
sk_sp<SkCanvas> canvas = sk_ref_sp(
recorder.beginRecording(resource_size.width(), resource_size.height()));
canvas->save();

// The GPU image decode controller assumes that Skia is done with an image
Expand All @@ -73,7 +73,7 @@ static sk_sp<SkPicture> PlaybackToPicture(
// later picture rasterization.
RasterSource::PlaybackSettings settings = playback_settings;
settings.use_image_hijack_canvas = false;
raster_source->PlaybackToCanvas(canvas, raster_full_rect, playback_rect,
raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect,
scales, settings);
canvas->restore();
return recorder.finishRecordingAsPicture();
Expand Down
9 changes: 5 additions & 4 deletions cc/test/fake_content_layer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ FakeContentLayerClient::PaintContentsToDisplayList(
DisplayItemList::Create(settings);
display_list->SetRetainVisualRectsForTesting(true);
SkPictureRecorder recorder;
sk_sp<SkCanvas> canvas;

for (RectPaintVector::const_iterator it = draw_rects_.begin();
it != draw_rects_.end(); ++it) {
const gfx::RectF& draw_rect = it->first;
const SkPaint& paint = it->second;
SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(draw_rect));
canvas = sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint);
display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
ToEnclosingRect(draw_rect), recorder.finishRecordingAsPicture());
Expand All @@ -75,8 +76,8 @@ FakeContentLayerClient::PaintContentsToDisplayList(
display_list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(
it->transform);
}
SkCanvas* canvas =
recorder.beginRecording(it->image->width(), it->image->height());
canvas = sk_ref_sp(
recorder.beginRecording(it->image->width(), it->image->height()));
canvas->drawImage(it->image.get(), it->point.x(), it->point.y(),
&it->paint);
display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
Expand All @@ -92,7 +93,7 @@ FakeContentLayerClient::PaintContentsToDisplayList(
while (!draw_rect.IsEmpty()) {
SkPaint paint;
paint.setColor(red ? SK_ColorRED : SK_ColorBLUE);
SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(draw_rect));
canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(draw_rect)));
canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint);
display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
draw_rect, recorder.finishRecordingAsPicture());
Expand Down
3 changes: 2 additions & 1 deletion cc/test/solid_color_content_layer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ SolidColorContentLayerClient::PaintContentsToDisplayList(
PaintingControlSetting painting_control) {
SkPictureRecorder recorder;
gfx::Rect clip(PaintableRegion());
SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip));
sk_sp<SkCanvas> canvas =
sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(clip)));

canvas->clear(SK_ColorTRANSPARENT);

Expand Down
12 changes: 6 additions & 6 deletions cc/trees/layer_tree_host_pixeltest_masks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class MaskContentLayerClient : public ContentLayerClient {
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
SkPictureRecorder recorder;
SkCanvas* canvas =
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)));
sk_sp<SkCanvas> canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));

SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
Expand Down Expand Up @@ -163,8 +163,8 @@ class CheckerContentLayerClient : public ContentLayerClient {
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
SkPictureRecorder recorder;
SkCanvas* canvas =
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)));
sk_sp<SkCanvas> canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));

SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
Expand Down Expand Up @@ -207,8 +207,8 @@ class CircleContentLayerClient : public ContentLayerClient {
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
SkPictureRecorder recorder;
SkCanvas* canvas =
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)));
sk_sp<SkCanvas> canvas = sk_ref_sp(
recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));

SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
Expand Down
Loading

0 comments on commit c5afa23

Please sign in to comment.