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

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
« ui/gfx/canvas.cc ('K') | « ui/gfx/nine_image_painter_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const uint32_t* buffer = static_cast<const uint32_t*>(bitmap.getPixels());
3826 surface->getCanvas()->peekPixels(&pixmap);
3827 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3828 ASSERT_NE(nullptr, buffer); 3828 ASSERT_NE(nullptr, buffer);
3829 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3829 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3830 kCanvasSize.height()); 3830 kCanvasSize.height());
3831 { 3831 {
3832 #if !defined(OS_CHROMEOS) 3832 #if !defined(OS_CHROMEOS)
3833 int top_test_height = kTestSize; 3833 int top_test_height = kTestSize;
3834 #if defined(OS_WIN) 3834 #if defined(OS_WIN)
3835 // Windows 8+ draws 1 pixel above the display rect. 3835 // Windows 8+ draws 1 pixel above the display rect.
3836 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 3836 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
3837 top_test_height = kTestSize - 1; 3837 top_test_height = kTestSize - 1;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3884 } 3884 }
3885 #endif // !defined(OS_WIN) 3885 #endif // !defined(OS_WIN)
3886 3886
3887 // Ensure that the text will clip to the display rect. Draws to a canvas and 3887 // 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. 3888 // checks whether any pixel beyond the bounding rectangle is colored.
3889 TEST_P(RenderTextTest, TextDoesClip) { 3889 TEST_P(RenderTextTest, TextDoesClip) {
3890 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; 3890 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"};
3891 const Size kCanvasSize(300, 50); 3891 const Size kCanvasSize(300, 50);
3892 const int kTestSize = 10; 3892 const int kTestSize = 10;
3893 3893
3894 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( 3894 SkBitmap bitmap;
3895 kCanvasSize.width(), kCanvasSize.height()); 3895 bitmap.allocPixels(
3896 Canvas canvas(surface->getCanvas(), 1.0f); 3896 SkImageInfo::MakeN32Premul(kCanvasSize.width(), kCanvasSize.height()));
3897 cc::SkiaPaintCanvas paint_canvas(bitmap);
3898 Canvas canvas(&paint_canvas, 1.0f);
3897 RenderText* render_text = GetRenderText(); 3899 RenderText* render_text = GetRenderText();
3898 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3900 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3899 render_text->SetColor(SK_ColorBLACK); 3901 render_text->SetColor(SK_ColorBLACK);
3900 3902
3901 for (auto* string : kTestStrings) { 3903 for (auto* string : kTestStrings) {
3902 surface->getCanvas()->clear(SK_ColorWHITE); 3904 paint_canvas.clear(SK_ColorWHITE);
3903 render_text->SetText(WideToUTF16(string)); 3905 render_text->SetText(WideToUTF16(string));
3904 const Size string_size = render_text->GetStringSize(); 3906 const Size string_size = render_text->GetStringSize();
3905 int fake_width = string_size.width() / 2; 3907 int fake_width = string_size.width() / 2;
3906 int fake_height = string_size.height() / 2; 3908 int fake_height = string_size.height() / 2;
3907 render_text->SetDisplayRect( 3909 render_text->SetDisplayRect(
3908 Rect(kTestSize, kTestSize, fake_width, fake_height)); 3910 Rect(kTestSize, kTestSize, fake_width, fake_height));
3909 render_text->set_clip_to_display_rect(true); 3911 render_text->set_clip_to_display_rect(true);
3910 render_text->Draw(&canvas); 3912 render_text->Draw(&canvas);
3911 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); 3913 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width());
3912 SkPixmap pixmap; 3914 const uint32_t* buffer = static_cast<const uint32_t*>(bitmap.getPixels());
3913 surface->getCanvas()->peekPixels(&pixmap);
3914 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3915 ASSERT_NE(nullptr, buffer); 3915 ASSERT_NE(nullptr, buffer);
3916 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3916 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3917 kCanvasSize.height()); 3917 kCanvasSize.height());
3918 { 3918 {
3919 SCOPED_TRACE("TextDoesClip Top Side"); 3919 SCOPED_TRACE("TextDoesClip Top Side");
3920 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), 3920 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(),
3921 kTestSize); 3921 kTestSize);
3922 } 3922 }
3923 3923
3924 { 3924 {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
4423 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4423 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4424 PrintRenderTextBackend()); 4424 PrintRenderTextBackend());
4425 #endif 4425 #endif
4426 4426
4427 INSTANTIATE_TEST_CASE_P(, 4427 INSTANTIATE_TEST_CASE_P(,
4428 RenderTextHarfBuzzTest, 4428 RenderTextHarfBuzzTest,
4429 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4429 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4430 PrintRenderTextBackend()); 4430 PrintRenderTextBackend());
4431 4431
4432 } // namespace gfx 4432 } // namespace gfx
OLDNEW
« ui/gfx/canvas.cc ('K') | « ui/gfx/nine_image_painter_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698