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

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

Issue 2758413002: cc/paint: Remove PaintCanvas::peekPixels. (Closed)
Patch Set: canvas 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.h ('K') | « ui/gfx/canvas_paint_mac.mm ('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 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after
3752 L"TEST some stuff", 3752 L"TEST some stuff",
3753 L"WWWWWWWWWW", 3753 L"WWWWWWWWWW",
3754 L"gAXAXAXAXAXAXA", 3754 L"gAXAXAXAXAXAXA",
3755 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. 3755 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812.
3756 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", 3756 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5",
3757 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" 3757 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D"
3758 L"\x0628\x0627"}; 3758 L"\x0628\x0627"};
3759 const Size kCanvasSize(300, 50); 3759 const Size kCanvasSize(300, 50);
3760 const int kTestSize = 10; 3760 const int kTestSize = 10;
3761 3761
3762 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( 3762 SkBitmap bitmap;
3763 kCanvasSize.width(), kCanvasSize.height()); 3763 bitmap.allocPixels(
3764 Canvas canvas(surface->getCanvas(), 1.0f); 3764 SkImageInfo::MakeN32Premul(kCanvasSize.width(), kCanvasSize.height()));
3765 cc::SkiaPaintCanvas paint_canvas(bitmap);
3766 Canvas canvas(&paint_canvas, 1.0f);
3765 RenderText* render_text = GetRenderText(); 3767 RenderText* render_text = GetRenderText();
3766 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3768 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3767 render_text->SetColor(SK_ColorBLACK); 3769 render_text->SetColor(SK_ColorBLACK);
3768 3770
3769 for (auto* string : kTestStrings) { 3771 for (auto* string : kTestStrings) {
3770 surface->getCanvas()->clear(SK_ColorWHITE); 3772 paint_canvas.clear(SK_ColorWHITE);
3771 render_text->SetText(WideToUTF16(string)); 3773 render_text->SetText(WideToUTF16(string));
3772 const Size string_size = render_text->GetStringSize(); 3774 const Size string_size = render_text->GetStringSize();
3773 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); 3775 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
3774 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); 3776 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4));
3775 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); 3777 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6));
3776 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8)); 3778 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8));
3777 render_text->SetWeight(Font::Weight::BOLD); 3779 render_text->SetWeight(Font::Weight::BOLD);
3778 render_text->SetDisplayRect( 3780 render_text->SetDisplayRect(
3779 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); 3781 Rect(kTestSize, kTestSize, string_size.width(), string_size.height()));
3780 // Allow the RenderText to paint outside of its display rect. 3782 // Allow the RenderText to paint outside of its display rect.
3781 render_text->set_clip_to_display_rect(false); 3783 render_text->set_clip_to_display_rect(false);
3782 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); 3784 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width());
3783 3785
3784 render_text->Draw(&canvas); 3786 render_text->Draw(&canvas);
3785 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); 3787 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width());
3786 SkPixmap pixmap; 3788 SkPixmap pixmap;
3787 surface->getCanvas()->peekPixels(&pixmap); 3789 bitmap.peekPixels(&pixmap);
3788 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); 3790 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3789 ASSERT_NE(nullptr, buffer); 3791 ASSERT_NE(nullptr, buffer);
3790 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3792 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3791 kCanvasSize.height()); 3793 kCanvasSize.height());
3792 { 3794 {
3793 #if !defined(OS_CHROMEOS) 3795 #if !defined(OS_CHROMEOS)
3794 int top_test_height = kTestSize; 3796 int top_test_height = kTestSize;
3795 #if defined(OS_WIN) 3797 #if defined(OS_WIN)
3796 // Windows 8+ draws 1 pixel above the display rect. 3798 // Windows 8+ draws 1 pixel above the display rect.
3797 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 3799 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3845 } 3847 }
3846 #endif // !defined(OS_WIN) 3848 #endif // !defined(OS_WIN)
3847 3849
3848 // Ensure that the text will clip to the display rect. Draws to a canvas and 3850 // Ensure that the text will clip to the display rect. Draws to a canvas and
3849 // checks whether any pixel beyond the bounding rectangle is colored. 3851 // checks whether any pixel beyond the bounding rectangle is colored.
3850 TEST_P(RenderTextTest, TextDoesClip) { 3852 TEST_P(RenderTextTest, TextDoesClip) {
3851 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; 3853 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"};
3852 const Size kCanvasSize(300, 50); 3854 const Size kCanvasSize(300, 50);
3853 const int kTestSize = 10; 3855 const int kTestSize = 10;
3854 3856
3855 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( 3857 SkBitmap bitmap;
3856 kCanvasSize.width(), kCanvasSize.height()); 3858 bitmap.allocPixels(
3857 Canvas canvas(surface->getCanvas(), 1.0f); 3859 SkImageInfo::MakeN32Premul(kCanvasSize.width(), kCanvasSize.height()));
3860 cc::SkiaPaintCanvas paint_canvas(bitmap);
3861 Canvas canvas(&paint_canvas, 1.0f);
3858 RenderText* render_text = GetRenderText(); 3862 RenderText* render_text = GetRenderText();
3859 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3863 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3860 render_text->SetColor(SK_ColorBLACK); 3864 render_text->SetColor(SK_ColorBLACK);
3861 3865
3862 for (auto* string : kTestStrings) { 3866 for (auto* string : kTestStrings) {
3863 surface->getCanvas()->clear(SK_ColorWHITE); 3867 paint_canvas.clear(SK_ColorWHITE);
3864 render_text->SetText(WideToUTF16(string)); 3868 render_text->SetText(WideToUTF16(string));
3865 const Size string_size = render_text->GetStringSize(); 3869 const Size string_size = render_text->GetStringSize();
3866 int fake_width = string_size.width() / 2; 3870 int fake_width = string_size.width() / 2;
3867 int fake_height = string_size.height() / 2; 3871 int fake_height = string_size.height() / 2;
3868 render_text->SetDisplayRect( 3872 render_text->SetDisplayRect(
3869 Rect(kTestSize, kTestSize, fake_width, fake_height)); 3873 Rect(kTestSize, kTestSize, fake_width, fake_height));
3870 render_text->set_clip_to_display_rect(true); 3874 render_text->set_clip_to_display_rect(true);
3871 render_text->Draw(&canvas); 3875 render_text->Draw(&canvas);
3872 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); 3876 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width());
3873 SkPixmap pixmap; 3877 SkPixmap pixmap;
3874 surface->getCanvas()->peekPixels(&pixmap); 3878 bitmap.peekPixels(&pixmap);
3875 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); 3879 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr());
3876 ASSERT_NE(nullptr, buffer); 3880 ASSERT_NE(nullptr, buffer);
3877 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 3881 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
3878 kCanvasSize.height()); 3882 kCanvasSize.height());
3879 { 3883 {
3880 SCOPED_TRACE("TextDoesClip Top Side"); 3884 SCOPED_TRACE("TextDoesClip Top Side");
3881 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), 3885 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(),
3882 kTestSize); 3886 kTestSize);
3883 } 3887 }
3884 3888
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
4384 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4388 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4385 PrintRenderTextBackend()); 4389 PrintRenderTextBackend());
4386 #endif 4390 #endif
4387 4391
4388 INSTANTIATE_TEST_CASE_P(, 4392 INSTANTIATE_TEST_CASE_P(,
4389 RenderTextHarfBuzzTest, 4393 RenderTextHarfBuzzTest,
4390 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4394 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4391 PrintRenderTextBackend()); 4395 PrintRenderTextBackend());
4392 4396
4393 } // namespace gfx 4397 } // namespace gfx
OLDNEW
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas_paint_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698