Skip to content

Commit

Permalink
Move skia extensions from the port to skia/ext for Windows only. Fixe…
Browse files Browse the repository at this point in the history
…d the

include guards of the moved files, but nothing else.

Review URL: http://codereview.chromium.org/11568

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5861 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@google.com committed Nov 21, 2008
1 parent bd2e63e commit 156f2c0
Show file tree
Hide file tree
Showing 26 changed files with 1,140 additions and 92 deletions.
2 changes: 1 addition & 1 deletion base/gfx/bitmap_platform_device_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// TODO(brettw) this file should be removed and the includes changed to this
// new location.
#include "webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceWin.h"
#include "skia/ext/bitmap_platform_device_win.h"

#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_

2 changes: 1 addition & 1 deletion base/gfx/platform_canvas_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// TODO(brettw) this file should be removed and the includes changed to this
// new location.
#include "webkit/port/platform/graphics/skia/public/PlatformCanvasWin.h"
#include "skia/ext/platform_canvas_win.h"

#endif // BASE_GFX_PLATFORM_CANVAS_WIN_H_

2 changes: 1 addition & 1 deletion base/gfx/platform_device_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// TODO(brettw) this file should be removed and the includes changed to this
// new location.
#include "webkit/port/platform/graphics/skia/public/PlatformDeviceWin.h"
#include "skia/ext/platform_device_win.h"

#endif // BASE_GFX_PLATFORM_DEVICE_WIN_H__

2 changes: 1 addition & 1 deletion base/gfx/vector_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

// TODO(brettw) this file should be removed and the includes changed to this
// new location.
#include "webkit/port/platform/graphics/skia/public/VectorDevice.h"
#include "skia/ext/vector_device.h"
1 change: 0 additions & 1 deletion chrome/chrome.sln
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui_tests", "test\ui\ui_test
{1832A374-8A74-4F9E-B536-69A699B3E165} = {1832A374-8A74-4F9E-B536-69A699B3E165}
{2A70CBF0-847E-4E3A-B926-542A656DC7FE} = {2A70CBF0-847E-4E3A-B926-542A656DC7FE}
{326E9795-E760-410A-B69A-3F79DB3F5243} = {326E9795-E760-410A-B69A-3F79DB3F5243}
{5597AD47-3494-4750-A235-4F9C2F864700} = {5597AD47-3494-4750-A235-4F9C2F864700}
{5BF908A7-68FB-4A4B-99E3-8C749F1FE4EA} = {5BF908A7-68FB-4A4B-99E3-8C749F1FE4EA}
{7100F41F-868D-4E99-80A2-AF8E6574749D} = {7100F41F-868D-4E99-80A2-AF8E6574749D}
{7B219FAA-E360-43C8-B341-804A94EEFFAC} = {7B219FAA-E360-43C8-B341-804A94EEFFAC}
Expand Down
6 changes: 6 additions & 0 deletions skia/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ if env['PLATFORM'] == 'darwin':
input_files.append('ext/platform_device_mac.cc')

if env['PLATFORM'] == 'win32':
input_files.append('ext/bitmap_platform_device_win.cc')
input_files.append('ext/platform_canvas_win.cc')
input_files.append('ext/platform_device_win.cc')
input_files.append('ext/vector_canvas.cc')
input_files.append('ext/vector_device.cc')

input_files.append('ports/SkThread_win.cpp')

env_p = env.Clone(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "BitmapPlatformDeviceWin.h"
#include "skia/ext/bitmap_platform_device_win.h"

#include "base/gfx/gdi_util.h"
#include "base/logging.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BitmapPlatformDeviceWin_h
#define BitmapPlatformDeviceWin_h
#ifndef SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_
#define SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_

#include "base/gfx/platform_device_win.h"
#include "base/ref_counted.h"
Expand Down Expand Up @@ -107,5 +107,5 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {

} // namespace gfx

#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_
#endif // SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_

296 changes: 296 additions & 0 deletions skia/ext/platform_canvas_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(awalker): clean up the const/non-const reference handling in this test

#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#else
#include <unistd.h>
#endif

#include "base/gfx/platform_canvas.h"
#include "base/gfx/platform_device.h"
#include "testing/gtest/include/gtest/gtest.h"

#include "SkColor.h"

namespace gfx {

namespace {

// Return true if the canvas is filled to canvas_color,
// and contains a single rectangle filled to rect_color.
bool VerifyRect(const PlatformCanvas& canvas,
uint32_t canvas_color, uint32_t rect_color,
int x, int y, int w, int h) {
PlatformDevice& device = canvas.getTopPlatformDevice();
const SkBitmap& bitmap = device.accessBitmap(false);
SkAutoLockPixels lock(bitmap);

for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) {
for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) {
if (cur_x >= x && cur_x < x + w &&
cur_y >= y && cur_y < y + h) {
// Inside the square should be rect_color
if (*bitmap.getAddr32(cur_x, cur_y) != rect_color)
return false;
} else {
// Outside the square should be canvas_color
if (*bitmap.getAddr32(cur_x, cur_y) != canvas_color)
return false;
}
}
}
return true;
}

// Checks whether there is a white canvas with a black square at the given
// location in pixels (not in the canvas coordinate system).
// TODO(ericroman): rename Square to Rect
bool VerifyBlackSquare(const PlatformCanvas& canvas, int x, int y, int w, int h) {
return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h);
}

// Check that every pixel in the canvas is a single color.
bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) {
return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0);
}

#if defined(OS_WIN)
void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
HDC dc = canvas.beginPlatformPaint();

RECT inner_rc;
inner_rc.left = x;
inner_rc.top = y;
inner_rc.right = x + w;
inner_rc.bottom = y + h;
FillRect(dc, &inner_rc, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));

canvas.endPlatformPaint();
}
#elif defined(OS_MACOSX)
void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
CGContextRef context = canvas.beginPlatformPaint();

CGRect inner_rc = CGRectMake(x, y, w, h);
// RGBA opaque black
CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0);
CGContextSetFillColorWithColor(context, black);
CGColorRelease(black);
CGContextFillRect(context, inner_rc);

canvas.endPlatformPaint();
}
#else
void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
NOTIMPLEMENTED();
}
#endif

// Clips the contents of the canvas to the given rectangle. This will be
// intersected with any existing clip.
void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) {
SkRect rect;
rect.set(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(x + w), SkIntToScalar(y + h));
canvas.clipRect(rect);
}

class LayerSaver {
public:
LayerSaver(PlatformCanvas& canvas, int x, int y, int w, int h)
: canvas_(canvas),
x_(x),
y_(y),
w_(w),
h_(h) {
SkRect bounds;
bounds.set(SkIntToScalar(x_), SkIntToScalar(y_),
SkIntToScalar(right()), SkIntToScalar(bottom()));
canvas_.saveLayer(&bounds, NULL);
}

~LayerSaver() {
canvas_.getTopPlatformDevice().fixupAlphaBeforeCompositing();
canvas_.restore();
}

int x() const { return x_; }
int y() const { return y_; }
int w() const { return w_; }
int h() const { return h_; }

// Returns the EXCLUSIVE far bounds of the layer.
int right() const { return x_ + w_; }
int bottom() const { return y_ + h_; }

private:
PlatformCanvas& canvas_;
int x_, y_, w_, h_;
};

// Size used for making layers in many of the below tests.
const int kLayerX = 2;
const int kLayerY = 3;
const int kLayerW = 9;
const int kLayerH = 7;

// Size used by some tests to draw a rectangle inside the layer.
const int kInnerX = 4;
const int kInnerY = 5;
const int kInnerW = 2;
const int kInnerH = 3;

}

// This just checks that our checking code is working properly, it just uses
// regular skia primitives.
TEST(PlatformCanvas, SkLayer) {
// Create the canvas initialized to opaque white.
PlatformCanvas canvas(16, 16, true);
canvas.drawColor(SK_ColorWHITE);

// Make a layer and fill it completely to make sure that the bounds are
// correct.
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
canvas.drawColor(SK_ColorBLACK);
}
EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
}

// Test native clipping.
TEST(PlatformCanvas, ClipRegion) {
// Initialize a white canvas
PlatformCanvas canvas(16, 16, true);
canvas.drawColor(SK_ColorWHITE);
EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));

// Test that initially the canvas has no clip region, by filling it
// with a black rectangle.
// Note: Don't use LayerSaver, since internally it sets a clip region.
DrawNativeRect(canvas, 0, 0, 16, 16);
canvas.getTopPlatformDevice().fixupAlphaBeforeCompositing();
EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorBLACK));

// Test that intersecting disjoint clip rectangles sets an empty clip region
canvas.drawColor(SK_ColorWHITE);
EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
{
LayerSaver layer(canvas, 0, 0, 16, 16);
AddClip(canvas, 2, 3, 4, 5);
AddClip(canvas, 4, 9, 10, 10);
DrawNativeRect(canvas, 0, 0, 16, 16);
}
EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
}

// Test the layers get filled properly by native rendering.
TEST(PlatformCanvas, FillLayer) {
// Create the canvas initialized to opaque white.
PlatformCanvas canvas(16, 16, true);

// Make a layer and fill it completely to make sure that the bounds are
// correct.
canvas.drawColor(SK_ColorWHITE);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
}
EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH));

// Make a layer and fill it partially to make sure the translation is correct.
canvas.drawColor(SK_ColorWHITE);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
}
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));

// Add a clip on the layer and fill to make sure clip is correct.
canvas.drawColor(SK_ColorWHITE);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
canvas.save();
AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
canvas.restore();
}
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));

// Add a clip and then make the layer to make sure the clip is correct.
canvas.drawColor(SK_ColorWHITE);
canvas.save();
AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
}
canvas.restore();
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
}

// Test that translation + make layer works properly.
TEST(PlatformCanvas, TranslateLayer) {
// Create the canvas initialized to opaque white.
PlatformCanvas canvas(16, 16, true);

// Make a layer and fill it completely to make sure that the bounds are
// correct.
canvas.drawColor(SK_ColorWHITE);
canvas.save();
canvas.translate(1, 1);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
}
canvas.restore();
EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX + 1, kLayerY + 1,
kLayerW, kLayerH));

// Translate then make the layer.
canvas.drawColor(SK_ColorWHITE);
canvas.save();
canvas.translate(1, 1);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
}
canvas.restore();
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1,
kInnerW, kInnerH));

// Make the layer then translate.
canvas.drawColor(SK_ColorWHITE);
canvas.save();
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
canvas.translate(1, 1);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
}
canvas.restore();
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1,
kInnerW, kInnerH));

// Translate both before and after, and have a clip.
canvas.drawColor(SK_ColorWHITE);
canvas.save();
canvas.translate(1, 1);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
canvas.translate(1, 1);
AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
}
canvas.restore();
EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 2, kInnerY + 2,
kInnerW, kInnerH));
}

} // namespace

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "PlatformCanvasWin.h"

#include "BitmapPlatformDeviceWin.h"
#include "skia/ext/platform_canvas_win.h"

#include "base/logging.h"
#include "base/process_util.h"
#include "skia/ext/bitmap_platform_device_win.h"

namespace gfx {

Expand Down
Loading

0 comments on commit 156f2c0

Please sign in to comment.