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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 2758413002: cc/paint: Remove PaintCanvas::peekPixels. (Closed)
Patch Set: update Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 3780 matching lines...) Expand 10 before | Expand all | Expand 10 after
3791 L"TEST some stuff", 3791 L"TEST some stuff",
3792 L"WWWWWWWWWW", 3792 L"WWWWWWWWWW",
3793 L"gAXAXAXAXAXAXA", 3793 L"gAXAXAXAXAXAXA",
3794 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. 3794 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812.
3795 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", 3795 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5",
3796 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" 3796 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D"
3797 L"\x0628\x0627"}; 3797 L"\x0628\x0627"};
3798 const Size kCanvasSize(300, 50); 3798 const Size kCanvasSize(300, 50);
3799 const int kTestSize = 10; 3799 const int kTestSize = 10;
3800 3800
3801 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( 3801 SkBitmap bitmap;
3802 kCanvasSize.width(), kCanvasSize.height()); 3802 bitmap.allocPixels(
3803 Canvas canvas(surface->getCanvas(), 1.0f); 3803 SkImageInfo::MakeN32Premul(kCanvasSize.width(), kCanvasSize.height()));
3804 cc::SkiaPaintCanvas paint_canvas(bitmap);
3805 Canvas canvas(&paint_canvas, 1.0f);
3804 RenderText* render_text = GetRenderText(); 3806 RenderText* render_text = GetRenderText();
3805 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3807 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3806 render_text->SetColor(SK_ColorBLACK); 3808 render_text->SetColor(SK_ColorBLACK);
3807 3809
3808 for (auto* string : kTestStrings) { 3810 for (auto* string : kTestStrings) {
3809 surface->getCanvas()->clear(SK_ColorWHITE); 3811 paint_canvas.clear(SK_ColorWHITE);
3810 render_text->SetText(WideToUTF16(string)); 3812 render_text->SetText(WideToUTF16(string));
3811 const Size string_size = render_text->GetStringSize(); 3813 const Size string_size = render_text->GetStringSize();
3812 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); 3814 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
3813 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); 3815 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4));
3814 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); 3816 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6));
3815 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8)); 3817 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8));
3816 render_text->SetWeight(Font::Weight::BOLD); 3818 render_text->SetWeight(Font::Weight::BOLD);
3817 render_text->SetDisplayRect( 3819 render_text->SetDisplayRect(
3818 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); 3820 Rect(kTestSize, kTestSize, string_size.width(), string_size.height()));
3819 // Allow the RenderText to paint outside of its display rect. 3821 // Allow the RenderText to paint outside of its display rect.
3820 render_text->set_clip_to_display_rect(false); 3822 render_text->set_clip_to_display_rect(false);
3821 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); 3823 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width());
3822 3824
3823 render_text->Draw(&canvas); 3825 render_text->Draw(&canvas);
3824 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); 3826 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width());
3825 SkPixmap pixmap; 3827 SkPixmap pixmap;
3826 surface->getCanvas()->peekPixels(&pixmap); 3828 bitmap.peekPixels(&pixmap);
danakj 2017/03/21 20:02:57 this could just use the bitmap directly instead of
vmpstr 2017/03/21 22:34:54 Done.
3827 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); 3829 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3828 ASSERT_NE(nullptr, buffer); 3830 ASSERT_NE(nullptr, buffer);
3829 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3831 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3830 kCanvasSize.height()); 3832 kCanvasSize.height());
3831 { 3833 {
3832 #if !defined(OS_CHROMEOS) 3834 #if !defined(OS_CHROMEOS)
3833 int top_test_height = kTestSize; 3835 int top_test_height = kTestSize;
3834 #if defined(OS_WIN) 3836 #if defined(OS_WIN)
3835 // Windows 8+ draws 1 pixel above the display rect. 3837 // Windows 8+ draws 1 pixel above the display rect.
3836 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 3838 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3884 } 3886 }
3885 #endif // !defined(OS_WIN) 3887 #endif // !defined(OS_WIN)
3886 3888
3887 // Ensure that the text will clip to the display rect. Draws to a canvas and 3889 // Ensure that the text will clip to the display rect. Draws to a canvas and
3888 // checks whether any pixel beyond the bounding rectangle is colored. 3890 // checks whether any pixel beyond the bounding rectangle is colored.
3889 TEST_P(RenderTextTest, TextDoesClip) { 3891 TEST_P(RenderTextTest, TextDoesClip) {
3890 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; 3892 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"};
3891 const Size kCanvasSize(300, 50); 3893 const Size kCanvasSize(300, 50);
3892 const int kTestSize = 10; 3894 const int kTestSize = 10;
3893 3895
3894 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( 3896 SkBitmap bitmap;
3895 kCanvasSize.width(), kCanvasSize.height()); 3897 bitmap.allocPixels(
3896 Canvas canvas(surface->getCanvas(), 1.0f); 3898 SkImageInfo::MakeN32Premul(kCanvasSize.width(), kCanvasSize.height()));
3899 cc::SkiaPaintCanvas paint_canvas(bitmap);
3900 Canvas canvas(&paint_canvas, 1.0f);
3897 RenderText* render_text = GetRenderText(); 3901 RenderText* render_text = GetRenderText();
3898 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3902 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3899 render_text->SetColor(SK_ColorBLACK); 3903 render_text->SetColor(SK_ColorBLACK);
3900 3904
3901 for (auto* string : kTestStrings) { 3905 for (auto* string : kTestStrings) {
3902 surface->getCanvas()->clear(SK_ColorWHITE); 3906 paint_canvas.clear(SK_ColorWHITE);
3903 render_text->SetText(WideToUTF16(string)); 3907 render_text->SetText(WideToUTF16(string));
3904 const Size string_size = render_text->GetStringSize(); 3908 const Size string_size = render_text->GetStringSize();
3905 int fake_width = string_size.width() / 2; 3909 int fake_width = string_size.width() / 2;
3906 int fake_height = string_size.height() / 2; 3910 int fake_height = string_size.height() / 2;
3907 render_text->SetDisplayRect( 3911 render_text->SetDisplayRect(
3908 Rect(kTestSize, kTestSize, fake_width, fake_height)); 3912 Rect(kTestSize, kTestSize, fake_width, fake_height));
3909 render_text->set_clip_to_display_rect(true); 3913 render_text->set_clip_to_display_rect(true);
3910 render_text->Draw(&canvas); 3914 render_text->Draw(&canvas);
3911 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); 3915 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width());
3912 SkPixmap pixmap; 3916 SkPixmap pixmap;
3913 surface->getCanvas()->peekPixels(&pixmap); 3917 bitmap.peekPixels(&pixmap);
danakj 2017/03/21 20:02:57 same
vmpstr 2017/03/21 22:34:54 Done.
3914 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); 3918 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3915 ASSERT_NE(nullptr, buffer); 3919 ASSERT_NE(nullptr, buffer);
3916 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3920 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3917 kCanvasSize.height()); 3921 kCanvasSize.height());
3918 { 3922 {
3919 SCOPED_TRACE("TextDoesClip Top Side"); 3923 SCOPED_TRACE("TextDoesClip Top Side");
3920 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), 3924 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(),
3921 kTestSize); 3925 kTestSize);
3922 } 3926 }
3923 3927
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
4423 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4427 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4424 PrintRenderTextBackend()); 4428 PrintRenderTextBackend());
4425 #endif 4429 #endif
4426 4430
4427 INSTANTIATE_TEST_CASE_P(, 4431 INSTANTIATE_TEST_CASE_P(,
4428 RenderTextHarfBuzzTest, 4432 RenderTextHarfBuzzTest,
4429 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4433 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4430 PrintRenderTextBackend()); 4434 PrintRenderTextBackend());
4431 4435
4432 } // namespace gfx 4436 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698