Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: cc/playback/display_list_raster_source_unittest.cc

Issue 1673193002: HBitmap can't be immutable Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "cc/playback/display_list_raster_source.h" 8 #include "cc/playback/display_list_raster_source.h"
9 #include "cc/test/fake_display_list_recording_source.h" 9 #include "cc/test/fake_display_list_recording_source.h"
10 #include "cc/test/skia_common.h" 10 #include "cc/test/skia_common.h"
11 #include "skia/ext/platform_canvas.h"
11 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkPixelRef.h" 14 #include "third_party/skia/include/core/SkPixelRef.h"
14 #include "third_party/skia/include/core/SkShader.h" 15 #include "third_party/skia/include/core/SkShader.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size_conversions.h" 17 #include "ui/gfx/geometry/size_conversions.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 recording_source->Rerecord(); 538 recording_source->Rerecord();
538 539
539 scoped_refptr<DisplayListRasterSource> raster = 540 scoped_refptr<DisplayListRasterSource> raster =
540 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 541 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
541 recording_source.get(), false); 542 recording_source.get(), false);
542 size_t total_memory_usage = raster->GetPictureMemoryUsage(); 543 size_t total_memory_usage = raster->GetPictureMemoryUsage();
543 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); 544 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes);
544 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); 545 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
545 } 546 }
546 547
548 class BadPainter : public FakeOnPaintDelegate {
549 public:
550 BadPainter() {}
551 void OnPaint(SkCanvas* canvas,
552 const gfx::Rect& invalidation) override {
553 skia::RefPtr<SkCanvas> temp_canvas =
554 skia::AdoptRef(
555 skia::CreatePlatformCanvas(invalidation.width(),
556 invalidation.height(),
557 false));
558 SkPaint bkgnd_paint;
559 bkgnd_paint.setColor(SK_ColorBLACK);
560 SkRect rect = gfx::RectToSkRect(invalidation);
561 temp_canvas->drawRect(rect, bkgnd_paint);
562 SkPixmap pixmap;
563 skia::GetWritablePixels(temp_canvas.get(), &pixmap);
564
565 bool is_odd = false;
566 for (int cur_y = 0; cur_y < pixmap.height(); cur_y++) {
567 uint32_t* text_row = pixmap.writable_addr32(0, cur_y);
568 for (int cur_x = 0; cur_x < pixmap.width(); cur_x++) {
569 if (is_odd)
570 text_row[cur_x] = SK_ColorRED;
571 is_odd = !is_odd;
572 }
573 }
574
575 SkBitmap bitmap;
576 bitmap.installPixels(pixmap.info(),
577 pixmap.writable_addr(),
578 pixmap.rowBytes());
579 // HBitmap can't be immutable!
580 // bitmap.setImmutable();
581 canvas->drawBitmap(bitmap, 0, 0);
582 }
583 };
584
585 TEST(DisplayListRasterSourceTest, TemporaryBitmapRaster) {
586 gfx::Size layer_bounds(10, 10);
587
588 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
589 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
590 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
591 recording_source->SetRequiresClear(true);
592 recording_source->SetClearCanvasWithDebugColor(false);
593 recording_source->set_on_paint_delegate(make_scoped_ptr(new BadPainter));
594 recording_source->Rerecord();
595
596 scoped_refptr<DisplayListRasterSource> raster =
597 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
598 recording_source.get(), false);
599
600 SkBitmap bitmap;
601 bitmap.allocN32Pixels(layer_bounds.width(), layer_bounds.height());
602 SkCanvas canvas(bitmap);
603
604 gfx::Rect canvas_rect(layer_bounds);
605 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, 1.0f);
606
607 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
608 int num_pixels = bitmap.width() * bitmap.height();
609 for (int i = 0; i < num_pixels; ++i) {
610 if (i % 2 == 0)
611 EXPECT_EQ(SK_ColorBLACK, pixels[i]);
612 else
613 EXPECT_EQ(SK_ColorRED, pixels[i]);
614 }
615 }
616
547 } // namespace 617 } // namespace
548 } // namespace cc 618 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698