Wow, it's been a while since we cleaned EOL.
Ran dos2unix on *.cc, *.h, *.py and SCons*.* Ran for /R /D %a in (*.*) do @if exist %a\.svn\. svn pset svn:eol-style LF %a\*.cc Ran for /R /D %a in (*.*) do @if exist %a\.svn\. svn pset svn:eol-style LF %a\*.h Ran for /R /D %a in (*.*) do @if exist %a\.svn\. svn pset svn:eol-style LF %a\*.py Ran for /R /D %a in (*.*) do @if exist %a\.svn\. svn pset svn:eol-style LF %a\SCons*.* git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2611 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
104
base/cpu.cc
104
base/cpu.cc
@@ -1,52 +1,52 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "base/cpu.h"
|
#include "base/cpu.h"
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
CPU::CPU()
|
CPU::CPU()
|
||||||
: type_(0),
|
: type_(0),
|
||||||
family_(0),
|
family_(0),
|
||||||
model_(0),
|
model_(0),
|
||||||
stepping_(0),
|
stepping_(0),
|
||||||
ext_model_(0),
|
ext_model_(0),
|
||||||
ext_family_(0),
|
ext_family_(0),
|
||||||
cpu_vendor_("unknown") {
|
cpu_vendor_("unknown") {
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::Initialize() {
|
void CPU::Initialize() {
|
||||||
int cpu_info[4] = {-1};
|
int cpu_info[4] = {-1};
|
||||||
char cpu_string[0x20];
|
char cpu_string[0x20];
|
||||||
|
|
||||||
// __cpuid with an InfoType argument of 0 returns the number of
|
// __cpuid with an InfoType argument of 0 returns the number of
|
||||||
// valid Ids in CPUInfo[0] and the CPU identification string in
|
// valid Ids in CPUInfo[0] and the CPU identification string in
|
||||||
// the other three array elements. The CPU identification string is
|
// the other three array elements. The CPU identification string is
|
||||||
// not in linear order. The code below arranges the information
|
// not in linear order. The code below arranges the information
|
||||||
// in a human readable form.
|
// in a human readable form.
|
||||||
//
|
//
|
||||||
// More info can be found here:
|
// More info can be found here:
|
||||||
// http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
|
// http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
|
||||||
__cpuid(cpu_info, 0);
|
__cpuid(cpu_info, 0);
|
||||||
int num_ids = cpu_info[0];
|
int num_ids = cpu_info[0];
|
||||||
memset(cpu_string, 0, sizeof(cpu_string));
|
memset(cpu_string, 0, sizeof(cpu_string));
|
||||||
*(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
|
*(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
|
||||||
*(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
|
*(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
|
||||||
*(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
|
*(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
|
||||||
|
|
||||||
// Interpret CPU feature information.
|
// Interpret CPU feature information.
|
||||||
__cpuid(cpu_info, 1);
|
__cpuid(cpu_info, 1);
|
||||||
stepping_ = cpu_info[0] & 0xf;
|
stepping_ = cpu_info[0] & 0xf;
|
||||||
model_ = (cpu_info[0] >> 4) & 0xf;
|
model_ = (cpu_info[0] >> 4) & 0xf;
|
||||||
family_ = (cpu_info[0] >> 8) & 0xf;
|
family_ = (cpu_info[0] >> 8) & 0xf;
|
||||||
type_ = (cpu_info[0] >> 12) & 0x3;
|
type_ = (cpu_info[0] >> 12) & 0x3;
|
||||||
ext_model_ = (cpu_info[0] >> 16) & 0xf;
|
ext_model_ = (cpu_info[0] >> 16) & 0xf;
|
||||||
ext_family_ = (cpu_info[0] >> 20) & 0xff;
|
ext_family_ = (cpu_info[0] >> 20) & 0xff;
|
||||||
cpu_vendor_ = cpu_string;
|
cpu_vendor_ = cpu_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
84
base/cpu.h
84
base/cpu.h
@@ -1,42 +1,42 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef BASE_CPU_H_
|
#ifndef BASE_CPU_H_
|
||||||
#define BASE_CPU_H_
|
#define BASE_CPU_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
// Query information about the processor.
|
// Query information about the processor.
|
||||||
class CPU {
|
class CPU {
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
CPU();
|
CPU();
|
||||||
|
|
||||||
// Accessors for CPU information.
|
// Accessors for CPU information.
|
||||||
const std::string& vendor_name() const { return cpu_vendor_; }
|
const std::string& vendor_name() const { return cpu_vendor_; }
|
||||||
int stepping() const { return stepping_; }
|
int stepping() const { return stepping_; }
|
||||||
int model() const { return model_; }
|
int model() const { return model_; }
|
||||||
int family() const { return family_; }
|
int family() const { return family_; }
|
||||||
int type() const { return type_; }
|
int type() const { return type_; }
|
||||||
int extended_model() const { return ext_model_; }
|
int extended_model() const { return ext_model_; }
|
||||||
int extended_family() const { return ext_family_; }
|
int extended_family() const { return ext_family_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Query the processor for CPUID information.
|
// Query the processor for CPUID information.
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
int type_; // process type
|
int type_; // process type
|
||||||
int family_; // family of the processor
|
int family_; // family of the processor
|
||||||
int model_; // model of processor
|
int model_; // model of processor
|
||||||
int stepping_; // processor revision number
|
int stepping_; // processor revision number
|
||||||
int ext_model_;
|
int ext_model_;
|
||||||
int ext_family_;
|
int ext_family_;
|
||||||
std::string cpu_vendor_;
|
std::string cpu_vendor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|
||||||
#endif // BASE_CPU_H_
|
#endif // BASE_CPU_H_
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
#ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
||||||
#define BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
#define BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
||||||
|
|
||||||
#include "base/gfx/platform_device_linux.h"
|
#include "base/gfx/platform_device_linux.h"
|
||||||
#include "base/ref_counted.h"
|
#include "base/ref_counted.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// I'm trying to get away with defining as little as possible on this. Right
|
// I'm trying to get away with defining as little as possible on this. Right
|
||||||
// now, we don't do anything.
|
// now, we don't do anything.
|
||||||
class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
|
class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
|
||||||
public:
|
public:
|
||||||
/// Static constructor. I don't understand this, it's just a copy of the mac
|
/// Static constructor. I don't understand this, it's just a copy of the mac
|
||||||
static BitmapPlatformDeviceLinux* Create(int width, int height,
|
static BitmapPlatformDeviceLinux* Create(int width, int height,
|
||||||
bool is_opaque);
|
bool is_opaque);
|
||||||
|
|
||||||
/// Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
|
/// Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
|
||||||
/// you should probably be using Create(). This may become private later if
|
/// you should probably be using Create(). This may become private later if
|
||||||
/// we ever have to share state between some native drawing UI and Skia, like
|
/// we ever have to share state between some native drawing UI and Skia, like
|
||||||
/// the Windows and Mac versions of this class do.
|
/// the Windows and Mac versions of this class do.
|
||||||
BitmapPlatformDeviceLinux(const SkBitmap& other);
|
BitmapPlatformDeviceLinux(const SkBitmap& other);
|
||||||
virtual ~BitmapPlatformDeviceLinux();
|
virtual ~BitmapPlatformDeviceLinux();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
|
||||||
|
@@ -1,487 +1,487 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "base/gfx/bitmap_platform_device_win.h"
|
#include "base/gfx/bitmap_platform_device_win.h"
|
||||||
|
|
||||||
#include "base/gfx/bitmap_header.h"
|
#include "base/gfx/bitmap_header.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/process_util.h"
|
#include "base/process_util.h"
|
||||||
#include "SkMatrix.h"
|
#include "SkMatrix.h"
|
||||||
#include "SkRegion.h"
|
#include "SkRegion.h"
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// When Windows draws text, is sets the fourth byte (which Skia uses for alpha)
|
// When Windows draws text, is sets the fourth byte (which Skia uses for alpha)
|
||||||
// to zero. This means that if we try compositing with text that Windows has
|
// to zero. This means that if we try compositing with text that Windows has
|
||||||
// drawn, we get invalid color values (if the alpha is 0, the other channels
|
// drawn, we get invalid color values (if the alpha is 0, the other channels
|
||||||
// should be 0 since Skia uses premultiplied colors) and strange results.
|
// should be 0 since Skia uses premultiplied colors) and strange results.
|
||||||
//
|
//
|
||||||
// HTML rendering only requires one bit of transparency. When you ask for a
|
// HTML rendering only requires one bit of transparency. When you ask for a
|
||||||
// semitransparent div, the div itself is drawn in another layer as completely
|
// semitransparent div, the div itself is drawn in another layer as completely
|
||||||
// opaque, and then composited onto the lower layer with a transfer function.
|
// opaque, and then composited onto the lower layer with a transfer function.
|
||||||
// The only place an alpha channel is needed is to track what has been drawn
|
// The only place an alpha channel is needed is to track what has been drawn
|
||||||
// and what has not been drawn.
|
// and what has not been drawn.
|
||||||
//
|
//
|
||||||
// Therefore, when we allocate a new device, we fill it with this special
|
// Therefore, when we allocate a new device, we fill it with this special
|
||||||
// color. Because Skia uses premultiplied colors, any color where the alpha
|
// color. Because Skia uses premultiplied colors, any color where the alpha
|
||||||
// channel is smaller than any component is impossible, so we know that no
|
// channel is smaller than any component is impossible, so we know that no
|
||||||
// legitimate drawing will produce this color. We use 1 as the alpha value
|
// legitimate drawing will produce this color. We use 1 as the alpha value
|
||||||
// because 0 is produced when Windows draws text (even though it should be
|
// because 0 is produced when Windows draws text (even though it should be
|
||||||
// opaque).
|
// opaque).
|
||||||
//
|
//
|
||||||
// When a layer is done and we want to render it to a lower layer, we use
|
// When a layer is done and we want to render it to a lower layer, we use
|
||||||
// fixupAlphaBeforeCompositing. This replaces all 0 alpha channels with
|
// fixupAlphaBeforeCompositing. This replaces all 0 alpha channels with
|
||||||
// opaque (to fix the text problem), and replaces this magic color value
|
// opaque (to fix the text problem), and replaces this magic color value
|
||||||
// with transparency. The result is something that can be correctly
|
// with transparency. The result is something that can be correctly
|
||||||
// composited. However, once this has been done, no more can be drawn to
|
// composited. However, once this has been done, no more can be drawn to
|
||||||
// the layer because fixing the alphas *again* will result in incorrect
|
// the layer because fixing the alphas *again* will result in incorrect
|
||||||
// values.
|
// values.
|
||||||
static const uint32_t kMagicTransparencyColor = 0x01FFFEFD;
|
static const uint32_t kMagicTransparencyColor = 0x01FFFEFD;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Constrains position and size to fit within available_size. If |size| is -1,
|
// Constrains position and size to fit within available_size. If |size| is -1,
|
||||||
// all the available_size is used. Returns false if the position is out of
|
// all the available_size is used. Returns false if the position is out of
|
||||||
// available_size.
|
// available_size.
|
||||||
bool Constrain(int available_size, int* position, int *size) {
|
bool Constrain(int available_size, int* position, int *size) {
|
||||||
if (*size < -2)
|
if (*size < -2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (*position < 0) {
|
if (*position < 0) {
|
||||||
if (*size != -1)
|
if (*size != -1)
|
||||||
*size += *position;
|
*size += *position;
|
||||||
*position = 0;
|
*position = 0;
|
||||||
}
|
}
|
||||||
if (*size == 0 || *position >= available_size)
|
if (*size == 0 || *position >= available_size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (*size > 0) {
|
if (*size > 0) {
|
||||||
int overflow = (*position + *size) - available_size;
|
int overflow = (*position + *size) - available_size;
|
||||||
if (overflow > 0) {
|
if (overflow > 0) {
|
||||||
*size -= overflow;
|
*size -= overflow;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fill up available size.
|
// Fill up available size.
|
||||||
*size = available_size - *position;
|
*size = available_size - *position;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the pixel value is 0, it gets set to kMagicTransparencyColor.
|
// If the pixel value is 0, it gets set to kMagicTransparencyColor.
|
||||||
void PrepareAlphaForGDI(uint32_t* pixel) {
|
void PrepareAlphaForGDI(uint32_t* pixel) {
|
||||||
if (*pixel == 0) {
|
if (*pixel == 0) {
|
||||||
*pixel = kMagicTransparencyColor;
|
*pixel = kMagicTransparencyColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the pixel value is kMagicTransparencyColor, it gets set to 0. Otherwise
|
// If the pixel value is kMagicTransparencyColor, it gets set to 0. Otherwise
|
||||||
// if the alpha is 0, the alpha is set to 255.
|
// if the alpha is 0, the alpha is set to 255.
|
||||||
void PostProcessAlphaForGDI(uint32_t* pixel) {
|
void PostProcessAlphaForGDI(uint32_t* pixel) {
|
||||||
if (*pixel == kMagicTransparencyColor) {
|
if (*pixel == kMagicTransparencyColor) {
|
||||||
*pixel = 0;
|
*pixel = 0;
|
||||||
} else if ((*pixel & 0xFF000000) == 0) {
|
} else if ((*pixel & 0xFF000000) == 0) {
|
||||||
*pixel |= 0xFF000000;
|
*pixel |= 0xFF000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the opacity of the specified value to 0xFF.
|
// Sets the opacity of the specified value to 0xFF.
|
||||||
void MakeOpaqueAlphaAdjuster(uint32_t* pixel) {
|
void MakeOpaqueAlphaAdjuster(uint32_t* pixel) {
|
||||||
*pixel |= 0xFF000000;
|
*pixel |= 0xFF000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See the declaration of kMagicTransparencyColor at the top of the file.
|
// See the declaration of kMagicTransparencyColor at the top of the file.
|
||||||
void FixupAlphaBeforeCompositing(uint32_t* pixel) {
|
void FixupAlphaBeforeCompositing(uint32_t* pixel) {
|
||||||
if (*pixel == kMagicTransparencyColor)
|
if (*pixel == kMagicTransparencyColor)
|
||||||
*pixel = 0;
|
*pixel = 0;
|
||||||
else
|
else
|
||||||
*pixel |= 0xFF000000;
|
*pixel |= 0xFF000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crashes the process. This is called when a bitmap allocation fails, and this
|
// Crashes the process. This is called when a bitmap allocation fails, and this
|
||||||
// function tries to determine why it might have failed, and crash on different
|
// function tries to determine why it might have failed, and crash on different
|
||||||
// lines. This allows us to see in crash dumps the most likely reason for the
|
// lines. This allows us to see in crash dumps the most likely reason for the
|
||||||
// failure. It takes the size of the bitmap we were trying to allocate as its
|
// failure. It takes the size of the bitmap we were trying to allocate as its
|
||||||
// arguments so we can check that as well.
|
// arguments so we can check that as well.
|
||||||
void CrashForBitmapAllocationFailure(int w, int h) {
|
void CrashForBitmapAllocationFailure(int w, int h) {
|
||||||
// The maximum number of GDI objects per process is 10K. If we're very close
|
// The maximum number of GDI objects per process is 10K. If we're very close
|
||||||
// to that, it's probably the problem.
|
// to that, it's probably the problem.
|
||||||
const int kLotsOfGDIObjs = 9990;
|
const int kLotsOfGDIObjs = 9990;
|
||||||
CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs);
|
CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs);
|
||||||
|
|
||||||
// If the bitmap is ginormous, then we probably can't allocate it.
|
// If the bitmap is ginormous, then we probably can't allocate it.
|
||||||
// We use 64M pixels = 256MB @ 4 bytes per pixel.
|
// We use 64M pixels = 256MB @ 4 bytes per pixel.
|
||||||
const int64 kGinormousBitmapPxl = 64000000;
|
const int64 kGinormousBitmapPxl = 64000000;
|
||||||
CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl);
|
CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl);
|
||||||
|
|
||||||
// If we're using a crazy amount of virtual address space, then maybe there
|
// If we're using a crazy amount of virtual address space, then maybe there
|
||||||
// isn't enough for our bitmap.
|
// isn't enough for our bitmap.
|
||||||
const int64 kLotsOfMem = 1500000000; // 1.5GB.
|
const int64 kLotsOfMem = 1500000000; // 1.5GB.
|
||||||
scoped_ptr<process_util::ProcessMetrics> process_metrics(
|
scoped_ptr<process_util::ProcessMetrics> process_metrics(
|
||||||
process_util::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess()));
|
process_util::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess()));
|
||||||
CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem);
|
CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem);
|
||||||
|
|
||||||
// Everything else.
|
// Everything else.
|
||||||
CHECK(0);
|
CHECK(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData
|
class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData
|
||||||
: public base::RefCounted<BitmapPlatformDeviceWinData> {
|
: public base::RefCounted<BitmapPlatformDeviceWinData> {
|
||||||
public:
|
public:
|
||||||
explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap);
|
explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap);
|
||||||
|
|
||||||
// Create/destroy hdc_, which is the memory DC for our bitmap data.
|
// Create/destroy hdc_, which is the memory DC for our bitmap data.
|
||||||
HDC GetBitmapDC();
|
HDC GetBitmapDC();
|
||||||
void ReleaseBitmapDC();
|
void ReleaseBitmapDC();
|
||||||
bool IsBitmapDCCreated() const;
|
bool IsBitmapDCCreated() const;
|
||||||
|
|
||||||
// Sets the transform and clip operations. This will not update the DC,
|
// Sets the transform and clip operations. This will not update the DC,
|
||||||
// but will mark the config as dirty. The next call of LoadConfig will
|
// but will mark the config as dirty. The next call of LoadConfig will
|
||||||
// pick up these changes.
|
// pick up these changes.
|
||||||
void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
|
void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
|
||||||
// The device offset is already modified according to the transformation.
|
// The device offset is already modified according to the transformation.
|
||||||
void SetDeviceOffset(int x, int y);
|
void SetDeviceOffset(int x, int y);
|
||||||
|
|
||||||
const SkMatrix& transform() const {
|
const SkMatrix& transform() const {
|
||||||
return transform_;
|
return transform_;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Loads the current transform (taking into account offset_*_) and clip
|
// Loads the current transform (taking into account offset_*_) and clip
|
||||||
// into the DC. Can be called even when the DC is NULL (will be a NOP).
|
// into the DC. Can be called even when the DC is NULL (will be a NOP).
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
|
|
||||||
// Windows bitmap corresponding to our surface.
|
// Windows bitmap corresponding to our surface.
|
||||||
HBITMAP hbitmap_;
|
HBITMAP hbitmap_;
|
||||||
|
|
||||||
// Lazily-created DC used to draw into the bitmap, see getBitmapDC.
|
// Lazily-created DC used to draw into the bitmap, see getBitmapDC.
|
||||||
HDC hdc_;
|
HDC hdc_;
|
||||||
|
|
||||||
// Additional offset applied to the transform. See setDeviceOffset().
|
// Additional offset applied to the transform. See setDeviceOffset().
|
||||||
int offset_x_;
|
int offset_x_;
|
||||||
int offset_y_;
|
int offset_y_;
|
||||||
|
|
||||||
// True when there is a transform or clip that has not been set to the DC.
|
// True when there is a transform or clip that has not been set to the DC.
|
||||||
// The DC is retrieved for every text operation, and the transform and clip
|
// The DC is retrieved for every text operation, and the transform and clip
|
||||||
// do not change as much. We can save time by not loading the clip and
|
// do not change as much. We can save time by not loading the clip and
|
||||||
// transform for every one.
|
// transform for every one.
|
||||||
bool config_dirty_;
|
bool config_dirty_;
|
||||||
|
|
||||||
// Translation assigned to the DC: we need to keep track of this separately
|
// Translation assigned to the DC: we need to keep track of this separately
|
||||||
// so it can be updated even if the DC isn't created yet.
|
// so it can be updated even if the DC isn't created yet.
|
||||||
SkMatrix transform_;
|
SkMatrix transform_;
|
||||||
|
|
||||||
// The current clipping
|
// The current clipping
|
||||||
SkRegion clip_region_;
|
SkRegion clip_region_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class base::RefCounted<BitmapPlatformDeviceWinData>;
|
friend class base::RefCounted<BitmapPlatformDeviceWinData>;
|
||||||
~BitmapPlatformDeviceWinData();
|
~BitmapPlatformDeviceWinData();
|
||||||
|
|
||||||
DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceWinData);
|
DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceWinData);
|
||||||
};
|
};
|
||||||
|
|
||||||
BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData(
|
BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData(
|
||||||
HBITMAP hbitmap)
|
HBITMAP hbitmap)
|
||||||
: hbitmap_(hbitmap),
|
: hbitmap_(hbitmap),
|
||||||
hdc_(NULL),
|
hdc_(NULL),
|
||||||
offset_x_(0),
|
offset_x_(0),
|
||||||
offset_y_(0),
|
offset_y_(0),
|
||||||
config_dirty_(true) { // Want to load the config next time.
|
config_dirty_(true) { // Want to load the config next time.
|
||||||
// Initialize the clip region to the entire bitmap.
|
// Initialize the clip region to the entire bitmap.
|
||||||
BITMAP bitmap_data;
|
BITMAP bitmap_data;
|
||||||
if (GetObject(hbitmap_, sizeof(BITMAP), &bitmap_data)) {
|
if (GetObject(hbitmap_, sizeof(BITMAP), &bitmap_data)) {
|
||||||
SkIRect rect;
|
SkIRect rect;
|
||||||
rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight);
|
rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight);
|
||||||
clip_region_ = SkRegion(rect);
|
clip_region_ = SkRegion(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
transform_.reset();
|
transform_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinData() {
|
BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinData() {
|
||||||
if (hdc_)
|
if (hdc_)
|
||||||
ReleaseBitmapDC();
|
ReleaseBitmapDC();
|
||||||
|
|
||||||
// this will free the bitmap data as well as the bitmap handle
|
// this will free the bitmap data as well as the bitmap handle
|
||||||
DeleteObject(hbitmap_);
|
DeleteObject(hbitmap_);
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() {
|
HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() {
|
||||||
if (!hdc_) {
|
if (!hdc_) {
|
||||||
hdc_ = CreateCompatibleDC(NULL);
|
hdc_ = CreateCompatibleDC(NULL);
|
||||||
InitializeDC(hdc_);
|
InitializeDC(hdc_);
|
||||||
HGDIOBJ old_bitmap = SelectObject(hdc_, hbitmap_);
|
HGDIOBJ old_bitmap = SelectObject(hdc_, hbitmap_);
|
||||||
// When the memory DC is created, its display surface is exactly one
|
// When the memory DC is created, its display surface is exactly one
|
||||||
// monochrome pixel wide and one monochrome pixel high. Since we select our
|
// monochrome pixel wide and one monochrome pixel high. Since we select our
|
||||||
// own bitmap, we must delete the previous one.
|
// own bitmap, we must delete the previous one.
|
||||||
DeleteObject(old_bitmap);
|
DeleteObject(old_bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
return hdc_;
|
return hdc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() {
|
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() {
|
||||||
DCHECK(hdc_);
|
DCHECK(hdc_);
|
||||||
DeleteDC(hdc_);
|
DeleteDC(hdc_);
|
||||||
hdc_ = NULL;
|
hdc_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::IsBitmapDCCreated() const {
|
bool BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::IsBitmapDCCreated() const {
|
||||||
return hdc_ != NULL;
|
return hdc_ != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip(
|
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip(
|
||||||
const SkMatrix& transform,
|
const SkMatrix& transform,
|
||||||
const SkRegion& region) {
|
const SkRegion& region) {
|
||||||
transform_ = transform;
|
transform_ = transform;
|
||||||
clip_region_ = region;
|
clip_region_ = region;
|
||||||
config_dirty_ = true;
|
config_dirty_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetDeviceOffset(int x,
|
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetDeviceOffset(int x,
|
||||||
int y) {
|
int y) {
|
||||||
offset_x_ = x;
|
offset_x_ = x;
|
||||||
offset_y_ = y;
|
offset_y_ = y;
|
||||||
config_dirty_ = true;
|
config_dirty_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() {
|
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() {
|
||||||
if (!config_dirty_ || !hdc_)
|
if (!config_dirty_ || !hdc_)
|
||||||
return; // Nothing to do.
|
return; // Nothing to do.
|
||||||
config_dirty_ = false;
|
config_dirty_ = false;
|
||||||
|
|
||||||
// Transform.
|
// Transform.
|
||||||
SkMatrix t(transform_);
|
SkMatrix t(transform_);
|
||||||
t.postTranslate(SkIntToScalar(-offset_x_), SkIntToScalar(-offset_y_));
|
t.postTranslate(SkIntToScalar(-offset_x_), SkIntToScalar(-offset_y_));
|
||||||
LoadTransformToDC(hdc_, t);
|
LoadTransformToDC(hdc_, t);
|
||||||
// We don't use transform_ for the clipping region since the translation is
|
// We don't use transform_ for the clipping region since the translation is
|
||||||
// already applied to offset_x_ and offset_y_.
|
// already applied to offset_x_ and offset_y_.
|
||||||
t.reset();
|
t.reset();
|
||||||
t.postTranslate(SkIntToScalar(-offset_x_), SkIntToScalar(-offset_y_));
|
t.postTranslate(SkIntToScalar(-offset_x_), SkIntToScalar(-offset_y_));
|
||||||
LoadClippingRegionToDC(hdc_, clip_region_, t);
|
LoadClippingRegionToDC(hdc_, clip_region_, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use this static factory function instead of the regular constructor so
|
// We use this static factory function instead of the regular constructor so
|
||||||
// that we can create the pixel data before calling the constructor. This is
|
// that we can create the pixel data before calling the constructor. This is
|
||||||
// required so that we can call the base class' constructor with the pixel
|
// required so that we can call the base class' constructor with the pixel
|
||||||
// data.
|
// data.
|
||||||
BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc,
|
BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque,
|
bool is_opaque,
|
||||||
HANDLE shared_section) {
|
HANDLE shared_section) {
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
|
|
||||||
// CreateDIBSection appears to get unhappy if we create an empty bitmap, so
|
// CreateDIBSection appears to get unhappy if we create an empty bitmap, so
|
||||||
// we just expand it here.
|
// we just expand it here.
|
||||||
if (width == 0)
|
if (width == 0)
|
||||||
width = 1;
|
width = 1;
|
||||||
if (height == 0)
|
if (height == 0)
|
||||||
height = 1;
|
height = 1;
|
||||||
|
|
||||||
BITMAPINFOHEADER hdr;
|
BITMAPINFOHEADER hdr;
|
||||||
CreateBitmapHeader(width, height, &hdr);
|
CreateBitmapHeader(width, height, &hdr);
|
||||||
|
|
||||||
void* data;
|
void* data;
|
||||||
HBITMAP hbitmap = CreateDIBSection(screen_dc,
|
HBITMAP hbitmap = CreateDIBSection(screen_dc,
|
||||||
reinterpret_cast<BITMAPINFO*>(&hdr), 0,
|
reinterpret_cast<BITMAPINFO*>(&hdr), 0,
|
||||||
&data,
|
&data,
|
||||||
shared_section, 0);
|
shared_section, 0);
|
||||||
|
|
||||||
// If we run out of GDI objects or some other error occurs, we won't get a
|
// If we run out of GDI objects or some other error occurs, we won't get a
|
||||||
// bitmap here. This will cause us to crash later because the data pointer is
|
// bitmap here. This will cause us to crash later because the data pointer is
|
||||||
// NULL. To make sure that we can assign blame for those crashes to this code,
|
// NULL. To make sure that we can assign blame for those crashes to this code,
|
||||||
// we deliberately crash here, even in release mode.
|
// we deliberately crash here, even in release mode.
|
||||||
if (!hbitmap)
|
if (!hbitmap)
|
||||||
CrashForBitmapAllocationFailure(width, height);
|
CrashForBitmapAllocationFailure(width, height);
|
||||||
|
|
||||||
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
||||||
bitmap.setPixels(data);
|
bitmap.setPixels(data);
|
||||||
bitmap.setIsOpaque(is_opaque);
|
bitmap.setIsOpaque(is_opaque);
|
||||||
|
|
||||||
if (is_opaque) {
|
if (is_opaque) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// To aid in finding bugs, we set the background color to something
|
// To aid in finding bugs, we set the background color to something
|
||||||
// obviously wrong so it will be noticable when it is not cleared
|
// obviously wrong so it will be noticable when it is not cleared
|
||||||
bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
|
bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// A transparent layer is requested: fill with our magic "transparent"
|
// A transparent layer is requested: fill with our magic "transparent"
|
||||||
// color, see the declaration of kMagicTransparencyColor above
|
// color, see the declaration of kMagicTransparencyColor above
|
||||||
sk_memset32(static_cast<uint32_t*>(data), kMagicTransparencyColor,
|
sk_memset32(static_cast<uint32_t*>(data), kMagicTransparencyColor,
|
||||||
width * height);
|
width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The device object will take ownership of the HBITMAP.
|
// The device object will take ownership of the HBITMAP.
|
||||||
return new BitmapPlatformDeviceWin(new BitmapPlatformDeviceWinData(hbitmap), bitmap);
|
return new BitmapPlatformDeviceWin(new BitmapPlatformDeviceWinData(hbitmap), bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The device will own the HBITMAP, which corresponds to also owning the pixel
|
// The device will own the HBITMAP, which corresponds to also owning the pixel
|
||||||
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
|
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
|
||||||
BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data,
|
BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data,
|
||||||
const SkBitmap& bitmap)
|
const SkBitmap& bitmap)
|
||||||
: PlatformDeviceWin(bitmap),
|
: PlatformDeviceWin(bitmap),
|
||||||
data_(data) {
|
data_(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The copy constructor just adds another reference to the underlying data.
|
// The copy constructor just adds another reference to the underlying data.
|
||||||
// We use a const cast since the default Skia definitions don't define the
|
// We use a const cast since the default Skia definitions don't define the
|
||||||
// proper constedness that we expect (accessBitmap should really be const).
|
// proper constedness that we expect (accessBitmap should really be const).
|
||||||
BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other)
|
BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other)
|
||||||
: PlatformDeviceWin(
|
: PlatformDeviceWin(
|
||||||
const_cast<BitmapPlatformDeviceWin&>(other).accessBitmap(true)),
|
const_cast<BitmapPlatformDeviceWin&>(other).accessBitmap(true)),
|
||||||
data_(other.data_) {
|
data_(other.data_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapPlatformDeviceWin::~BitmapPlatformDeviceWin() {
|
BitmapPlatformDeviceWin::~BitmapPlatformDeviceWin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapPlatformDeviceWin& BitmapPlatformDeviceWin::operator=(
|
BitmapPlatformDeviceWin& BitmapPlatformDeviceWin::operator=(
|
||||||
const BitmapPlatformDeviceWin& other) {
|
const BitmapPlatformDeviceWin& other) {
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC BitmapPlatformDeviceWin::getBitmapDC() {
|
HDC BitmapPlatformDeviceWin::getBitmapDC() {
|
||||||
return data_->GetBitmapDC();
|
return data_->GetBitmapDC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::setMatrixClip(const SkMatrix& transform,
|
void BitmapPlatformDeviceWin::setMatrixClip(const SkMatrix& transform,
|
||||||
const SkRegion& region) {
|
const SkRegion& region) {
|
||||||
data_->SetMatrixClip(transform, region);
|
data_->SetMatrixClip(transform, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::setDeviceOffset(int x, int y) {
|
void BitmapPlatformDeviceWin::setDeviceOffset(int x, int y) {
|
||||||
data_->SetDeviceOffset(x, y);
|
data_->SetDeviceOffset(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y,
|
void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y,
|
||||||
const RECT* src_rect) {
|
const RECT* src_rect) {
|
||||||
bool created_dc = !data_->IsBitmapDCCreated();
|
bool created_dc = !data_->IsBitmapDCCreated();
|
||||||
HDC source_dc = getBitmapDC();
|
HDC source_dc = getBitmapDC();
|
||||||
|
|
||||||
RECT temp_rect;
|
RECT temp_rect;
|
||||||
if (!src_rect) {
|
if (!src_rect) {
|
||||||
temp_rect.left = 0;
|
temp_rect.left = 0;
|
||||||
temp_rect.right = width();
|
temp_rect.right = width();
|
||||||
temp_rect.top = 0;
|
temp_rect.top = 0;
|
||||||
temp_rect.bottom = height();
|
temp_rect.bottom = height();
|
||||||
src_rect = &temp_rect;
|
src_rect = &temp_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
int copy_width = src_rect->right - src_rect->left;
|
int copy_width = src_rect->right - src_rect->left;
|
||||||
int copy_height = src_rect->bottom - src_rect->top;
|
int copy_height = src_rect->bottom - src_rect->top;
|
||||||
|
|
||||||
// We need to reset the translation for our bitmap or (0,0) won't be in the
|
// We need to reset the translation for our bitmap or (0,0) won't be in the
|
||||||
// upper left anymore
|
// upper left anymore
|
||||||
SkMatrix identity;
|
SkMatrix identity;
|
||||||
identity.reset();
|
identity.reset();
|
||||||
|
|
||||||
LoadTransformToDC(source_dc, identity);
|
LoadTransformToDC(source_dc, identity);
|
||||||
if (isOpaque()) {
|
if (isOpaque()) {
|
||||||
BitBlt(dc,
|
BitBlt(dc,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
copy_width,
|
copy_width,
|
||||||
copy_height,
|
copy_height,
|
||||||
source_dc,
|
source_dc,
|
||||||
src_rect->left,
|
src_rect->left,
|
||||||
src_rect->top,
|
src_rect->top,
|
||||||
SRCCOPY);
|
SRCCOPY);
|
||||||
} else {
|
} else {
|
||||||
BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
|
BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
|
||||||
AlphaBlend(dc,
|
AlphaBlend(dc,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
copy_width,
|
copy_width,
|
||||||
copy_height,
|
copy_height,
|
||||||
source_dc,
|
source_dc,
|
||||||
src_rect->left,
|
src_rect->left,
|
||||||
src_rect->top,
|
src_rect->top,
|
||||||
copy_width,
|
copy_width,
|
||||||
copy_height,
|
copy_height,
|
||||||
blend_function);
|
blend_function);
|
||||||
}
|
}
|
||||||
LoadTransformToDC(source_dc, data_->transform());
|
LoadTransformToDC(source_dc, data_->transform());
|
||||||
|
|
||||||
if (created_dc)
|
if (created_dc)
|
||||||
data_->ReleaseBitmapDC();
|
data_->ReleaseBitmapDC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::prepareForGDI(int x, int y, int width, int height) {
|
void BitmapPlatformDeviceWin::prepareForGDI(int x, int y, int width, int height) {
|
||||||
processPixels<PrepareAlphaForGDI>(x, y, width, height);
|
processPixels<PrepareAlphaForGDI>(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::postProcessGDI(int x, int y, int width, int height) {
|
void BitmapPlatformDeviceWin::postProcessGDI(int x, int y, int width, int height) {
|
||||||
processPixels<PostProcessAlphaForGDI>(x, y, width, height);
|
processPixels<PostProcessAlphaForGDI>(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) {
|
void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) {
|
||||||
processPixels<MakeOpaqueAlphaAdjuster>(x, y, width, height);
|
processPixels<MakeOpaqueAlphaAdjuster>(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::fixupAlphaBeforeCompositing() {
|
void BitmapPlatformDeviceWin::fixupAlphaBeforeCompositing() {
|
||||||
const SkBitmap& bitmap = accessBitmap(true);
|
const SkBitmap& bitmap = accessBitmap(true);
|
||||||
SkAutoLockPixels lock(bitmap);
|
SkAutoLockPixels lock(bitmap);
|
||||||
uint32_t* data = bitmap.getAddr32(0, 0);
|
uint32_t* data = bitmap.getAddr32(0, 0);
|
||||||
|
|
||||||
size_t words = bitmap.rowBytes() / sizeof(uint32_t) * bitmap.height();
|
size_t words = bitmap.rowBytes() / sizeof(uint32_t) * bitmap.height();
|
||||||
for (size_t i = 0; i < words; i++) {
|
for (size_t i = 0; i < words; i++) {
|
||||||
if (data[i] == kMagicTransparencyColor)
|
if (data[i] == kMagicTransparencyColor)
|
||||||
data[i] = 0;
|
data[i] = 0;
|
||||||
else
|
else
|
||||||
data[i] |= 0xFF000000;
|
data[i] |= 0xFF000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the color value at the specified location.
|
// Returns the color value at the specified location.
|
||||||
SkColor BitmapPlatformDeviceWin::getColorAt(int x, int y) {
|
SkColor BitmapPlatformDeviceWin::getColorAt(int x, int y) {
|
||||||
const SkBitmap& bitmap = accessBitmap(false);
|
const SkBitmap& bitmap = accessBitmap(false);
|
||||||
SkAutoLockPixels lock(bitmap);
|
SkAutoLockPixels lock(bitmap);
|
||||||
uint32_t* data = bitmap.getAddr32(0, 0);
|
uint32_t* data = bitmap.getAddr32(0, 0);
|
||||||
return static_cast<SkColor>(data[x + y * width()]);
|
return static_cast<SkColor>(data[x + y * width()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPlatformDeviceWin::onAccessBitmap(SkBitmap* bitmap) {
|
void BitmapPlatformDeviceWin::onAccessBitmap(SkBitmap* bitmap) {
|
||||||
// FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI
|
// FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI
|
||||||
// operation has occurred on our DC.
|
// operation has occurred on our DC.
|
||||||
if (data_->IsBitmapDCCreated())
|
if (data_->IsBitmapDCCreated())
|
||||||
GdiFlush();
|
GdiFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<BitmapPlatformDeviceWin::adjustAlpha adjustor>
|
template<BitmapPlatformDeviceWin::adjustAlpha adjustor>
|
||||||
void BitmapPlatformDeviceWin::processPixels(int x,
|
void BitmapPlatformDeviceWin::processPixels(int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
int height) {
|
int height) {
|
||||||
const SkBitmap& bitmap = accessBitmap(true);
|
const SkBitmap& bitmap = accessBitmap(true);
|
||||||
DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config);
|
DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config);
|
||||||
const SkMatrix& matrix = data_->transform();
|
const SkMatrix& matrix = data_->transform();
|
||||||
int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
|
int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
|
||||||
int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y;
|
int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y;
|
||||||
|
|
||||||
if (Constrain(bitmap.width(), &bitmap_start_x, &width) &&
|
if (Constrain(bitmap.width(), &bitmap_start_x, &width) &&
|
||||||
Constrain(bitmap.height(), &bitmap_start_y, &height)) {
|
Constrain(bitmap.height(), &bitmap_start_y, &height)) {
|
||||||
SkAutoLockPixels lock(bitmap);
|
SkAutoLockPixels lock(bitmap);
|
||||||
DCHECK_EQ(bitmap.rowBytes() % sizeof(uint32_t), 0u);
|
DCHECK_EQ(bitmap.rowBytes() % sizeof(uint32_t), 0u);
|
||||||
size_t row_words = bitmap.rowBytes() / sizeof(uint32_t);
|
size_t row_words = bitmap.rowBytes() / sizeof(uint32_t);
|
||||||
// Set data to the first pixel to be modified.
|
// Set data to the first pixel to be modified.
|
||||||
uint32_t* data = bitmap.getAddr32(0, 0) + (bitmap_start_y * row_words) +
|
uint32_t* data = bitmap.getAddr32(0, 0) + (bitmap_start_y * row_words) +
|
||||||
bitmap_start_x;
|
bitmap_start_x;
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
adjustor(data + j);
|
adjustor(data + j);
|
||||||
}
|
}
|
||||||
data += row_words;
|
data += row_words;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
|
@@ -1,111 +1,111 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
#ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
||||||
#define BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
#define BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
||||||
|
|
||||||
#include "base/gfx/platform_device_win.h"
|
#include "base/gfx/platform_device_win.h"
|
||||||
#include "base/ref_counted.h"
|
#include "base/ref_counted.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// A device is basically a wrapper around SkBitmap that provides a surface for
|
// A device is basically a wrapper around SkBitmap that provides a surface for
|
||||||
// SkCanvas to draw into. Our device provides a surface Windows can also write
|
// SkCanvas to draw into. Our device provides a surface Windows can also write
|
||||||
// to. BitmapPlatformDeviceWin creates a bitmap using CreateDIBSection() in a
|
// to. BitmapPlatformDeviceWin creates a bitmap using CreateDIBSection() in a
|
||||||
// format that Skia supports and can then use this to draw ClearType into, etc.
|
// format that Skia supports and can then use this to draw ClearType into, etc.
|
||||||
// This pixel data is provided to the bitmap that the device contains so that it
|
// This pixel data is provided to the bitmap that the device contains so that it
|
||||||
// can be shared.
|
// can be shared.
|
||||||
//
|
//
|
||||||
// The device owns the pixel data, when the device goes away, the pixel data
|
// The device owns the pixel data, when the device goes away, the pixel data
|
||||||
// also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses
|
// also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses
|
||||||
// reference counting for the pixel data. In normal Skia, you could assign
|
// reference counting for the pixel data. In normal Skia, you could assign
|
||||||
// another bitmap to this device's bitmap and everything will work properly.
|
// another bitmap to this device's bitmap and everything will work properly.
|
||||||
// For us, that other bitmap will become invalid as soon as the device becomes
|
// For us, that other bitmap will become invalid as soon as the device becomes
|
||||||
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
|
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
|
||||||
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
|
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
|
||||||
class BitmapPlatformDeviceWin : public PlatformDeviceWin {
|
class BitmapPlatformDeviceWin : public PlatformDeviceWin {
|
||||||
public:
|
public:
|
||||||
// Factory function. The screen DC is used to create the bitmap, and will not
|
// Factory function. The screen DC is used to create the bitmap, and will not
|
||||||
// be stored beyond this function. is_opaque should be set if the caller
|
// be stored beyond this function. is_opaque should be set if the caller
|
||||||
// knows the bitmap will be completely opaque and allows some optimizations.
|
// knows the bitmap will be completely opaque and allows some optimizations.
|
||||||
//
|
//
|
||||||
// The shared_section parameter is optional (pass NULL for default behavior).
|
// The shared_section parameter is optional (pass NULL for default behavior).
|
||||||
// If shared_section is non-null, then it must be a handle to a file-mapping
|
// If shared_section is non-null, then it must be a handle to a file-mapping
|
||||||
// object returned by CreateFileMapping. See CreateDIBSection for details.
|
// object returned by CreateFileMapping. See CreateDIBSection for details.
|
||||||
static BitmapPlatformDeviceWin* create(HDC screen_dc,
|
static BitmapPlatformDeviceWin* create(HDC screen_dc,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque,
|
bool is_opaque,
|
||||||
HANDLE shared_section);
|
HANDLE shared_section);
|
||||||
|
|
||||||
// Copy constructor. When copied, devices duplicate their internal data, so
|
// Copy constructor. When copied, devices duplicate their internal data, so
|
||||||
// stay linked. This is because their implementation is very heavyweight
|
// stay linked. This is because their implementation is very heavyweight
|
||||||
// (lots of memory and some GDI objects). If a device has been copied, both
|
// (lots of memory and some GDI objects). If a device has been copied, both
|
||||||
// clip rects and other state will stay in sync.
|
// clip rects and other state will stay in sync.
|
||||||
//
|
//
|
||||||
// This means it will NOT work to duplicate a device and assign it to a
|
// This means it will NOT work to duplicate a device and assign it to a
|
||||||
// canvas, because the two canvases will each set their own clip rects, and
|
// canvas, because the two canvases will each set their own clip rects, and
|
||||||
// the resulting GDI clip rect will be random.
|
// the resulting GDI clip rect will be random.
|
||||||
//
|
//
|
||||||
// Copy constucting and "=" is designed for saving the device or passing it
|
// Copy constucting and "=" is designed for saving the device or passing it
|
||||||
// around to another routine willing to deal with the bitmap data directly.
|
// around to another routine willing to deal with the bitmap data directly.
|
||||||
BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other);
|
BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other);
|
||||||
virtual ~BitmapPlatformDeviceWin();
|
virtual ~BitmapPlatformDeviceWin();
|
||||||
|
|
||||||
// See warning for copy constructor above.
|
// See warning for copy constructor above.
|
||||||
BitmapPlatformDeviceWin& operator=(const BitmapPlatformDeviceWin& other);
|
BitmapPlatformDeviceWin& operator=(const BitmapPlatformDeviceWin& other);
|
||||||
|
|
||||||
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
|
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
|
||||||
// bitmap DC is lazy created.
|
// bitmap DC is lazy created.
|
||||||
virtual HDC getBitmapDC();
|
virtual HDC getBitmapDC();
|
||||||
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
|
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
|
||||||
virtual void setDeviceOffset(int x, int y);
|
virtual void setDeviceOffset(int x, int y);
|
||||||
|
|
||||||
virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
|
virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
|
||||||
virtual void prepareForGDI(int x, int y, int width, int height);
|
virtual void prepareForGDI(int x, int y, int width, int height);
|
||||||
virtual void postProcessGDI(int x, int y, int width, int height);
|
virtual void postProcessGDI(int x, int y, int width, int height);
|
||||||
virtual void makeOpaque(int x, int y, int width, int height);
|
virtual void makeOpaque(int x, int y, int width, int height);
|
||||||
virtual void fixupAlphaBeforeCompositing();
|
virtual void fixupAlphaBeforeCompositing();
|
||||||
virtual bool IsVectorial() { return false; }
|
virtual bool IsVectorial() { return false; }
|
||||||
|
|
||||||
// Returns the color value at the specified location. This does not
|
// Returns the color value at the specified location. This does not
|
||||||
// consider any transforms that may be set on the device.
|
// consider any transforms that may be set on the device.
|
||||||
SkColor getColorAt(int x, int y);
|
SkColor getColorAt(int x, int y);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Flushes the Windows device context so that the pixel data can be accessed
|
// Flushes the Windows device context so that the pixel data can be accessed
|
||||||
// directly by Skia. Overridden from SkDevice, this is called when Skia
|
// directly by Skia. Overridden from SkDevice, this is called when Skia
|
||||||
// starts accessing pixel data.
|
// starts accessing pixel data.
|
||||||
virtual void onAccessBitmap(SkBitmap* bitmap);
|
virtual void onAccessBitmap(SkBitmap* bitmap);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Function pointer used by the processPixels method for setting the alpha
|
// Function pointer used by the processPixels method for setting the alpha
|
||||||
// value of a particular pixel.
|
// value of a particular pixel.
|
||||||
typedef void (*adjustAlpha)(uint32_t* pixel);
|
typedef void (*adjustAlpha)(uint32_t* pixel);
|
||||||
|
|
||||||
// Reference counted data that can be shared between multiple devices. This
|
// Reference counted data that can be shared between multiple devices. This
|
||||||
// allows copy constructors and operator= for devices to work properly. The
|
// allows copy constructors and operator= for devices to work properly. The
|
||||||
// bitmaps used by the base device class are already refcounted and copyable.
|
// bitmaps used by the base device class are already refcounted and copyable.
|
||||||
class BitmapPlatformDeviceWinData;
|
class BitmapPlatformDeviceWinData;
|
||||||
|
|
||||||
// Private constructor.
|
// Private constructor.
|
||||||
BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data, const SkBitmap& bitmap);
|
BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data, const SkBitmap& bitmap);
|
||||||
|
|
||||||
// Loops through each of the pixels in the specified range, invoking
|
// Loops through each of the pixels in the specified range, invoking
|
||||||
// adjustor for the alpha value of each pixel. If |width| or |height| are -1,
|
// adjustor for the alpha value of each pixel. If |width| or |height| are -1,
|
||||||
// the available width/height is used.
|
// the available width/height is used.
|
||||||
template<adjustAlpha adjustor>
|
template<adjustAlpha adjustor>
|
||||||
void processPixels(int x,
|
void processPixels(int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
|
|
||||||
// Data associated with this device, guaranteed non-null.
|
// Data associated with this device, guaranteed non-null.
|
||||||
scoped_refptr<BitmapPlatformDeviceWinData> data_;
|
scoped_refptr<BitmapPlatformDeviceWinData> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H__
|
||||||
|
|
||||||
|
@@ -1,85 +1,85 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "base/gfx/platform_canvas_win.h"
|
#include "base/gfx/platform_canvas_win.h"
|
||||||
|
|
||||||
#include "base/gfx/bitmap_platform_device_win.h"
|
#include "base/gfx/bitmap_platform_device_win.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
|
||||||
#ifdef ARCH_CPU_64_BITS
|
#ifdef ARCH_CPU_64_BITS
|
||||||
#error This code does not work on x64. Please make sure all the base unit tests\
|
#error This code does not work on x64. Please make sure all the base unit tests\
|
||||||
pass before doing any real work.
|
pass before doing any real work.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
|
PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque)
|
PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque)
|
||||||
: SkCanvas() {
|
: SkCanvas() {
|
||||||
initialize(width, height, is_opaque, NULL);
|
initialize(width, height, is_opaque, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformCanvasWin::PlatformCanvasWin(int width,
|
PlatformCanvasWin::PlatformCanvasWin(int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque,
|
bool is_opaque,
|
||||||
HANDLE shared_section)
|
HANDLE shared_section)
|
||||||
: SkCanvas() {
|
: SkCanvas() {
|
||||||
initialize(width, height, is_opaque, shared_section);
|
initialize(width, height, is_opaque, shared_section);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformCanvasWin::~PlatformCanvasWin() {
|
PlatformCanvasWin::~PlatformCanvasWin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformCanvasWin::initialize(int width,
|
void PlatformCanvasWin::initialize(int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque,
|
bool is_opaque,
|
||||||
HANDLE shared_section) {
|
HANDLE shared_section) {
|
||||||
SkDevice* device =
|
SkDevice* device =
|
||||||
createPlatformDevice(width, height, is_opaque, shared_section);
|
createPlatformDevice(width, height, is_opaque, shared_section);
|
||||||
setDevice(device);
|
setDevice(device);
|
||||||
device->unref(); // was created with refcount 1, and setDevice also refs
|
device->unref(); // was created with refcount 1, and setDevice also refs
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC PlatformCanvasWin::beginPlatformPaint() {
|
HDC PlatformCanvasWin::beginPlatformPaint() {
|
||||||
return getTopPlatformDevice().getBitmapDC();
|
return getTopPlatformDevice().getBitmapDC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformCanvasWin::endPlatformPaint() {
|
void PlatformCanvasWin::endPlatformPaint() {
|
||||||
// we don't clear the DC here since it will be likely to be used again
|
// we don't clear the DC here since it will be likely to be used again
|
||||||
// flushing will be done in onAccessBitmap
|
// flushing will be done in onAccessBitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const {
|
PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const {
|
||||||
// All of our devices should be our special PlatformDevice.
|
// All of our devices should be our special PlatformDevice.
|
||||||
SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false);
|
SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false);
|
||||||
return *static_cast<PlatformDeviceWin*>(iter.device());
|
return *static_cast<PlatformDeviceWin*>(iter.device());
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
|
SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque, bool isForLayer) {
|
bool is_opaque, bool isForLayer) {
|
||||||
DCHECK(config == SkBitmap::kARGB_8888_Config);
|
DCHECK(config == SkBitmap::kARGB_8888_Config);
|
||||||
return createPlatformDevice(width, height, is_opaque, NULL);
|
return createPlatformDevice(width, height, is_opaque, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
|
SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
|
||||||
int height,
|
int height,
|
||||||
bool is_opaque,
|
bool is_opaque,
|
||||||
HANDLE shared_section) {
|
HANDLE shared_section) {
|
||||||
HDC screen_dc = GetDC(NULL);
|
HDC screen_dc = GetDC(NULL);
|
||||||
SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
|
SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
|
||||||
is_opaque, shared_section);
|
is_opaque, shared_section);
|
||||||
ReleaseDC(NULL, screen_dc);
|
ReleaseDC(NULL, screen_dc);
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
|
SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
@@ -1,185 +1,185 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
#ifndef BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
||||||
#define BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
#define BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
||||||
|
|
||||||
#include "base/gfx/platform_device_win.h"
|
#include "base/gfx/platform_device_win.h"
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
|
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// This class is a specialization of the regular SkCanvas that is designed to
|
// This class is a specialization of the regular SkCanvas that is designed to
|
||||||
// work with a gfx::PlatformDevice to manage platform-specific drawing. It
|
// work with a gfx::PlatformDevice to manage platform-specific drawing. It
|
||||||
// allows using both Skia operations and platform-specific operations.
|
// allows using both Skia operations and platform-specific operations.
|
||||||
class PlatformCanvasWin : public SkCanvas {
|
class PlatformCanvasWin : public SkCanvas {
|
||||||
public:
|
public:
|
||||||
// Set is_opaque if you are going to erase the bitmap and not use
|
// Set is_opaque if you are going to erase the bitmap and not use
|
||||||
// transparency: this will enable some optimizations. The shared_section
|
// transparency: this will enable some optimizations. The shared_section
|
||||||
// parameter is passed to gfx::PlatformDevice::create. See it for details.
|
// parameter is passed to gfx::PlatformDevice::create. See it for details.
|
||||||
//
|
//
|
||||||
// If you use the version with no arguments, you MUST call initialize()
|
// If you use the version with no arguments, you MUST call initialize()
|
||||||
PlatformCanvasWin();
|
PlatformCanvasWin();
|
||||||
PlatformCanvasWin(int width, int height, bool is_opaque);
|
PlatformCanvasWin(int width, int height, bool is_opaque);
|
||||||
PlatformCanvasWin(int width, int height, bool is_opaque, HANDLE shared_section);
|
PlatformCanvasWin(int width, int height, bool is_opaque, HANDLE shared_section);
|
||||||
virtual ~PlatformCanvasWin();
|
virtual ~PlatformCanvasWin();
|
||||||
|
|
||||||
// For two-part init, call if you use the no-argument constructor above
|
// For two-part init, call if you use the no-argument constructor above
|
||||||
void initialize(int width, int height, bool is_opaque, HANDLE shared_section);
|
void initialize(int width, int height, bool is_opaque, HANDLE shared_section);
|
||||||
|
|
||||||
// These calls should surround calls to platform drawing routines, the DC
|
// These calls should surround calls to platform drawing routines, the DC
|
||||||
// returned by beginPlatformPaint is the DC that can be used to draw into.
|
// returned by beginPlatformPaint is the DC that can be used to draw into.
|
||||||
// Call endPlatformPaint when you are done and want to use Skia operations
|
// Call endPlatformPaint when you are done and want to use Skia operations
|
||||||
// again; this will synchronize the bitmap to Windows.
|
// again; this will synchronize the bitmap to Windows.
|
||||||
virtual HDC beginPlatformPaint();
|
virtual HDC beginPlatformPaint();
|
||||||
virtual void endPlatformPaint();
|
virtual void endPlatformPaint();
|
||||||
|
|
||||||
// Returns the platform device pointer of the topmost rect with a non-empty
|
// Returns the platform device pointer of the topmost rect with a non-empty
|
||||||
// clip. In practice, this is usually either the top layer or nothing, since
|
// clip. In practice, this is usually either the top layer or nothing, since
|
||||||
// we usually set the clip to new layers when we make them.
|
// we usually set the clip to new layers when we make them.
|
||||||
//
|
//
|
||||||
// If there is no layer that is not all clipped out, this will return a
|
// If there is no layer that is not all clipped out, this will return a
|
||||||
// dummy device so callers do not have to check. If you are concerned about
|
// dummy device so callers do not have to check. If you are concerned about
|
||||||
// performance, check the clip before doing any painting.
|
// performance, check the clip before doing any painting.
|
||||||
//
|
//
|
||||||
// This is different than SkCanvas' getDevice, because that returns the
|
// This is different than SkCanvas' getDevice, because that returns the
|
||||||
// bottommost device.
|
// bottommost device.
|
||||||
//
|
//
|
||||||
// Danger: the resulting device should not be saved. It will be invalidated
|
// Danger: the resulting device should not be saved. It will be invalidated
|
||||||
// by the next call to save() or restore().
|
// by the next call to save() or restore().
|
||||||
PlatformDeviceWin& getTopPlatformDevice() const;
|
PlatformDeviceWin& getTopPlatformDevice() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Creates a device store for use by the canvas. We override this so that
|
// Creates a device store for use by the canvas. We override this so that
|
||||||
// the device is always our own so we know that we can use GDI operations
|
// the device is always our own so we know that we can use GDI operations
|
||||||
// on it. Simply calls into createPlatformDevice().
|
// on it. Simply calls into createPlatformDevice().
|
||||||
virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
|
virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
|
||||||
bool is_opaque, bool isForLayer);
|
bool is_opaque, bool isForLayer);
|
||||||
|
|
||||||
// Creates a device store for use by the canvas. By default, it creates a
|
// Creates a device store for use by the canvas. By default, it creates a
|
||||||
// BitmapPlatformDeviceWin object. Can be overridden to change the object type.
|
// BitmapPlatformDeviceWin object. Can be overridden to change the object type.
|
||||||
virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
|
virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
|
||||||
HANDLE shared_section);
|
HANDLE shared_section);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Unimplemented.
|
// Unimplemented.
|
||||||
virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
|
virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
|
||||||
|
|
||||||
DISALLOW_EVIL_CONSTRUCTORS(PlatformCanvasWin);
|
DISALLOW_EVIL_CONSTRUCTORS(PlatformCanvasWin);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A class designed to help with WM_PAINT operations on Windows. It will
|
// A class designed to help with WM_PAINT operations on Windows. It will
|
||||||
// do BeginPaint/EndPaint on init/destruction, and will create the bitmap and
|
// do BeginPaint/EndPaint on init/destruction, and will create the bitmap and
|
||||||
// canvas with the correct size and transform for the dirty rect. The bitmap
|
// canvas with the correct size and transform for the dirty rect. The bitmap
|
||||||
// will be automatically painted to the screen on destruction.
|
// will be automatically painted to the screen on destruction.
|
||||||
//
|
//
|
||||||
// You MUST call isEmpty before painting to determine if anything needs
|
// You MUST call isEmpty before painting to determine if anything needs
|
||||||
// painting. Sometimes the dirty rect can actually be empty, and this makes
|
// painting. Sometimes the dirty rect can actually be empty, and this makes
|
||||||
// the bitmap functions we call unhappy. The caller should not paint in this
|
// the bitmap functions we call unhappy. The caller should not paint in this
|
||||||
// case.
|
// case.
|
||||||
//
|
//
|
||||||
// Therefore, all you need to do is:
|
// Therefore, all you need to do is:
|
||||||
// case WM_PAINT: {
|
// case WM_PAINT: {
|
||||||
// gfx::PlatformCanvasWinPaint canvas(hwnd);
|
// gfx::PlatformCanvasWinPaint canvas(hwnd);
|
||||||
// if (!canvas.isEmpty()) {
|
// if (!canvas.isEmpty()) {
|
||||||
// ... paint to the canvas ...
|
// ... paint to the canvas ...
|
||||||
// }
|
// }
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
template <class T>
|
template <class T>
|
||||||
class CanvasPaintT : public T {
|
class CanvasPaintT : public T {
|
||||||
public:
|
public:
|
||||||
CanvasPaintT(HWND hwnd) : hwnd_(hwnd), for_paint_(true) {
|
CanvasPaintT(HWND hwnd) : hwnd_(hwnd), for_paint_(true) {
|
||||||
initPaint(true);
|
initPaint(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), for_paint_(true) {
|
CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), for_paint_(true) {
|
||||||
initPaint(opaque);
|
initPaint(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a CanvasPaintT for the specified region that paints to the
|
// Creates a CanvasPaintT for the specified region that paints to the
|
||||||
// specified dc. This does NOT do BeginPaint/EndPaint.
|
// specified dc. This does NOT do BeginPaint/EndPaint.
|
||||||
CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h)
|
CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h)
|
||||||
: hwnd_(NULL),
|
: hwnd_(NULL),
|
||||||
paint_dc_(dc),
|
paint_dc_(dc),
|
||||||
for_paint_(false) {
|
for_paint_(false) {
|
||||||
memset(&ps_, 0, sizeof(ps_));
|
memset(&ps_, 0, sizeof(ps_));
|
||||||
ps_.rcPaint.left = x;
|
ps_.rcPaint.left = x;
|
||||||
ps_.rcPaint.right = x + w;
|
ps_.rcPaint.right = x + w;
|
||||||
ps_.rcPaint.top = y;
|
ps_.rcPaint.top = y;
|
||||||
ps_.rcPaint.bottom = y + h;
|
ps_.rcPaint.bottom = y + h;
|
||||||
init(opaque);
|
init(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~CanvasPaintT() {
|
virtual ~CanvasPaintT() {
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
restoreToCount(1);
|
restoreToCount(1);
|
||||||
// Commit the drawing to the screen
|
// Commit the drawing to the screen
|
||||||
getTopPlatformDevice().drawToHDC(paint_dc_,
|
getTopPlatformDevice().drawToHDC(paint_dc_,
|
||||||
ps_.rcPaint.left, ps_.rcPaint.top,
|
ps_.rcPaint.left, ps_.rcPaint.top,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
if (for_paint_)
|
if (for_paint_)
|
||||||
EndPaint(hwnd_, &ps_);
|
EndPaint(hwnd_, &ps_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the invalid region is empty. The caller should call this
|
// Returns true if the invalid region is empty. The caller should call this
|
||||||
// function to determine if anything needs painting.
|
// function to determine if anything needs painting.
|
||||||
bool isEmpty() const {
|
bool isEmpty() const {
|
||||||
return ps_.rcPaint.right - ps_.rcPaint.left == 0 ||
|
return ps_.rcPaint.right - ps_.rcPaint.left == 0 ||
|
||||||
ps_.rcPaint.bottom - ps_.rcPaint.top == 0;
|
ps_.rcPaint.bottom - ps_.rcPaint.top == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use to access the Windows painting parameters, especially useful for
|
// Use to access the Windows painting parameters, especially useful for
|
||||||
// getting the bounding rect for painting: paintstruct().rcPaint
|
// getting the bounding rect for painting: paintstruct().rcPaint
|
||||||
const PAINTSTRUCT& paintStruct() const {
|
const PAINTSTRUCT& paintStruct() const {
|
||||||
return ps_;
|
return ps_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the DC that will be painted to
|
// Returns the DC that will be painted to
|
||||||
HDC paintDC() const {
|
HDC paintDC() const {
|
||||||
return paint_dc_;
|
return paint_dc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HWND hwnd_;
|
HWND hwnd_;
|
||||||
HDC paint_dc_;
|
HDC paint_dc_;
|
||||||
PAINTSTRUCT ps_;
|
PAINTSTRUCT ps_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initPaint(bool opaque) {
|
void initPaint(bool opaque) {
|
||||||
paint_dc_ = BeginPaint(hwnd_, &ps_);
|
paint_dc_ = BeginPaint(hwnd_, &ps_);
|
||||||
|
|
||||||
init(opaque);
|
init(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(bool opaque) {
|
void init(bool opaque) {
|
||||||
// FIXME(brettw) for ClearType, we probably want to expand the bounds of
|
// FIXME(brettw) for ClearType, we probably want to expand the bounds of
|
||||||
// painting by one pixel so that the boundaries will be correct (ClearType
|
// painting by one pixel so that the boundaries will be correct (ClearType
|
||||||
// text can depend on the adjacent pixel). Then we would paint just the inset
|
// text can depend on the adjacent pixel). Then we would paint just the inset
|
||||||
// pixels to the screen.
|
// pixels to the screen.
|
||||||
initialize(ps_.rcPaint.right - ps_.rcPaint.left,
|
initialize(ps_.rcPaint.right - ps_.rcPaint.left,
|
||||||
ps_.rcPaint.bottom - ps_.rcPaint.top, opaque, NULL);
|
ps_.rcPaint.bottom - ps_.rcPaint.top, opaque, NULL);
|
||||||
|
|
||||||
// This will bring the canvas into the screen coordinate system for the
|
// This will bring the canvas into the screen coordinate system for the
|
||||||
// dirty rect
|
// dirty rect
|
||||||
translate(SkIntToScalar(-ps_.rcPaint.left),
|
translate(SkIntToScalar(-ps_.rcPaint.left),
|
||||||
SkIntToScalar(-ps_.rcPaint.top));
|
SkIntToScalar(-ps_.rcPaint.top));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If true, this canvas was created for a BeginPaint.
|
// If true, this canvas was created for a BeginPaint.
|
||||||
const bool for_paint_;
|
const bool for_paint_;
|
||||||
|
|
||||||
DISALLOW_EVIL_CONSTRUCTORS(CanvasPaintT);
|
DISALLOW_EVIL_CONSTRUCTORS(CanvasPaintT);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef CanvasPaintT<PlatformCanvasWin> PlatformCanvasWinPaint;
|
typedef CanvasPaintT<PlatformCanvasWin> PlatformCanvasWinPaint;
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
#endif // BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
#endif // BASE_GFX_PLATFORM_CANVAS_WIN_H__
|
||||||
|
|
||||||
|
@@ -1,229 +1,229 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "base/gfx/platform_device_win.h"
|
#include "base/gfx/platform_device_win.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/gfx/skia_utils.h"
|
#include "base/gfx/skia_utils.h"
|
||||||
#include "SkMatrix.h"
|
#include "SkMatrix.h"
|
||||||
#include "SkPath.h"
|
#include "SkPath.h"
|
||||||
#include "SkRegion.h"
|
#include "SkRegion.h"
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
PlatformDeviceWin::PlatformDeviceWin(const SkBitmap& bitmap)
|
PlatformDeviceWin::PlatformDeviceWin(const SkBitmap& bitmap)
|
||||||
: SkDevice(bitmap) {
|
: SkDevice(bitmap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PlatformDeviceWin::InitializeDC(HDC context) {
|
void PlatformDeviceWin::InitializeDC(HDC context) {
|
||||||
// Enables world transformation.
|
// Enables world transformation.
|
||||||
// If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the
|
// If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the
|
||||||
// counterclockwise direction in logical space. This is equivalent to the
|
// counterclockwise direction in logical space. This is equivalent to the
|
||||||
// statement that, in the GM_ADVANCED graphics mode, both arc control points
|
// statement that, in the GM_ADVANCED graphics mode, both arc control points
|
||||||
// and arcs themselves fully respect the device context's world-to-device
|
// and arcs themselves fully respect the device context's world-to-device
|
||||||
// transformation.
|
// transformation.
|
||||||
BOOL res = SetGraphicsMode(context, GM_ADVANCED);
|
BOOL res = SetGraphicsMode(context, GM_ADVANCED);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
|
|
||||||
// Enables dithering.
|
// Enables dithering.
|
||||||
res = SetStretchBltMode(context, HALFTONE);
|
res = SetStretchBltMode(context, HALFTONE);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
// As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called
|
// As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called
|
||||||
// right after.
|
// right after.
|
||||||
res = SetBrushOrgEx(context, 0, 0, NULL);
|
res = SetBrushOrgEx(context, 0, 0, NULL);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
|
|
||||||
// Sets up default orientation.
|
// Sets up default orientation.
|
||||||
res = SetArcDirection(context, AD_CLOCKWISE);
|
res = SetArcDirection(context, AD_CLOCKWISE);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
|
|
||||||
// Sets up default colors.
|
// Sets up default colors.
|
||||||
res = SetBkColor(context, RGB(255, 255, 255));
|
res = SetBkColor(context, RGB(255, 255, 255));
|
||||||
DCHECK_NE(res, CLR_INVALID);
|
DCHECK_NE(res, CLR_INVALID);
|
||||||
res = SetTextColor(context, RGB(0, 0, 0));
|
res = SetTextColor(context, RGB(0, 0, 0));
|
||||||
DCHECK_NE(res, CLR_INVALID);
|
DCHECK_NE(res, CLR_INVALID);
|
||||||
res = SetDCBrushColor(context, RGB(255, 255, 255));
|
res = SetDCBrushColor(context, RGB(255, 255, 255));
|
||||||
DCHECK_NE(res, CLR_INVALID);
|
DCHECK_NE(res, CLR_INVALID);
|
||||||
res = SetDCPenColor(context, RGB(0, 0, 0));
|
res = SetDCPenColor(context, RGB(0, 0, 0));
|
||||||
DCHECK_NE(res, CLR_INVALID);
|
DCHECK_NE(res, CLR_INVALID);
|
||||||
|
|
||||||
// Sets up default transparency.
|
// Sets up default transparency.
|
||||||
res = SetBkMode(context, OPAQUE);
|
res = SetBkMode(context, OPAQUE);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
res = SetROP2(context, R2_COPYPEN);
|
res = SetROP2(context, R2_COPYPEN);
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
|
void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
|
||||||
switch (path.getFillType()) {
|
switch (path.getFillType()) {
|
||||||
case SkPath::kWinding_FillType: {
|
case SkPath::kWinding_FillType: {
|
||||||
int res = SetPolyFillMode(context, WINDING);
|
int res = SetPolyFillMode(context, WINDING);
|
||||||
DCHECK(res != 0);
|
DCHECK(res != 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SkPath::kEvenOdd_FillType: {
|
case SkPath::kEvenOdd_FillType: {
|
||||||
int res = SetPolyFillMode(context, ALTERNATE);
|
int res = SetPolyFillMode(context, ALTERNATE);
|
||||||
DCHECK(res != 0);
|
DCHECK(res != 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOL res = BeginPath(context);
|
BOOL res = BeginPath(context);
|
||||||
DCHECK(res != 0);
|
DCHECK(res != 0);
|
||||||
|
|
||||||
CubicPaths paths;
|
CubicPaths paths;
|
||||||
if (!SkPathToCubicPaths(&paths, path))
|
if (!SkPathToCubicPaths(&paths, path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<POINT> points;
|
std::vector<POINT> points;
|
||||||
for (CubicPaths::const_iterator path(paths.begin()); path != paths.end();
|
for (CubicPaths::const_iterator path(paths.begin()); path != paths.end();
|
||||||
++path) {
|
++path) {
|
||||||
if (!path->size())
|
if (!path->size())
|
||||||
continue;
|
continue;
|
||||||
// DCHECK_EQ(points.size() % 4, 0);
|
// DCHECK_EQ(points.size() % 4, 0);
|
||||||
points.resize(0);
|
points.resize(0);
|
||||||
points.reserve(path->size() * 3 / 4 + 1);
|
points.reserve(path->size() * 3 / 4 + 1);
|
||||||
points.push_back(SkPointToPOINT(path->front().p[0]));
|
points.push_back(SkPointToPOINT(path->front().p[0]));
|
||||||
for (CubicPath::const_iterator point(path->begin()); point != path->end();
|
for (CubicPath::const_iterator point(path->begin()); point != path->end();
|
||||||
++point) {
|
++point) {
|
||||||
// Never add point->p[0]
|
// Never add point->p[0]
|
||||||
points.push_back(SkPointToPOINT(point->p[1]));
|
points.push_back(SkPointToPOINT(point->p[1]));
|
||||||
points.push_back(SkPointToPOINT(point->p[2]));
|
points.push_back(SkPointToPOINT(point->p[2]));
|
||||||
points.push_back(SkPointToPOINT(point->p[3]));
|
points.push_back(SkPointToPOINT(point->p[3]));
|
||||||
}
|
}
|
||||||
DCHECK_EQ((points.size() - 1) % 3, 0);
|
DCHECK_EQ((points.size() - 1) % 3, 0);
|
||||||
// This is slightly inefficient since all straight line and quadratic lines
|
// This is slightly inefficient since all straight line and quadratic lines
|
||||||
// are "upgraded" to a cubic line.
|
// are "upgraded" to a cubic line.
|
||||||
// TODO(maruel): http://b/1147346 We should use
|
// TODO(maruel): http://b/1147346 We should use
|
||||||
// PolyDraw/PolyBezier/Polyline whenever possible.
|
// PolyDraw/PolyBezier/Polyline whenever possible.
|
||||||
res = PolyBezier(context, &points.front(),
|
res = PolyBezier(context, &points.front(),
|
||||||
static_cast<DWORD>(points.size()));
|
static_cast<DWORD>(points.size()));
|
||||||
DCHECK_NE(res, 0);
|
DCHECK_NE(res, 0);
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
// Make sure the path is discarded.
|
// Make sure the path is discarded.
|
||||||
AbortPath(context);
|
AbortPath(context);
|
||||||
} else {
|
} else {
|
||||||
res = EndPath(context);
|
res = EndPath(context);
|
||||||
DCHECK(res != 0);
|
DCHECK(res != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PlatformDeviceWin::LoadTransformToDC(HDC dc, const SkMatrix& matrix) {
|
void PlatformDeviceWin::LoadTransformToDC(HDC dc, const SkMatrix& matrix) {
|
||||||
XFORM xf;
|
XFORM xf;
|
||||||
xf.eM11 = matrix[SkMatrix::kMScaleX];
|
xf.eM11 = matrix[SkMatrix::kMScaleX];
|
||||||
xf.eM21 = matrix[SkMatrix::kMSkewX];
|
xf.eM21 = matrix[SkMatrix::kMSkewX];
|
||||||
xf.eDx = matrix[SkMatrix::kMTransX];
|
xf.eDx = matrix[SkMatrix::kMTransX];
|
||||||
xf.eM12 = matrix[SkMatrix::kMSkewY];
|
xf.eM12 = matrix[SkMatrix::kMSkewY];
|
||||||
xf.eM22 = matrix[SkMatrix::kMScaleY];
|
xf.eM22 = matrix[SkMatrix::kMScaleY];
|
||||||
xf.eDy = matrix[SkMatrix::kMTransY];
|
xf.eDy = matrix[SkMatrix::kMTransY];
|
||||||
SetWorldTransform(dc, &xf);
|
SetWorldTransform(dc, &xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths,
|
bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths,
|
||||||
const SkPath& skpath) {
|
const SkPath& skpath) {
|
||||||
paths->clear();
|
paths->clear();
|
||||||
CubicPath* current_path = NULL;
|
CubicPath* current_path = NULL;
|
||||||
SkPoint current_points[4];
|
SkPoint current_points[4];
|
||||||
CubicPoints points_to_add;
|
CubicPoints points_to_add;
|
||||||
SkPath::Iter iter(skpath, false);
|
SkPath::Iter iter(skpath, false);
|
||||||
for (SkPath::Verb verb = iter.next(current_points);
|
for (SkPath::Verb verb = iter.next(current_points);
|
||||||
verb != SkPath::kDone_Verb;
|
verb != SkPath::kDone_Verb;
|
||||||
verb = iter.next(current_points)) {
|
verb = iter.next(current_points)) {
|
||||||
switch (verb) {
|
switch (verb) {
|
||||||
case SkPath::kMove_Verb: { // iter.next returns 1 point
|
case SkPath::kMove_Verb: { // iter.next returns 1 point
|
||||||
// Ignores it since the point is copied in the next operation. See
|
// Ignores it since the point is copied in the next operation. See
|
||||||
// SkPath::Iter::next() for reference.
|
// SkPath::Iter::next() for reference.
|
||||||
paths->push_back(CubicPath());
|
paths->push_back(CubicPath());
|
||||||
current_path = &paths->back();
|
current_path = &paths->back();
|
||||||
// Skip point addition.
|
// Skip point addition.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case SkPath::kLine_Verb: { // iter.next returns 2 points
|
case SkPath::kLine_Verb: { // iter.next returns 2 points
|
||||||
points_to_add.p[0] = current_points[0];
|
points_to_add.p[0] = current_points[0];
|
||||||
points_to_add.p[1] = current_points[0];
|
points_to_add.p[1] = current_points[0];
|
||||||
points_to_add.p[2] = current_points[1];
|
points_to_add.p[2] = current_points[1];
|
||||||
points_to_add.p[3] = current_points[1];
|
points_to_add.p[3] = current_points[1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SkPath::kQuad_Verb: { // iter.next returns 3 points
|
case SkPath::kQuad_Verb: { // iter.next returns 3 points
|
||||||
points_to_add.p[0] = current_points[0];
|
points_to_add.p[0] = current_points[0];
|
||||||
points_to_add.p[1] = current_points[1];
|
points_to_add.p[1] = current_points[1];
|
||||||
points_to_add.p[2] = current_points[2];
|
points_to_add.p[2] = current_points[2];
|
||||||
points_to_add.p[3] = current_points[2];
|
points_to_add.p[3] = current_points[2];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SkPath::kCubic_Verb: { // iter.next returns 4 points
|
case SkPath::kCubic_Verb: { // iter.next returns 4 points
|
||||||
points_to_add.p[0] = current_points[0];
|
points_to_add.p[0] = current_points[0];
|
||||||
points_to_add.p[1] = current_points[1];
|
points_to_add.p[1] = current_points[1];
|
||||||
points_to_add.p[2] = current_points[2];
|
points_to_add.p[2] = current_points[2];
|
||||||
points_to_add.p[3] = current_points[3];
|
points_to_add.p[3] = current_points[3];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point)
|
case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point)
|
||||||
paths->push_back(CubicPath());
|
paths->push_back(CubicPath());
|
||||||
current_path = &paths->back();
|
current_path = &paths->back();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case SkPath::kDone_Verb: // iter.next returns 0 points
|
case SkPath::kDone_Verb: // iter.next returns 0 points
|
||||||
default: {
|
default: {
|
||||||
current_path = NULL;
|
current_path = NULL;
|
||||||
// Will return false.
|
// Will return false.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DCHECK(current_path);
|
DCHECK(current_path);
|
||||||
if (!current_path) {
|
if (!current_path) {
|
||||||
paths->clear();
|
paths->clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
current_path->push_back(points_to_add);
|
current_path->push_back(points_to_add);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PlatformDeviceWin::LoadClippingRegionToDC(HDC context,
|
void PlatformDeviceWin::LoadClippingRegionToDC(HDC context,
|
||||||
const SkRegion& region,
|
const SkRegion& region,
|
||||||
const SkMatrix& transformation) {
|
const SkMatrix& transformation) {
|
||||||
HRGN hrgn;
|
HRGN hrgn;
|
||||||
if (region.isEmpty()) {
|
if (region.isEmpty()) {
|
||||||
// region can be empty, in which case everything will be clipped.
|
// region can be empty, in which case everything will be clipped.
|
||||||
hrgn = CreateRectRgn(0, 0, 0, 0);
|
hrgn = CreateRectRgn(0, 0, 0, 0);
|
||||||
} else if (region.isRect()) {
|
} else if (region.isRect()) {
|
||||||
// Do the transformation.
|
// Do the transformation.
|
||||||
SkRect rect;
|
SkRect rect;
|
||||||
rect.set(region.getBounds());
|
rect.set(region.getBounds());
|
||||||
transformation.mapRect(&rect);
|
transformation.mapRect(&rect);
|
||||||
SkIRect irect;
|
SkIRect irect;
|
||||||
rect.round(&irect);
|
rect.round(&irect);
|
||||||
hrgn = CreateRectRgnIndirect(&SkIRectToRECT(irect));
|
hrgn = CreateRectRgnIndirect(&SkIRectToRECT(irect));
|
||||||
} else {
|
} else {
|
||||||
// It is complex.
|
// It is complex.
|
||||||
SkPath path;
|
SkPath path;
|
||||||
region.getBoundaryPath(&path);
|
region.getBoundaryPath(&path);
|
||||||
// Clip. Note that windows clipping regions are not affected by the
|
// Clip. Note that windows clipping regions are not affected by the
|
||||||
// transform so apply it manually.
|
// transform so apply it manually.
|
||||||
path.transform(transformation);
|
path.transform(transformation);
|
||||||
LoadPathToDC(context, path);
|
LoadPathToDC(context, path);
|
||||||
hrgn = PathToRegion(context);
|
hrgn = PathToRegion(context);
|
||||||
}
|
}
|
||||||
int result = SelectClipRgn(context, hrgn);
|
int result = SelectClipRgn(context, hrgn);
|
||||||
DCHECK_NE(result, ERROR);
|
DCHECK_NE(result, ERROR);
|
||||||
result = DeleteObject(hrgn);
|
result = DeleteObject(hrgn);
|
||||||
DCHECK_NE(result, 0);
|
DCHECK_NE(result, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
|
@@ -1,96 +1,96 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
#ifndef BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
||||||
#define BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
#define BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
|
|
||||||
class SkMatrix;
|
class SkMatrix;
|
||||||
class SkPath;
|
class SkPath;
|
||||||
class SkRegion;
|
class SkRegion;
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
// A device is basically a wrapper around SkBitmap that provides a surface for
|
// A device is basically a wrapper around SkBitmap that provides a surface for
|
||||||
// SkCanvas to draw into. Our device provides a surface Windows can also write
|
// SkCanvas to draw into. Our device provides a surface Windows can also write
|
||||||
// to. It also provides functionality to play well with GDI drawing functions.
|
// to. It also provides functionality to play well with GDI drawing functions.
|
||||||
// This class is abstract and must be subclassed. It provides the basic
|
// This class is abstract and must be subclassed. It provides the basic
|
||||||
// interface to implement it either with or without a bitmap backend.
|
// interface to implement it either with or without a bitmap backend.
|
||||||
class PlatformDeviceWin : public SkDevice {
|
class PlatformDeviceWin : public SkDevice {
|
||||||
public:
|
public:
|
||||||
// The DC that corresponds to the bitmap, used for GDI operations drawing
|
// The DC that corresponds to the bitmap, used for GDI operations drawing
|
||||||
// into the bitmap. This is possibly heavyweight, so it should be existant
|
// into the bitmap. This is possibly heavyweight, so it should be existant
|
||||||
// only during one pass of rendering.
|
// only during one pass of rendering.
|
||||||
virtual HDC getBitmapDC() = 0;
|
virtual HDC getBitmapDC() = 0;
|
||||||
|
|
||||||
// Draws to the given screen DC, if the bitmap DC doesn't exist, this will
|
// Draws to the given screen DC, if the bitmap DC doesn't exist, this will
|
||||||
// temporarily create it. However, if you have created the bitmap DC, it will
|
// temporarily create it. However, if you have created the bitmap DC, it will
|
||||||
// be more efficient if you don't free it until after this call so it doesn't
|
// be more efficient if you don't free it until after this call so it doesn't
|
||||||
// have to be created twice. If src_rect is null, then the entirety of the
|
// have to be created twice. If src_rect is null, then the entirety of the
|
||||||
// source device will be copied.
|
// source device will be copied.
|
||||||
virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect) = 0;
|
virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect) = 0;
|
||||||
|
|
||||||
// Invoke before using GDI functions. See description in platform_device.cc
|
// Invoke before using GDI functions. See description in platform_device.cc
|
||||||
// for specifics.
|
// for specifics.
|
||||||
// NOTE: x,y,width and height are relative to the current transform.
|
// NOTE: x,y,width and height are relative to the current transform.
|
||||||
virtual void prepareForGDI(int x, int y, int width, int height) { }
|
virtual void prepareForGDI(int x, int y, int width, int height) { }
|
||||||
|
|
||||||
// Invoke after using GDI functions. See description in platform_device.cc
|
// Invoke after using GDI functions. See description in platform_device.cc
|
||||||
// for specifics.
|
// for specifics.
|
||||||
// NOTE: x,y,width and height are relative to the current transform.
|
// NOTE: x,y,width and height are relative to the current transform.
|
||||||
virtual void postProcessGDI(int x, int y, int width, int height) { }
|
virtual void postProcessGDI(int x, int y, int width, int height) { }
|
||||||
|
|
||||||
// Sets the opacity of each pixel in the specified region to be opaque.
|
// Sets the opacity of each pixel in the specified region to be opaque.
|
||||||
virtual void makeOpaque(int x, int y, int width, int height) { }
|
virtual void makeOpaque(int x, int y, int width, int height) { }
|
||||||
|
|
||||||
// Call this function to fix the alpha channels before compositing this layer
|
// Call this function to fix the alpha channels before compositing this layer
|
||||||
// onto another. Internally, the device uses a special alpha method to work
|
// onto another. Internally, the device uses a special alpha method to work
|
||||||
// around problems with Windows. This call will put the values into what
|
// around problems with Windows. This call will put the values into what
|
||||||
// Skia expects, so it can be composited onto other layers.
|
// Skia expects, so it can be composited onto other layers.
|
||||||
//
|
//
|
||||||
// After this call, no more drawing can be done because the
|
// After this call, no more drawing can be done because the
|
||||||
// alpha channels will be "correct", which, if this function is called again
|
// alpha channels will be "correct", which, if this function is called again
|
||||||
// will make them wrong. See the implementation for more discussion.
|
// will make them wrong. See the implementation for more discussion.
|
||||||
virtual void fixupAlphaBeforeCompositing() { }
|
virtual void fixupAlphaBeforeCompositing() { }
|
||||||
|
|
||||||
// Returns if the preferred rendering engine is vectorial or bitmap based.
|
// Returns if the preferred rendering engine is vectorial or bitmap based.
|
||||||
virtual bool IsVectorial() = 0;
|
virtual bool IsVectorial() = 0;
|
||||||
|
|
||||||
// Initializes the default settings and colors in a device context.
|
// Initializes the default settings and colors in a device context.
|
||||||
static void InitializeDC(HDC context);
|
static void InitializeDC(HDC context);
|
||||||
|
|
||||||
// Loads a SkPath into the GDI context. The path can there after be used for
|
// Loads a SkPath into the GDI context. The path can there after be used for
|
||||||
// clipping or as a stroke.
|
// clipping or as a stroke.
|
||||||
static void LoadPathToDC(HDC context, const SkPath& path);
|
static void LoadPathToDC(HDC context, const SkPath& path);
|
||||||
|
|
||||||
// Loads a SkRegion into the GDI context.
|
// Loads a SkRegion into the GDI context.
|
||||||
static void LoadClippingRegionToDC(HDC context, const SkRegion& region,
|
static void LoadClippingRegionToDC(HDC context, const SkRegion& region,
|
||||||
const SkMatrix& transformation);
|
const SkMatrix& transformation);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Arrays must be inside structures.
|
// Arrays must be inside structures.
|
||||||
struct CubicPoints {
|
struct CubicPoints {
|
||||||
SkPoint p[4];
|
SkPoint p[4];
|
||||||
};
|
};
|
||||||
typedef std::vector<CubicPoints> CubicPath;
|
typedef std::vector<CubicPoints> CubicPath;
|
||||||
typedef std::vector<CubicPath> CubicPaths;
|
typedef std::vector<CubicPath> CubicPaths;
|
||||||
|
|
||||||
// Forwards |bitmap| to SkDevice's constructor.
|
// Forwards |bitmap| to SkDevice's constructor.
|
||||||
PlatformDeviceWin(const SkBitmap& bitmap);
|
PlatformDeviceWin(const SkBitmap& bitmap);
|
||||||
|
|
||||||
// Loads the specified Skia transform into the device context, excluding
|
// Loads the specified Skia transform into the device context, excluding
|
||||||
// perspective (which GDI doesn't support).
|
// perspective (which GDI doesn't support).
|
||||||
static void LoadTransformToDC(HDC dc, const SkMatrix& matrix);
|
static void LoadTransformToDC(HDC dc, const SkMatrix& matrix);
|
||||||
|
|
||||||
// Transforms SkPath's paths into a series of cubic path.
|
// Transforms SkPath's paths into a series of cubic path.
|
||||||
static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
|
static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
||||||
#endif // BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
#endif // BASE_GFX_PLATFORM_DEVICE_WIN_H__
|
||||||
|
|
||||||
|
@@ -1,80 +1,80 @@
|
|||||||
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
# Ripped and modded from chrome.
|
# Ripped and modded from chrome.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Replace(
|
env.Replace(
|
||||||
LIBGD_DIR = '$THIRD_PARTY_DIR/libgd',
|
LIBGD_DIR = '$THIRD_PARTY_DIR/libgd',
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$LIBGD_DIR',
|
'$LIBGD_DIR',
|
||||||
'$THIRD_PARTY_DIR/libjpeg',
|
'$THIRD_PARTY_DIR/libjpeg',
|
||||||
'$THIRD_PARTY_DIR/libpng',
|
'$THIRD_PARTY_DIR/libpng',
|
||||||
'$THIRD_PARTY_DIR/zlib',
|
'$THIRD_PARTY_DIR/zlib',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPDEFINES = [
|
CPPDEFINES = [
|
||||||
'HAVE_CONFIG_H',
|
'HAVE_CONFIG_H',
|
||||||
'BGDWIN32',
|
'BGDWIN32',
|
||||||
],
|
],
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPFLAGS = [
|
CPPFLAGS = [
|
||||||
# Disable some warnings when building third-party code, so we can enable /WX.
|
# Disable some warnings when building third-party code, so we can enable /WX.
|
||||||
# Examples:
|
# Examples:
|
||||||
# warning C4244: conversion from 'type1' to 'type2', possible loss of data
|
# warning C4244: conversion from 'type1' to 'type2', possible loss of data
|
||||||
# warning C4018: signed/unsigned mismatch in comparison
|
# warning C4018: signed/unsigned mismatch in comparison
|
||||||
# warning C4003: not enough actual parameters for macro
|
# warning C4003: not enough actual parameters for macro
|
||||||
'/wd4244',
|
'/wd4244',
|
||||||
'/wd4996',
|
'/wd4996',
|
||||||
'/wd4005',
|
'/wd4005',
|
||||||
'/wd4142',
|
'/wd4142',
|
||||||
'/wd4018',
|
'/wd4018',
|
||||||
'/wd4133',
|
'/wd4133',
|
||||||
'/wd4102',
|
'/wd4102',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'$LIBGD_DIR/gd.c',
|
'$LIBGD_DIR/gd.c',
|
||||||
'$LIBGD_DIR/gdfx.c',
|
'$LIBGD_DIR/gdfx.c',
|
||||||
'$LIBGD_DIR/gd_security.c',
|
'$LIBGD_DIR/gd_security.c',
|
||||||
'$LIBGD_DIR/gd_gd.c',
|
'$LIBGD_DIR/gd_gd.c',
|
||||||
'$LIBGD_DIR/gd_gd2.c',
|
'$LIBGD_DIR/gd_gd2.c',
|
||||||
'$LIBGD_DIR/gd_io.c',
|
'$LIBGD_DIR/gd_io.c',
|
||||||
'$LIBGD_DIR/gd_io_dp.c',
|
'$LIBGD_DIR/gd_io_dp.c',
|
||||||
'$LIBGD_DIR/gd_gif_in.c',
|
'$LIBGD_DIR/gd_gif_in.c',
|
||||||
'$LIBGD_DIR/gd_gif_out.c',
|
'$LIBGD_DIR/gd_gif_out.c',
|
||||||
'$LIBGD_DIR/gd_io_file.c',
|
'$LIBGD_DIR/gd_io_file.c',
|
||||||
'$LIBGD_DIR/gd_io_ss.c',
|
'$LIBGD_DIR/gd_io_ss.c',
|
||||||
'$LIBGD_DIR/gd_jpeg.c',
|
'$LIBGD_DIR/gd_jpeg.c',
|
||||||
'$LIBGD_DIR/gd_png.c',
|
'$LIBGD_DIR/gd_png.c',
|
||||||
'$LIBGD_DIR/gd_ss.c',
|
'$LIBGD_DIR/gd_ss.c',
|
||||||
'$LIBGD_DIR/gd_topal.c',
|
'$LIBGD_DIR/gd_topal.c',
|
||||||
'$LIBGD_DIR/gd_wbmp.c',
|
'$LIBGD_DIR/gd_wbmp.c',
|
||||||
'$LIBGD_DIR/gdcache.c',
|
'$LIBGD_DIR/gdcache.c',
|
||||||
'$LIBGD_DIR/gdfontg.c',
|
'$LIBGD_DIR/gdfontg.c',
|
||||||
'$LIBGD_DIR/gdfontl.c',
|
'$LIBGD_DIR/gdfontl.c',
|
||||||
'$LIBGD_DIR/gdfontmb.c',
|
'$LIBGD_DIR/gdfontmb.c',
|
||||||
'$LIBGD_DIR/gdfonts.c',
|
'$LIBGD_DIR/gdfonts.c',
|
||||||
'$LIBGD_DIR/gdfontt.c',
|
'$LIBGD_DIR/gdfontt.c',
|
||||||
'$LIBGD_DIR/gdft.c',
|
'$LIBGD_DIR/gdft.c',
|
||||||
'$LIBGD_DIR/gdhelpers.c',
|
'$LIBGD_DIR/gdhelpers.c',
|
||||||
'$LIBGD_DIR/gdkanji.c',
|
'$LIBGD_DIR/gdkanji.c',
|
||||||
'$LIBGD_DIR/gdtables.c',
|
'$LIBGD_DIR/gdtables.c',
|
||||||
'$LIBGD_DIR/gdxpm.c',
|
'$LIBGD_DIR/gdxpm.c',
|
||||||
'$LIBGD_DIR/wbmp.c',
|
'$LIBGD_DIR/wbmp.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('gd', input_files)
|
env.ChromeStaticLibrary('gd', input_files)
|
||||||
|
@@ -1,74 +1,74 @@
|
|||||||
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
# Ripped and modded from chrome.
|
# Ripped and modded from chrome.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
LIBJPEG_DIR = ''
|
LIBJPEG_DIR = ''
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Replace(
|
env.Replace(
|
||||||
LIBJPEG_DIR = '$THIRD_PARTY_DIR/libjpeg',
|
LIBJPEG_DIR = '$THIRD_PARTY_DIR/libjpeg',
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$LIBJPEG_DIR',
|
'$LIBJPEG_DIR',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
#env.Append(
|
#env.Append(
|
||||||
# CPPDEFINES = [
|
# CPPDEFINES = [
|
||||||
# ],
|
# ],
|
||||||
#)
|
#)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'$LIBJPEG_DIR/jcapimin.c',
|
'$LIBJPEG_DIR/jcapimin.c',
|
||||||
'$LIBJPEG_DIR/jcapistd.c',
|
'$LIBJPEG_DIR/jcapistd.c',
|
||||||
'$LIBJPEG_DIR/jccoefct.c',
|
'$LIBJPEG_DIR/jccoefct.c',
|
||||||
'$LIBJPEG_DIR/jccolor.c',
|
'$LIBJPEG_DIR/jccolor.c',
|
||||||
'$LIBJPEG_DIR/jcdctmgr.c',
|
'$LIBJPEG_DIR/jcdctmgr.c',
|
||||||
'$LIBJPEG_DIR/jchuff.c',
|
'$LIBJPEG_DIR/jchuff.c',
|
||||||
'$LIBJPEG_DIR/jcinit.c',
|
'$LIBJPEG_DIR/jcinit.c',
|
||||||
'$LIBJPEG_DIR/jcmainct.c',
|
'$LIBJPEG_DIR/jcmainct.c',
|
||||||
'$LIBJPEG_DIR/jcmarker.c',
|
'$LIBJPEG_DIR/jcmarker.c',
|
||||||
'$LIBJPEG_DIR/jcmaster.c',
|
'$LIBJPEG_DIR/jcmaster.c',
|
||||||
'$LIBJPEG_DIR/jcomapi.c',
|
'$LIBJPEG_DIR/jcomapi.c',
|
||||||
'$LIBJPEG_DIR/jcparam.c',
|
'$LIBJPEG_DIR/jcparam.c',
|
||||||
'$LIBJPEG_DIR/jcphuff.c',
|
'$LIBJPEG_DIR/jcphuff.c',
|
||||||
'$LIBJPEG_DIR/jcprepct.c',
|
'$LIBJPEG_DIR/jcprepct.c',
|
||||||
'$LIBJPEG_DIR/jcsample.c',
|
'$LIBJPEG_DIR/jcsample.c',
|
||||||
'$LIBJPEG_DIR/jctrans.c',
|
'$LIBJPEG_DIR/jctrans.c',
|
||||||
'$LIBJPEG_DIR/jdapimin.c',
|
'$LIBJPEG_DIR/jdapimin.c',
|
||||||
'$LIBJPEG_DIR/jdapistd.c',
|
'$LIBJPEG_DIR/jdapistd.c',
|
||||||
'$LIBJPEG_DIR/jdatadst.c',
|
'$LIBJPEG_DIR/jdatadst.c',
|
||||||
'$LIBJPEG_DIR/jdatasrc.c',
|
'$LIBJPEG_DIR/jdatasrc.c',
|
||||||
'$LIBJPEG_DIR/jdcoefct.c',
|
'$LIBJPEG_DIR/jdcoefct.c',
|
||||||
'$LIBJPEG_DIR/jdcolor.c',
|
'$LIBJPEG_DIR/jdcolor.c',
|
||||||
'$LIBJPEG_DIR/jddctmgr.c',
|
'$LIBJPEG_DIR/jddctmgr.c',
|
||||||
'$LIBJPEG_DIR/jdhuff.c',
|
'$LIBJPEG_DIR/jdhuff.c',
|
||||||
'$LIBJPEG_DIR/jdinput.c',
|
'$LIBJPEG_DIR/jdinput.c',
|
||||||
'$LIBJPEG_DIR/jdmainct.c',
|
'$LIBJPEG_DIR/jdmainct.c',
|
||||||
'$LIBJPEG_DIR/jdmarker.c',
|
'$LIBJPEG_DIR/jdmarker.c',
|
||||||
'$LIBJPEG_DIR/jdmaster.c',
|
'$LIBJPEG_DIR/jdmaster.c',
|
||||||
'$LIBJPEG_DIR/jdmerge.c',
|
'$LIBJPEG_DIR/jdmerge.c',
|
||||||
'$LIBJPEG_DIR/jdphuff.c',
|
'$LIBJPEG_DIR/jdphuff.c',
|
||||||
'$LIBJPEG_DIR/jdpostct.c',
|
'$LIBJPEG_DIR/jdpostct.c',
|
||||||
'$LIBJPEG_DIR/jdsample.c',
|
'$LIBJPEG_DIR/jdsample.c',
|
||||||
'$LIBJPEG_DIR/jdtrans.c',
|
'$LIBJPEG_DIR/jdtrans.c',
|
||||||
'$LIBJPEG_DIR/jerror.c',
|
'$LIBJPEG_DIR/jerror.c',
|
||||||
'$LIBJPEG_DIR/jfdctflt.c',
|
'$LIBJPEG_DIR/jfdctflt.c',
|
||||||
'$LIBJPEG_DIR/jfdctfst.c',
|
'$LIBJPEG_DIR/jfdctfst.c',
|
||||||
'$LIBJPEG_DIR/jfdctint.c',
|
'$LIBJPEG_DIR/jfdctint.c',
|
||||||
'$LIBJPEG_DIR/jidctflt.c',
|
'$LIBJPEG_DIR/jidctflt.c',
|
||||||
'$LIBJPEG_DIR/jidctfst.c',
|
'$LIBJPEG_DIR/jidctfst.c',
|
||||||
'$LIBJPEG_DIR/jidctint.c',
|
'$LIBJPEG_DIR/jidctint.c',
|
||||||
'$LIBJPEG_DIR/jidctred.c',
|
'$LIBJPEG_DIR/jidctred.c',
|
||||||
'$LIBJPEG_DIR/jquant1.c',
|
'$LIBJPEG_DIR/jquant1.c',
|
||||||
'$LIBJPEG_DIR/jquant2.c',
|
'$LIBJPEG_DIR/jquant2.c',
|
||||||
'$LIBJPEG_DIR/jutils.c',
|
'$LIBJPEG_DIR/jutils.c',
|
||||||
'$LIBJPEG_DIR/jmemmgr.c',
|
'$LIBJPEG_DIR/jmemmgr.c',
|
||||||
'$LIBJPEG_DIR/jmemnobs.c',
|
'$LIBJPEG_DIR/jmemnobs.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('jpeg', input_files)
|
env.ChromeStaticLibrary('jpeg', input_files)
|
||||||
|
@@ -1,52 +1,52 @@
|
|||||||
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
# Ripped and modded from chrome.
|
# Ripped and modded from chrome.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Replace(
|
env.Replace(
|
||||||
LIBPNG_DIR = '$THIRD_PARTY_DIR/libpng',
|
LIBPNG_DIR = '$THIRD_PARTY_DIR/libpng',
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$LIBPNG_DIR',
|
'$LIBPNG_DIR',
|
||||||
'$THIRD_PARTY_DIR/zlib',
|
'$THIRD_PARTY_DIR/zlib',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPDEFINES = [
|
CPPDEFINES = [
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
# Common Files
|
# Common Files
|
||||||
'$LIBPNG_DIR/png.c',
|
'$LIBPNG_DIR/png.c',
|
||||||
'$LIBPNG_DIR/pngerror.c',
|
'$LIBPNG_DIR/pngerror.c',
|
||||||
'$LIBPNG_DIR/pngget.c',
|
'$LIBPNG_DIR/pngget.c',
|
||||||
'$LIBPNG_DIR/pngmem.c',
|
'$LIBPNG_DIR/pngmem.c',
|
||||||
'$LIBPNG_DIR/pngset.c',
|
'$LIBPNG_DIR/pngset.c',
|
||||||
'$LIBPNG_DIR/pngtrans.c',
|
'$LIBPNG_DIR/pngtrans.c',
|
||||||
|
|
||||||
# Reading PNGs
|
# Reading PNGs
|
||||||
'$LIBPNG_DIR/pngpread.c',
|
'$LIBPNG_DIR/pngpread.c',
|
||||||
'$LIBPNG_DIR/pngread.c',
|
'$LIBPNG_DIR/pngread.c',
|
||||||
'$LIBPNG_DIR/pngrio.c',
|
'$LIBPNG_DIR/pngrio.c',
|
||||||
'$LIBPNG_DIR/pngrtran.c',
|
'$LIBPNG_DIR/pngrtran.c',
|
||||||
'$LIBPNG_DIR/pngrutil.c',
|
'$LIBPNG_DIR/pngrutil.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
# The following files are not yet needed; exclude them to save size.
|
# The following files are not yet needed; exclude them to save size.
|
||||||
if not env['OFFICIAL_BUILD']:
|
if not env['OFFICIAL_BUILD']:
|
||||||
input_files += [
|
input_files += [
|
||||||
# Writing PNGs
|
# Writing PNGs
|
||||||
'$LIBPNG_DIR/pngwio.c',
|
'$LIBPNG_DIR/pngwio.c',
|
||||||
'$LIBPNG_DIR/pngwrite.c',
|
'$LIBPNG_DIR/pngwrite.c',
|
||||||
'$LIBPNG_DIR/pngwtran.c',
|
'$LIBPNG_DIR/pngwtran.c',
|
||||||
'$LIBPNG_DIR/pngwutil.c',
|
'$LIBPNG_DIR/pngwutil.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('png', input_files)
|
env.ChromeStaticLibrary('png', input_files)
|
||||||
|
@@ -1,51 +1,51 @@
|
|||||||
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Replace(
|
env.Replace(
|
||||||
PA_DIR = '$THIRD_PARTY_DIR/portaudio',
|
PA_DIR = '$THIRD_PARTY_DIR/portaudio',
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$PA_DIR/include',
|
'$PA_DIR/include',
|
||||||
'$PA_DIR/src/common',
|
'$PA_DIR/src/common',
|
||||||
'$PA_DIR/src/os/win',
|
'$PA_DIR/src/os/win',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPDEFINES = [
|
CPPDEFINES = [
|
||||||
'PA_NO_DS',
|
'PA_NO_DS',
|
||||||
'PA_NO_ASIO',
|
'PA_NO_ASIO',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPFLAGS = [
|
CPPFLAGS = [
|
||||||
'/wd4133',
|
'/wd4133',
|
||||||
'/wd4101',
|
'/wd4101',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'$PA_DIR/src/common/pa_allocation.c',
|
'$PA_DIR/src/common/pa_allocation.c',
|
||||||
'$PA_DIR/src/common/pa_converters.c',
|
'$PA_DIR/src/common/pa_converters.c',
|
||||||
'$PA_DIR/src/common/pa_cpuload.c',
|
'$PA_DIR/src/common/pa_cpuload.c',
|
||||||
'$PA_DIR/src/common/pa_debugprint.c',
|
'$PA_DIR/src/common/pa_debugprint.c',
|
||||||
'$PA_DIR/src/common/pa_dither.c',
|
'$PA_DIR/src/common/pa_dither.c',
|
||||||
'$PA_DIR/src/common/pa_front.c',
|
'$PA_DIR/src/common/pa_front.c',
|
||||||
'$PA_DIR/src/common/pa_process.c',
|
'$PA_DIR/src/common/pa_process.c',
|
||||||
'$PA_DIR/src/common/pa_skeleton.c',
|
'$PA_DIR/src/common/pa_skeleton.c',
|
||||||
'$PA_DIR/src/common/pa_stream.c',
|
'$PA_DIR/src/common/pa_stream.c',
|
||||||
'$PA_DIR/src/common/pa_trace.c',
|
'$PA_DIR/src/common/pa_trace.c',
|
||||||
'$PA_DIR/src/hostapi/wmme/pa_win_wmme.c',
|
'$PA_DIR/src/hostapi/wmme/pa_win_wmme.c',
|
||||||
'$PA_DIR/src/os/win/pa_win_hostapis.c',
|
'$PA_DIR/src/os/win/pa_win_hostapis.c',
|
||||||
'$PA_DIR/src/os/win/pa_win_util.c',
|
'$PA_DIR/src/os/win/pa_win_util.c',
|
||||||
'$PA_DIR/src/os/win/pa_win_waveformat.c',
|
'$PA_DIR/src/os/win/pa_win_waveformat.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('portaudio', input_files)
|
env.ChromeStaticLibrary('portaudio', input_files)
|
||||||
|
@@ -1,47 +1,47 @@
|
|||||||
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
# Ripped and modded from chrome.
|
# Ripped and modded from chrome.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Replace(
|
env.Replace(
|
||||||
ZLIB_DIR = '$THIRD_PARTY_DIR/zlib',
|
ZLIB_DIR = '$THIRD_PARTY_DIR/zlib',
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$ZLIB_DIR',
|
'$ZLIB_DIR',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
#env.Append(
|
#env.Append(
|
||||||
# CPPDEFINES = [
|
# CPPDEFINES = [
|
||||||
# ],
|
# ],
|
||||||
#)
|
#)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
# Common Files
|
# Common Files
|
||||||
'$ZLIB_DIR/adler32.c',
|
'$ZLIB_DIR/adler32.c',
|
||||||
'$ZLIB_DIR/zutil.c',
|
'$ZLIB_DIR/zutil.c',
|
||||||
# Inflate Algorithm (use inflate or infback, but not both)
|
# Inflate Algorithm (use inflate or infback, but not both)
|
||||||
'$ZLIB_DIR/inflate.c',
|
'$ZLIB_DIR/inflate.c',
|
||||||
'$ZLIB_DIR/inffast.c',
|
'$ZLIB_DIR/inffast.c',
|
||||||
'$ZLIB_DIR/inftrees.c',
|
'$ZLIB_DIR/inftrees.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
# The following files are not yet needed; exclude them to save size.
|
# The following files are not yet needed; exclude them to save size.
|
||||||
if not env['OFFICIAL_BUILD']:
|
if not env['OFFICIAL_BUILD']:
|
||||||
input_files += [
|
input_files += [
|
||||||
# Other Algorithms
|
# Other Algorithms
|
||||||
'$ZLIB_DIR/compress.c',
|
'$ZLIB_DIR/compress.c',
|
||||||
'$ZLIB_DIR/deflate.c',
|
'$ZLIB_DIR/deflate.c',
|
||||||
'$ZLIB_DIR/uncompr.c',
|
'$ZLIB_DIR/uncompr.c',
|
||||||
# Other Common Files
|
# Other Common Files
|
||||||
'$ZLIB_DIR/crc32.c',
|
'$ZLIB_DIR/crc32.c',
|
||||||
'$ZLIB_DIR/gzio.c',
|
'$ZLIB_DIR/gzio.c',
|
||||||
'$ZLIB_DIR/trees.c',
|
'$ZLIB_DIR/trees.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('zlib-gears', input_files)
|
env.ChromeStaticLibrary('zlib-gears', input_files)
|
||||||
|
@@ -1,34 +1,34 @@
|
|||||||
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
# 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
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone()
|
env = env.Clone()
|
||||||
|
|
||||||
env.Prepend(
|
env.Prepend(
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$GTEST_DIR',
|
'$GTEST_DIR',
|
||||||
'$GTEST_DIR/include',
|
'$GTEST_DIR/include',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
env.Append(
|
env.Append(
|
||||||
CCFLAGS = [
|
CCFLAGS = [
|
||||||
'/TP',
|
'/TP',
|
||||||
|
|
||||||
'/WX',
|
'/WX',
|
||||||
'/Wp64',
|
'/Wp64',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'gtest/src/gtest-death-test.cc',
|
'gtest/src/gtest-death-test.cc',
|
||||||
'gtest/src/gtest-filepath.cc',
|
'gtest/src/gtest-filepath.cc',
|
||||||
'gtest/src/gtest-port.cc',
|
'gtest/src/gtest-port.cc',
|
||||||
'gtest/src/gtest.cc',
|
'gtest/src/gtest.cc',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('gtest', input_files)
|
env.ChromeStaticLibrary('gtest', input_files)
|
||||||
|
|
||||||
|
@@ -1,269 +1,269 @@
|
|||||||
#!/bin/env python
|
#!/bin/env python
|
||||||
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
# 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
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
|
||||||
"""Module to setup and generate code coverage data
|
"""Module to setup and generate code coverage data
|
||||||
|
|
||||||
This module first sets up the environment for code coverage, instruments the
|
This module first sets up the environment for code coverage, instruments the
|
||||||
binaries, runs the tests and collects the code coverage data.
|
binaries, runs the tests and collects the code coverage data.
|
||||||
|
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
coverage.py --upload=<upload_location>
|
coverage.py --upload=<upload_location>
|
||||||
--revision=<revision_number>
|
--revision=<revision_number>
|
||||||
--src_root=<root_of_source_tree>
|
--src_root=<root_of_source_tree>
|
||||||
[--tools_path=<tools_path>]
|
[--tools_path=<tools_path>]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import google.logging_utils
|
import google.logging_utils
|
||||||
import google.process_utils as proc
|
import google.process_utils as proc
|
||||||
|
|
||||||
|
|
||||||
# The list of binaries that will be instrumented for code coverage
|
# The list of binaries that will be instrumented for code coverage
|
||||||
# TODO(niranjan): Add a complete list of binaries
|
# TODO(niranjan): Add a complete list of binaries
|
||||||
windows_binaries = ['unit_tests.exe',
|
windows_binaries = ['unit_tests.exe',
|
||||||
'ui_tests.exe']
|
'ui_tests.exe']
|
||||||
|
|
||||||
# The list of tests that will be run
|
# The list of tests that will be run
|
||||||
#TODO(niranjan): Add more tests
|
#TODO(niranjan): Add more tests
|
||||||
windows_tests = ['unit_tests.exe',
|
windows_tests = ['unit_tests.exe',
|
||||||
'ui_tests.exe']
|
'ui_tests.exe']
|
||||||
|
|
||||||
|
|
||||||
def IsWindows():
|
def IsWindows():
|
||||||
"""Checks if the current platform is Windows.
|
"""Checks if the current platform is Windows.
|
||||||
"""
|
"""
|
||||||
return sys.platform[:3] == 'win'
|
return sys.platform[:3] == 'win'
|
||||||
|
|
||||||
|
|
||||||
class Coverage(object):
|
class Coverage(object):
|
||||||
"""Class to set up and generate code coverage.
|
"""Class to set up and generate code coverage.
|
||||||
|
|
||||||
This class contains methods that are useful to set up the environment for
|
This class contains methods that are useful to set up the environment for
|
||||||
code coverage.
|
code coverage.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
instrumented: A boolean indicating if all the binaries have been
|
instrumented: A boolean indicating if all the binaries have been
|
||||||
instrumented.
|
instrumented.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
revision,
|
revision,
|
||||||
vsts_path = None,
|
vsts_path = None,
|
||||||
lcov_converter_path = None):
|
lcov_converter_path = None):
|
||||||
google.logging_utils.config_root()
|
google.logging_utils.config_root()
|
||||||
self.revision = revision
|
self.revision = revision
|
||||||
self.instrumented = False
|
self.instrumented = False
|
||||||
self.vsts_path = vsts_path
|
self.vsts_path = vsts_path
|
||||||
self.lcov_converter_path = lcov_converter_path
|
self.lcov_converter_path = lcov_converter_path
|
||||||
self._dir = None
|
self._dir = None
|
||||||
|
|
||||||
|
|
||||||
def SetUp(self, binaries):
|
def SetUp(self, binaries):
|
||||||
"""Set up the platform specific environment and instrument the binaries for
|
"""Set up the platform specific environment and instrument the binaries for
|
||||||
coverage.
|
coverage.
|
||||||
|
|
||||||
This method sets up the environment, instruments all the compiled binaries
|
This method sets up the environment, instruments all the compiled binaries
|
||||||
and sets up the code coverage counters.
|
and sets up the code coverage counters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
binaries: List of binaries that need to be instrumented.
|
binaries: List of binaries that need to be instrumented.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Path of the file containing code coverage data on successful
|
Path of the file containing code coverage data on successful
|
||||||
instrumentation.
|
instrumentation.
|
||||||
None on error.
|
None on error.
|
||||||
"""
|
"""
|
||||||
if self.instrumented:
|
if self.instrumented:
|
||||||
logging.error('Binaries already instrumented')
|
logging.error('Binaries already instrumented')
|
||||||
return None
|
return None
|
||||||
coverage_file = None
|
coverage_file = None
|
||||||
if IsWindows():
|
if IsWindows():
|
||||||
# Stop all previous instance of VSPerfMon counters
|
# Stop all previous instance of VSPerfMon counters
|
||||||
counters_command = ('%s -shutdown' %
|
counters_command = ('%s -shutdown' %
|
||||||
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
||||||
(retcode, output) = proc.RunCommandFull(counters_command,
|
(retcode, output) = proc.RunCommandFull(counters_command,
|
||||||
collect_output=True)
|
collect_output=True)
|
||||||
# TODO(niranjan): Add a check that to verify that the binaries were built
|
# TODO(niranjan): Add a check that to verify that the binaries were built
|
||||||
# using the /PROFILE linker flag.
|
# using the /PROFILE linker flag.
|
||||||
if self.vsts_path == None or self.lcov_converter_path == None:
|
if self.vsts_path == None or self.lcov_converter_path == None:
|
||||||
return None
|
return None
|
||||||
# Remove trailing slashes
|
# Remove trailing slashes
|
||||||
self.vsts_path = self.vsts_path.rstrip('\\')
|
self.vsts_path = self.vsts_path.rstrip('\\')
|
||||||
instrument_command = '%s /COVERAGE ' % (os.path.join(self.vsts_path,
|
instrument_command = '%s /COVERAGE ' % (os.path.join(self.vsts_path,
|
||||||
'vsinstr.exe'))
|
'vsinstr.exe'))
|
||||||
for binary in binaries:
|
for binary in binaries:
|
||||||
logging.info('binary = %s' % (binary))
|
logging.info('binary = %s' % (binary))
|
||||||
logging.info('instrument_command = %s' % (instrument_command))
|
logging.info('instrument_command = %s' % (instrument_command))
|
||||||
# Instrument each binary in the list
|
# Instrument each binary in the list
|
||||||
(retcode, output) = proc.RunCommandFull(instrument_command + binary,
|
(retcode, output) = proc.RunCommandFull(instrument_command + binary,
|
||||||
collect_output=True)
|
collect_output=True)
|
||||||
# Check if the file has been instrumented correctly.
|
# Check if the file has been instrumented correctly.
|
||||||
if output.pop().rfind('Successfully instrumented') == -1:
|
if output.pop().rfind('Successfully instrumented') == -1:
|
||||||
logging.error('Error instrumenting %s' % (binary))
|
logging.error('Error instrumenting %s' % (binary))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Generate the file name for the coverage results
|
# Generate the file name for the coverage results
|
||||||
self._dir = tempfile.mkdtemp()
|
self._dir = tempfile.mkdtemp()
|
||||||
coverage_file = os.path.join(self._dir, 'chrome_win32_%s.coverage' %
|
coverage_file = os.path.join(self._dir, 'chrome_win32_%s.coverage' %
|
||||||
(self.revision))
|
(self.revision))
|
||||||
logging.info('.coverage file: %s' % (coverage_file))
|
logging.info('.coverage file: %s' % (coverage_file))
|
||||||
|
|
||||||
# After all the binaries have been instrumented, we start the counters.
|
# After all the binaries have been instrumented, we start the counters.
|
||||||
counters_command = ('%s -start:coverage -output:%s' %
|
counters_command = ('%s -start:coverage -output:%s' %
|
||||||
(os.path.join(self.vsts_path, 'vsperfcmd.exe'),
|
(os.path.join(self.vsts_path, 'vsperfcmd.exe'),
|
||||||
coverage_file))
|
coverage_file))
|
||||||
# Here we use subprocess.call() instead of the RunCommandFull because the
|
# Here we use subprocess.call() instead of the RunCommandFull because the
|
||||||
# VSPerfCmd spawns another process before terminating and this confuses
|
# VSPerfCmd spawns another process before terminating and this confuses
|
||||||
# the subprocess.Popen() used by RunCommandFull.
|
# the subprocess.Popen() used by RunCommandFull.
|
||||||
retcode = subprocess.call(counters_command)
|
retcode = subprocess.call(counters_command)
|
||||||
# TODO(niranjan): Check whether the counters have been started
|
# TODO(niranjan): Check whether the counters have been started
|
||||||
# successfully.
|
# successfully.
|
||||||
|
|
||||||
# We are now ready to run tests and measure code coverage.
|
# We are now ready to run tests and measure code coverage.
|
||||||
self.instrumented = True
|
self.instrumented = True
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
return coverage_file
|
return coverage_file
|
||||||
|
|
||||||
|
|
||||||
def TearDown(self):
|
def TearDown(self):
|
||||||
"""Tear down method.
|
"""Tear down method.
|
||||||
|
|
||||||
This method shuts down the counters, and cleans up all the intermediate
|
This method shuts down the counters, and cleans up all the intermediate
|
||||||
artifacts.
|
artifacts.
|
||||||
"""
|
"""
|
||||||
if self.instrumented == False:
|
if self.instrumented == False:
|
||||||
return
|
return
|
||||||
|
|
||||||
if IsWindows():
|
if IsWindows():
|
||||||
# Stop counters
|
# Stop counters
|
||||||
counters_command = ('%s -shutdown' %
|
counters_command = ('%s -shutdown' %
|
||||||
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
||||||
(retcode, output) = proc.RunCommandFull(counters_command,
|
(retcode, output) = proc.RunCommandFull(counters_command,
|
||||||
collect_output=True)
|
collect_output=True)
|
||||||
logging.info('Counters shut down: %s' % (output))
|
logging.info('Counters shut down: %s' % (output))
|
||||||
# TODO(niranjan): Revert the instrumented binaries to their original
|
# TODO(niranjan): Revert the instrumented binaries to their original
|
||||||
# versions.
|
# versions.
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
# Delete all the temp files and folders
|
# Delete all the temp files and folders
|
||||||
if self._dir != None:
|
if self._dir != None:
|
||||||
shutil.rmtree(self._dir, ignore_errors=True)
|
shutil.rmtree(self._dir, ignore_errors=True)
|
||||||
logging.info('Cleaned up temporary files and folders')
|
logging.info('Cleaned up temporary files and folders')
|
||||||
# Reset the instrumented flag.
|
# Reset the instrumented flag.
|
||||||
self.instrumented = False
|
self.instrumented = False
|
||||||
|
|
||||||
|
|
||||||
def Upload(self, coverage_file, upload_path, sym_path=None, src_root=None):
|
def Upload(self, coverage_file, upload_path, sym_path=None, src_root=None):
|
||||||
"""Upload the results to the dashboard.
|
"""Upload the results to the dashboard.
|
||||||
|
|
||||||
This method uploads the coverage data to a dashboard where it will be
|
This method uploads the coverage data to a dashboard where it will be
|
||||||
processed. On Windows, this method will first convert the .coverage file to
|
processed. On Windows, this method will first convert the .coverage file to
|
||||||
the lcov format. This method needs to be called before the TearDown method.
|
the lcov format. This method needs to be called before the TearDown method.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
coverage_file: The coverage data file to upload.
|
coverage_file: The coverage data file to upload.
|
||||||
upload_path: Destination where the coverage data will be processed.
|
upload_path: Destination where the coverage data will be processed.
|
||||||
sym_path: Symbol path for the build (Win32 only)
|
sym_path: Symbol path for the build (Win32 only)
|
||||||
src_root: Root folder of the source tree (Win32 only)
|
src_root: Root folder of the source tree (Win32 only)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True on success.
|
True on success.
|
||||||
False on failure.
|
False on failure.
|
||||||
"""
|
"""
|
||||||
if self.IsWindows():
|
if self.IsWindows():
|
||||||
# Stop counters
|
# Stop counters
|
||||||
counters_command = ('%s -shutdown' %
|
counters_command = ('%s -shutdown' %
|
||||||
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
(os.path.join(self.vsts_path, 'vsperfcmd.exe')))
|
||||||
(retcode, output) = proc.RunCommandFull(counters_command,
|
(retcode, output) = proc.RunCommandFull(counters_command,
|
||||||
collect_output=True)
|
collect_output=True)
|
||||||
logging.info('Counters shut down: %s' % (output))
|
logging.info('Counters shut down: %s' % (output))
|
||||||
# Convert the .coverage file to lcov format
|
# Convert the .coverage file to lcov format
|
||||||
if self.lcov_converter_path == False:
|
if self.lcov_converter_path == False:
|
||||||
logging.error('Lcov converter tool not found')
|
logging.error('Lcov converter tool not found')
|
||||||
return False
|
return False
|
||||||
self.lcov_converter_path = self.lcov_converter_path.rstrip('\\')
|
self.lcov_converter_path = self.lcov_converter_path.rstrip('\\')
|
||||||
convert_command = ('%s -sym_path=%s -src_root=%s ' %
|
convert_command = ('%s -sym_path=%s -src_root=%s ' %
|
||||||
(os.path.join(self.lcov_converter_path,
|
(os.path.join(self.lcov_converter_path,
|
||||||
'coverage_analyzer.exe'),
|
'coverage_analyzer.exe'),
|
||||||
sym_path,
|
sym_path,
|
||||||
src_root))
|
src_root))
|
||||||
logging.info('Conversion to lcov complete')
|
logging.info('Conversion to lcov complete')
|
||||||
(retcode, output) = proc.RunCommandFull(convert_command + coverage_file,
|
(retcode, output) = proc.RunCommandFull(convert_command + coverage_file,
|
||||||
collect_output=True)
|
collect_output=True)
|
||||||
shutil.copy(coverage_file, coverage_file.replace('.coverage', ''))
|
shutil.copy(coverage_file, coverage_file.replace('.coverage', ''))
|
||||||
# TODO(niranjan): Upload this somewhere!
|
# TODO(niranjan): Upload this somewhere!
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Command line parsing
|
# Command line parsing
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
# Path where the .coverage to .lcov converter tools are stored.
|
# Path where the .coverage to .lcov converter tools are stored.
|
||||||
parser.add_option('-t',
|
parser.add_option('-t',
|
||||||
'--tools_path',
|
'--tools_path',
|
||||||
dest='tools_path',
|
dest='tools_path',
|
||||||
default=None,
|
default=None,
|
||||||
help='Location of the coverage tools (windows only)')
|
help='Location of the coverage tools (windows only)')
|
||||||
parser.add_option('-u',
|
parser.add_option('-u',
|
||||||
'--upload',
|
'--upload',
|
||||||
dest='upload_path'
|
dest='upload_path'
|
||||||
default=None,
|
default=None,
|
||||||
help='Location where the results should be uploaded')
|
help='Location where the results should be uploaded')
|
||||||
# We need the revision number so that we can generate the output file of the
|
# We need the revision number so that we can generate the output file of the
|
||||||
# format chrome_<platform>_<revision>.lcov
|
# format chrome_<platform>_<revision>.lcov
|
||||||
parser.add_option('-r',
|
parser.add_option('-r',
|
||||||
'--revision',
|
'--revision',
|
||||||
dest='revision',
|
dest='revision',
|
||||||
default=None,
|
default=None,
|
||||||
help='Revision number of the Chromium source repo')
|
help='Revision number of the Chromium source repo')
|
||||||
# Root of the source tree. Needed for converting the generated .coverage file
|
# Root of the source tree. Needed for converting the generated .coverage file
|
||||||
# on Windows to the open source lcov format.
|
# on Windows to the open source lcov format.
|
||||||
parser.add_option('-s',
|
parser.add_option('-s',
|
||||||
'--src_root',
|
'--src_root',
|
||||||
dest='src_root',
|
dest='src_root',
|
||||||
default=None,
|
default=None,
|
||||||
help='Root of the source repository')
|
help='Root of the source repository')
|
||||||
|
|
||||||
if revision == None or src_root == None or upload_path == None:
|
if revision == None or src_root == None or upload_path == None:
|
||||||
logging.error('Invalid command line arguments')
|
logging.error('Invalid command line arguments')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if IsWindows():
|
if IsWindows():
|
||||||
# Initialize coverage
|
# Initialize coverage
|
||||||
cov = coverage.Coverage(revision,
|
cov = coverage.Coverage(revision,
|
||||||
tools_path,
|
tools_path,
|
||||||
tools_path)
|
tools_path)
|
||||||
# Instrument the binaries
|
# Instrument the binaries
|
||||||
coverage_file = cov.SetUp(windows_binaries)
|
coverage_file = cov.SetUp(windows_binaries)
|
||||||
if coverage_file != None:
|
if coverage_file != None:
|
||||||
# Run all the tests
|
# Run all the tests
|
||||||
for test in windows_tests:
|
for test in windows_tests:
|
||||||
logging.info('Executing test %s: ' % binary)
|
logging.info('Executing test %s: ' % binary)
|
||||||
(retcode, output) = proc.RunCommandFull(binary, collect_output=True)
|
(retcode, output) = proc.RunCommandFull(binary, collect_output=True)
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
sys.exit(retcode)
|
sys.exit(retcode)
|
||||||
else:
|
else:
|
||||||
logging.error('Error during instrumentation.')
|
logging.error('Error during instrumentation.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cov.Upload(coverage_file,
|
cov.Upload(coverage_file,
|
||||||
upload_path,
|
upload_path,
|
||||||
os.path.join(src_root, 'chrome', 'Release'),
|
os.path.join(src_root, 'chrome', 'Release'),
|
||||||
src_root)
|
src_root)
|
||||||
cov.TearDown()
|
cov.TearDown()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
||||||
|
@@ -1,233 +1,233 @@
|
|||||||
#!/usr/bin/python2.4
|
#!/usr/bin/python2.4
|
||||||
#
|
#
|
||||||
# Copyright 2008, Google Inc.
|
# Copyright 2008, Google Inc.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions are
|
# modification, are permitted provided that the following conditions are
|
||||||
# met:
|
# met:
|
||||||
#
|
#
|
||||||
# * Redistributions of source code must retain the above copyright
|
# * Redistributions of source code must retain the above copyright
|
||||||
# notice, this list of conditions and the following disclaimer.
|
# notice, this list of conditions and the following disclaimer.
|
||||||
# * Redistributions in binary form must reproduce the above
|
# * Redistributions in binary form must reproduce the above
|
||||||
# copyright notice, this list of conditions and the following disclaimer
|
# copyright notice, this list of conditions and the following disclaimer
|
||||||
# in the documentation and/or other materials provided with the
|
# in the documentation and/or other materials provided with the
|
||||||
# distribution.
|
# distribution.
|
||||||
# * Neither the name of Google Inc. nor the names of its
|
# * Neither the name of Google Inc. nor the names of its
|
||||||
# contributors may be used to endorse or promote products derived from
|
# contributors may be used to endorse or promote products derived from
|
||||||
# this software without specific prior written permission.
|
# this software without specific prior written permission.
|
||||||
#
|
#
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
"""Script to clean the lcov files and convert it to HTML
|
"""Script to clean the lcov files and convert it to HTML
|
||||||
|
|
||||||
TODO(niranjan): Add usage information here
|
TODO(niranjan): Add usage information here
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
# These are source files that were generated during compile time. We want to
|
# These are source files that were generated during compile time. We want to
|
||||||
# remove references to these files from the lcov file otherwise genhtml will
|
# remove references to these files from the lcov file otherwise genhtml will
|
||||||
# throw an error.
|
# throw an error.
|
||||||
win32_srcs_exclude = ['parse.y',
|
win32_srcs_exclude = ['parse.y',
|
||||||
'xpathgrammar.cpp',
|
'xpathgrammar.cpp',
|
||||||
'cssgrammar.cpp']
|
'cssgrammar.cpp']
|
||||||
|
|
||||||
|
|
||||||
def CleanPathNames(dir):
|
def CleanPathNames(dir):
|
||||||
"""Clean the pathnames of the HTML generated by genhtml.
|
"""Clean the pathnames of the HTML generated by genhtml.
|
||||||
|
|
||||||
This method is required only for code coverage on Win32. Due to a known issue
|
This method is required only for code coverage on Win32. Due to a known issue
|
||||||
with reading from CIFS shares mounted on Linux, genhtml appends a ^M to every
|
with reading from CIFS shares mounted on Linux, genhtml appends a ^M to every
|
||||||
file name it reads from the Windows share, causing corrupt filenames in
|
file name it reads from the Windows share, causing corrupt filenames in
|
||||||
genhtml's output folder.
|
genhtml's output folder.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dir: Output folder of the genhtml output.
|
dir: Output folder of the genhtml output.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
# Stip off the ^M characters that get appended to the file name
|
# Stip off the ^M characters that get appended to the file name
|
||||||
for file in os.walk(dir):
|
for file in os.walk(dir):
|
||||||
file_clean = file.replace('\r', '')
|
file_clean = file.replace('\r', '')
|
||||||
if file_clean != file:
|
if file_clean != file:
|
||||||
os.rename(file, file_clean)
|
os.rename(file, file_clean)
|
||||||
|
|
||||||
|
|
||||||
def GenerateHtml(lcov_path, dash_root):
|
def GenerateHtml(lcov_path, dash_root):
|
||||||
"""Runs genhtml to convert lcov data to human readable HTML.
|
"""Runs genhtml to convert lcov data to human readable HTML.
|
||||||
|
|
||||||
This script expects the LCOV file name to be in the format:
|
This script expects the LCOV file name to be in the format:
|
||||||
chrome_<platform>_<revision#>.lcov.
|
chrome_<platform>_<revision#>.lcov.
|
||||||
This method parses the file name and then sets up the correct folder
|
This method parses the file name and then sets up the correct folder
|
||||||
hierarchy for the coverage data and then runs genhtml to get the actual HTML
|
hierarchy for the coverage data and then runs genhtml to get the actual HTML
|
||||||
formatted coverage data.
|
formatted coverage data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
lcov_path: Path of the lcov data file.
|
lcov_path: Path of the lcov data file.
|
||||||
dash_root: Root location of the dashboard.
|
dash_root: Root location of the dashboard.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Code coverage percentage on sucess.
|
Code coverage percentage on sucess.
|
||||||
None on failure.
|
None on failure.
|
||||||
"""
|
"""
|
||||||
# Parse the LCOV file name.
|
# Parse the LCOV file name.
|
||||||
filename = os.path.basename(lcov_path).split('.')[0]
|
filename = os.path.basename(lcov_path).split('.')[0]
|
||||||
buffer = filename.split('_')
|
buffer = filename.split('_')
|
||||||
dash_root = dash_root.rstrip('/') # Remove trailing '/'
|
dash_root = dash_root.rstrip('/') # Remove trailing '/'
|
||||||
|
|
||||||
# Set up correct folder heirarchy in the dashboard root
|
# Set up correct folder heirarchy in the dashboard root
|
||||||
# TODO(niranjan): Check the formatting using a regexp
|
# TODO(niranjan): Check the formatting using a regexp
|
||||||
if len(buffer) >= 3: # Check if filename has right formatting
|
if len(buffer) >= 3: # Check if filename has right formatting
|
||||||
platform = buffer[len(buffer) - 2]
|
platform = buffer[len(buffer) - 2]
|
||||||
revision = buffer[len(buffer) - 1]
|
revision = buffer[len(buffer) - 1]
|
||||||
if os.path.exists(os.path.join(dash_root, platform)) == False:
|
if os.path.exists(os.path.join(dash_root, platform)) == False:
|
||||||
os.mkdir(os.path.join(dash_root, platform))
|
os.mkdir(os.path.join(dash_root, platform))
|
||||||
output_dir = os.join.path(dash_root, platform, revision)
|
output_dir = os.join.path(dash_root, platform, revision)
|
||||||
os.mkdir(output_dir)
|
os.mkdir(output_dir)
|
||||||
else:
|
else:
|
||||||
# TODO(niranjan): Add failure logging here.
|
# TODO(niranjan): Add failure logging here.
|
||||||
return None # File not formatted correctly
|
return None # File not formatted correctly
|
||||||
|
|
||||||
# Run genhtml
|
# Run genhtml
|
||||||
os.system('/usr/bin/genhtml -o %s %s' % (output_dir, lcov_path))
|
os.system('/usr/bin/genhtml -o %s %s' % (output_dir, lcov_path))
|
||||||
# TODO(niranjan): Check the exit status of the genhtml command.
|
# TODO(niranjan): Check the exit status of the genhtml command.
|
||||||
# TODO(niranjan): Parse the stdout and return coverage percentage.
|
# TODO(niranjan): Parse the stdout and return coverage percentage.
|
||||||
CleanPathNames(output_dir)
|
CleanPathNames(output_dir)
|
||||||
return 'dummy' # TODO(niranjan): Return actual percentage.
|
return 'dummy' # TODO(niranjan): Return actual percentage.
|
||||||
|
|
||||||
|
|
||||||
def CleanWin32Lcov(lcov_path, src_root):
|
def CleanWin32Lcov(lcov_path, src_root):
|
||||||
"""Cleanup the lcov data generated on Windows.
|
"""Cleanup the lcov data generated on Windows.
|
||||||
|
|
||||||
This method fixes up the paths inside the lcov file from the Win32 specific
|
This method fixes up the paths inside the lcov file from the Win32 specific
|
||||||
paths to the actual paths of the mounted CIFS share. The lcov files generated
|
paths to the actual paths of the mounted CIFS share. The lcov files generated
|
||||||
on Windows have the following format:
|
on Windows have the following format:
|
||||||
|
|
||||||
SF:c:\chrome_src\src\skia\sgl\skscan_antihair.cpp
|
SF:c:\chrome_src\src\skia\sgl\skscan_antihair.cpp
|
||||||
DA:97,0
|
DA:97,0
|
||||||
DA:106,0
|
DA:106,0
|
||||||
DA:107,0
|
DA:107,0
|
||||||
DA:109,0
|
DA:109,0
|
||||||
...
|
...
|
||||||
end_of_record
|
end_of_record
|
||||||
|
|
||||||
This method changes the source-file (SF) lines to a format compatible with
|
This method changes the source-file (SF) lines to a format compatible with
|
||||||
genhtml on Linux by fixing paths. This method also removes references to
|
genhtml on Linux by fixing paths. This method also removes references to
|
||||||
certain dynamically generated files to be excluded from the code ceverage.
|
certain dynamically generated files to be excluded from the code ceverage.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
lcov_path: Path of the Win32 lcov file to be cleaned.
|
lcov_path: Path of the Win32 lcov file to be cleaned.
|
||||||
src_root: Location of the source and symbols dir.
|
src_root: Location of the source and symbols dir.
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
strip_flag = False
|
strip_flag = False
|
||||||
lcov = open(lcov_path, 'r')
|
lcov = open(lcov_path, 'r')
|
||||||
(tmpfile, tmpfile_name) = tempfile.mkstemp()
|
(tmpfile, tmpfile_name) = tempfile.mkstemp()
|
||||||
src_root = src_root.rstrip('/') # Remove trailing '/'
|
src_root = src_root.rstrip('/') # Remove trailing '/'
|
||||||
for line in lcov:
|
for line in lcov:
|
||||||
if line.startswith('SF'):
|
if line.startswith('SF'):
|
||||||
# We want to exclude certain auto-generated files otherwise genhtml will
|
# We want to exclude certain auto-generated files otherwise genhtml will
|
||||||
# fail to convert lcov to HTML.
|
# fail to convert lcov to HTML.
|
||||||
for exp in win32_srcs_exclude:
|
for exp in win32_srcs_exclude:
|
||||||
if line.rfind(exp) != -1:
|
if line.rfind(exp) != -1:
|
||||||
strip_flag = True # Indicates that we want to remove this section
|
strip_flag = True # Indicates that we want to remove this section
|
||||||
|
|
||||||
# Now we normalize the paths
|
# Now we normalize the paths
|
||||||
# e.g. Change SF:c:\foo\src\... to SF:/chrome_src/...
|
# e.g. Change SF:c:\foo\src\... to SF:/chrome_src/...
|
||||||
parse_buffer = line.split(':')
|
parse_buffer = line.split(':')
|
||||||
buffer = '%s:%s%s' % (parse_buffer[0],
|
buffer = '%s:%s%s' % (parse_buffer[0],
|
||||||
src_root,
|
src_root,
|
||||||
parse_buffer[2])
|
parse_buffer[2])
|
||||||
buffer = buffer.replace('\\', '/')
|
buffer = buffer.replace('\\', '/')
|
||||||
line = buffer
|
line = buffer
|
||||||
|
|
||||||
# Write to the temp file if the section to write is valid
|
# Write to the temp file if the section to write is valid
|
||||||
if strip_flag == False:
|
if strip_flag == False:
|
||||||
tmpfile.write('%s' % (line))
|
tmpfile.write('%s' % (line))
|
||||||
|
|
||||||
# Reset the strip flag
|
# Reset the strip flag
|
||||||
if line.endswith('end_of_record'):
|
if line.endswith('end_of_record'):
|
||||||
strip_flag = False
|
strip_flag = False
|
||||||
|
|
||||||
# Close the files and replace the lcov file by the 'clean' tmpfile
|
# Close the files and replace the lcov file by the 'clean' tmpfile
|
||||||
tmpfile.close()
|
tmpfile.close()
|
||||||
lcov.close()
|
lcov.close()
|
||||||
shutil.move(tmpfile_name, lcov_path)
|
shutil.move(tmpfile_name, lcov_path)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if sys.platform[:5] != 'linux': # Run this only on Linux
|
if sys.platform[:5] != 'linux': # Run this only on Linux
|
||||||
print 'This script is supported only on Linux'
|
print 'This script is supported only on Linux'
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
|
|
||||||
# Command line parsing
|
# Command line parsing
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option('-p',
|
parser.add_option('-p',
|
||||||
'--platform',
|
'--platform',
|
||||||
dest='platform',
|
dest='platform',
|
||||||
default=None,
|
default=None,
|
||||||
help='Platform that the locv file was generated on. Must be
|
help='Platform that the locv file was generated on. Must be
|
||||||
one of {win32, linux2, macosx}')
|
one of {win32, linux2, macosx}')
|
||||||
parser.add_option('-s',
|
parser.add_option('-s',
|
||||||
'--source',
|
'--source',
|
||||||
dest='src_dir',
|
dest='src_dir',
|
||||||
default=None,
|
default=None,
|
||||||
help='Path to the source code and symbols')
|
help='Path to the source code and symbols')
|
||||||
parser.add_option('-d',
|
parser.add_option('-d',
|
||||||
'--dash_root',
|
'--dash_root',
|
||||||
dest='dash_root',
|
dest='dash_root',
|
||||||
default=None,
|
default=None,
|
||||||
help='Root directory for the dashboard')
|
help='Root directory for the dashboard')
|
||||||
parser.add_option('-l',
|
parser.add_option('-l',
|
||||||
'--lcov',
|
'--lcov',
|
||||||
dest='lcov_path',
|
dest='lcov_path',
|
||||||
default=None,
|
default=None,
|
||||||
help='Location of the LCOV file to process')
|
help='Location of the LCOV file to process')
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.platform == None:
|
if options.platform == None:
|
||||||
parser.error('Platform not specified')
|
parser.error('Platform not specified')
|
||||||
if options.lcov_path == None:
|
if options.lcov_path == None:
|
||||||
parser.error('lcov file path not specified')
|
parser.error('lcov file path not specified')
|
||||||
if options.src_dir == None:
|
if options.src_dir == None:
|
||||||
parser.error('Source directory not specified')
|
parser.error('Source directory not specified')
|
||||||
if options.dash_root == None:
|
if options.dash_root == None:
|
||||||
parser.error('Dashboard root not specified')
|
parser.error('Dashboard root not specified')
|
||||||
if options.platform == 'win32':
|
if options.platform == 'win32':
|
||||||
CleanWin32Lcov(options.lcov_path, options.src_dir)
|
CleanWin32Lcov(options.lcov_path, options.src_dir)
|
||||||
percent = GenerateHtml(options.lcov_path, options.dash_root)
|
percent = GenerateHtml(options.lcov_path, options.dash_root)
|
||||||
if percent == None:
|
if percent == None:
|
||||||
# TODO(niranjan): Add logging.
|
# TODO(niranjan): Add logging.
|
||||||
print 'Failed to generate code coverage'
|
print 'Failed to generate code coverage'
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
else:
|
else:
|
||||||
# TODO(niranjan): Do something with the code coverage numbers
|
# TODO(niranjan): Do something with the code coverage numbers
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print 'Unsupported platform'
|
print 'Unsupported platform'
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@@ -1,376 +1,376 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "call_stack.h"
|
#include "call_stack.h"
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#include <tlhelp32.h>
|
#include <tlhelp32.h>
|
||||||
|
|
||||||
#include "memory_hook.h"
|
#include "memory_hook.h"
|
||||||
#include "base/string_util.h"
|
#include "base/string_util.h"
|
||||||
|
|
||||||
// Typedefs for explicit dynamic linking with functions exported from
|
// Typedefs for explicit dynamic linking with functions exported from
|
||||||
// dbghelp.dll.
|
// dbghelp.dll.
|
||||||
typedef BOOL (__stdcall *t_StackWalk64)(DWORD, HANDLE, HANDLE,
|
typedef BOOL (__stdcall *t_StackWalk64)(DWORD, HANDLE, HANDLE,
|
||||||
LPSTACKFRAME64, PVOID,
|
LPSTACKFRAME64, PVOID,
|
||||||
PREAD_PROCESS_MEMORY_ROUTINE64,
|
PREAD_PROCESS_MEMORY_ROUTINE64,
|
||||||
PFUNCTION_TABLE_ACCESS_ROUTINE64,
|
PFUNCTION_TABLE_ACCESS_ROUTINE64,
|
||||||
PGET_MODULE_BASE_ROUTINE64,
|
PGET_MODULE_BASE_ROUTINE64,
|
||||||
PTRANSLATE_ADDRESS_ROUTINE64);
|
PTRANSLATE_ADDRESS_ROUTINE64);
|
||||||
typedef PVOID (__stdcall *t_SymFunctionTableAccess64)(HANDLE, DWORD64);
|
typedef PVOID (__stdcall *t_SymFunctionTableAccess64)(HANDLE, DWORD64);
|
||||||
typedef DWORD64 (__stdcall *t_SymGetModuleBase64)(HANDLE, DWORD64);
|
typedef DWORD64 (__stdcall *t_SymGetModuleBase64)(HANDLE, DWORD64);
|
||||||
typedef BOOL (__stdcall *t_SymCleanup)(HANDLE);
|
typedef BOOL (__stdcall *t_SymCleanup)(HANDLE);
|
||||||
typedef BOOL (__stdcall *t_SymGetSymFromAddr64)(HANDLE, DWORD64,
|
typedef BOOL (__stdcall *t_SymGetSymFromAddr64)(HANDLE, DWORD64,
|
||||||
PDWORD64, PIMAGEHLP_SYMBOL64);
|
PDWORD64, PIMAGEHLP_SYMBOL64);
|
||||||
typedef BOOL (__stdcall *t_SymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD,
|
typedef BOOL (__stdcall *t_SymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD,
|
||||||
PIMAGEHLP_LINE64);
|
PIMAGEHLP_LINE64);
|
||||||
typedef BOOL (__stdcall *t_SymInitialize)(HANDLE, PCTSTR, BOOL);
|
typedef BOOL (__stdcall *t_SymInitialize)(HANDLE, PCTSTR, BOOL);
|
||||||
typedef DWORD (__stdcall *t_SymGetOptions)(void);
|
typedef DWORD (__stdcall *t_SymGetOptions)(void);
|
||||||
typedef DWORD (__stdcall *t_SymSetOptions)(DWORD);
|
typedef DWORD (__stdcall *t_SymSetOptions)(DWORD);
|
||||||
typedef BOOL (__stdcall *t_SymGetSearchPath)(HANDLE, PTSTR, DWORD);
|
typedef BOOL (__stdcall *t_SymGetSearchPath)(HANDLE, PTSTR, DWORD);
|
||||||
typedef DWORD64 (__stdcall *t_SymLoadModule64)(HANDLE, HANDLE, PCSTR,
|
typedef DWORD64 (__stdcall *t_SymLoadModule64)(HANDLE, HANDLE, PCSTR,
|
||||||
PCSTR, DWORD64, DWORD);
|
PCSTR, DWORD64, DWORD);
|
||||||
typedef BOOL (__stdcall *t_SymGetModuleInfo64)(HANDLE, DWORD64,
|
typedef BOOL (__stdcall *t_SymGetModuleInfo64)(HANDLE, DWORD64,
|
||||||
PIMAGEHLP_MODULE64);
|
PIMAGEHLP_MODULE64);
|
||||||
|
|
||||||
// According to http://msdn2.microsoft.com/en-us/library/ms680650(VS.85).aspx
|
// According to http://msdn2.microsoft.com/en-us/library/ms680650(VS.85).aspx
|
||||||
// "All DbgHelp functions, such as this one, are single threaded. Therefore,
|
// "All DbgHelp functions, such as this one, are single threaded. Therefore,
|
||||||
// calls from more than one thread to this function will likely result in
|
// calls from more than one thread to this function will likely result in
|
||||||
// unexpected behavior or memory corruption. To avoid this, you must
|
// unexpected behavior or memory corruption. To avoid this, you must
|
||||||
// synchromize all concurrent calls from one thread to this function."
|
// synchromize all concurrent calls from one thread to this function."
|
||||||
//
|
//
|
||||||
// dbghelp_lock_ is used to serialize access across all calls to the DbgHelp
|
// dbghelp_lock_ is used to serialize access across all calls to the DbgHelp
|
||||||
// library. This may be overly conservative (serializing them all together),
|
// library. This may be overly conservative (serializing them all together),
|
||||||
// but does guarantee correctness.
|
// but does guarantee correctness.
|
||||||
static Lock dbghelp_lock_;
|
static Lock dbghelp_lock_;
|
||||||
|
|
||||||
static t_StackWalk64 pStackWalk64 = NULL;
|
static t_StackWalk64 pStackWalk64 = NULL;
|
||||||
static t_SymCleanup pSymCleanup = NULL;
|
static t_SymCleanup pSymCleanup = NULL;
|
||||||
static t_SymGetSymFromAddr64 pSymGetSymFromAddr64 = NULL;
|
static t_SymGetSymFromAddr64 pSymGetSymFromAddr64 = NULL;
|
||||||
static t_SymFunctionTableAccess64 pSymFunctionTableAccess64 = NULL;
|
static t_SymFunctionTableAccess64 pSymFunctionTableAccess64 = NULL;
|
||||||
static t_SymGetModuleBase64 pSymGetModuleBase64 = NULL;
|
static t_SymGetModuleBase64 pSymGetModuleBase64 = NULL;
|
||||||
static t_SymGetLineFromAddr64 pSymGetLineFromAddr64 = NULL;
|
static t_SymGetLineFromAddr64 pSymGetLineFromAddr64 = NULL;
|
||||||
static t_SymInitialize pSymInitialize = NULL;
|
static t_SymInitialize pSymInitialize = NULL;
|
||||||
static t_SymGetOptions pSymGetOptions = NULL;
|
static t_SymGetOptions pSymGetOptions = NULL;
|
||||||
static t_SymSetOptions pSymSetOptions = NULL;
|
static t_SymSetOptions pSymSetOptions = NULL;
|
||||||
static t_SymGetModuleInfo64 pSymGetModuleInfo64 = NULL;
|
static t_SymGetModuleInfo64 pSymGetModuleInfo64 = NULL;
|
||||||
static t_SymGetSearchPath pSymGetSearchPath = NULL;
|
static t_SymGetSearchPath pSymGetSearchPath = NULL;
|
||||||
static t_SymLoadModule64 pSymLoadModule64 = NULL;
|
static t_SymLoadModule64 pSymLoadModule64 = NULL;
|
||||||
|
|
||||||
#define LOADPROC(module, name) do { \
|
#define LOADPROC(module, name) do { \
|
||||||
p##name = reinterpret_cast<t_##name>(GetProcAddress(module, #name)); \
|
p##name = reinterpret_cast<t_##name>(GetProcAddress(module, #name)); \
|
||||||
if (p##name == NULL) return false; \
|
if (p##name == NULL) return false; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Dynamically load the DbgHelp library and supporting routines that we
|
// Dynamically load the DbgHelp library and supporting routines that we
|
||||||
// will use.
|
// will use.
|
||||||
static bool LoadDbgHelp() {
|
static bool LoadDbgHelp() {
|
||||||
static bool loaded = false;
|
static bool loaded = false;
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
AutoLock Lock(dbghelp_lock_);
|
AutoLock Lock(dbghelp_lock_);
|
||||||
|
|
||||||
// Re-check if we've loaded successfully now that we have the lock.
|
// Re-check if we've loaded successfully now that we have the lock.
|
||||||
if (loaded)
|
if (loaded)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Load dbghelp.dll, and obtain pointers to the exported functions that we
|
// Load dbghelp.dll, and obtain pointers to the exported functions that we
|
||||||
// will be using.
|
// will be using.
|
||||||
HMODULE dbghelp_module = LoadLibrary(L"dbghelp.dll");
|
HMODULE dbghelp_module = LoadLibrary(L"dbghelp.dll");
|
||||||
if (dbghelp_module) {
|
if (dbghelp_module) {
|
||||||
LOADPROC(dbghelp_module, StackWalk64);
|
LOADPROC(dbghelp_module, StackWalk64);
|
||||||
LOADPROC(dbghelp_module, SymFunctionTableAccess64);
|
LOADPROC(dbghelp_module, SymFunctionTableAccess64);
|
||||||
LOADPROC(dbghelp_module, SymGetModuleBase64);
|
LOADPROC(dbghelp_module, SymGetModuleBase64);
|
||||||
LOADPROC(dbghelp_module, SymCleanup);
|
LOADPROC(dbghelp_module, SymCleanup);
|
||||||
LOADPROC(dbghelp_module, SymGetSymFromAddr64);
|
LOADPROC(dbghelp_module, SymGetSymFromAddr64);
|
||||||
LOADPROC(dbghelp_module, SymGetLineFromAddr64);
|
LOADPROC(dbghelp_module, SymGetLineFromAddr64);
|
||||||
LOADPROC(dbghelp_module, SymInitialize);
|
LOADPROC(dbghelp_module, SymInitialize);
|
||||||
LOADPROC(dbghelp_module, SymGetOptions);
|
LOADPROC(dbghelp_module, SymGetOptions);
|
||||||
LOADPROC(dbghelp_module, SymSetOptions);
|
LOADPROC(dbghelp_module, SymSetOptions);
|
||||||
LOADPROC(dbghelp_module, SymGetModuleInfo64);
|
LOADPROC(dbghelp_module, SymGetModuleInfo64);
|
||||||
LOADPROC(dbghelp_module, SymGetSearchPath);
|
LOADPROC(dbghelp_module, SymGetSearchPath);
|
||||||
LOADPROC(dbghelp_module, SymLoadModule64);
|
LOADPROC(dbghelp_module, SymLoadModule64);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the symbols for generating stack traces.
|
// Load the symbols for generating stack traces.
|
||||||
static bool LoadSymbols(HANDLE process_handle) {
|
static bool LoadSymbols(HANDLE process_handle) {
|
||||||
static bool symbols_loaded = false;
|
static bool symbols_loaded = false;
|
||||||
if (symbols_loaded) return true;
|
if (symbols_loaded) return true;
|
||||||
|
|
||||||
BOOL ok;
|
BOOL ok;
|
||||||
|
|
||||||
// Initialize the symbol engine.
|
// Initialize the symbol engine.
|
||||||
ok = pSymInitialize(process_handle, /* hProcess */
|
ok = pSymInitialize(process_handle, /* hProcess */
|
||||||
NULL, /* UserSearchPath */
|
NULL, /* UserSearchPath */
|
||||||
FALSE); /* fInvadeProcess */
|
FALSE); /* fInvadeProcess */
|
||||||
if (!ok) return false;
|
if (!ok) return false;
|
||||||
|
|
||||||
DWORD options = pSymGetOptions();
|
DWORD options = pSymGetOptions();
|
||||||
options |= SYMOPT_LOAD_LINES;
|
options |= SYMOPT_LOAD_LINES;
|
||||||
options |= SYMOPT_FAIL_CRITICAL_ERRORS;
|
options |= SYMOPT_FAIL_CRITICAL_ERRORS;
|
||||||
options |= SYMOPT_UNDNAME;
|
options |= SYMOPT_UNDNAME;
|
||||||
options = pSymSetOptions(options);
|
options = pSymSetOptions(options);
|
||||||
|
|
||||||
const DWORD kMaxSearchPath = 1024;
|
const DWORD kMaxSearchPath = 1024;
|
||||||
TCHAR buf[kMaxSearchPath] = {0};
|
TCHAR buf[kMaxSearchPath] = {0};
|
||||||
ok = pSymGetSearchPath(process_handle, buf, kMaxSearchPath);
|
ok = pSymGetSearchPath(process_handle, buf, kMaxSearchPath);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
|
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
|
||||||
GetCurrentProcessId());
|
GetCurrentProcessId());
|
||||||
if (snapshot == INVALID_HANDLE_VALUE)
|
if (snapshot == INVALID_HANDLE_VALUE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
MODULEENTRY32W module;
|
MODULEENTRY32W module;
|
||||||
module.dwSize = sizeof(module); // Set the size of the structure.
|
module.dwSize = sizeof(module); // Set the size of the structure.
|
||||||
BOOL cont = Module32FirstW(snapshot, &module);
|
BOOL cont = Module32FirstW(snapshot, &module);
|
||||||
while (cont) {
|
while (cont) {
|
||||||
DWORD64 base;
|
DWORD64 base;
|
||||||
// NOTE the SymLoadModule64 function has the peculiarity of accepting a
|
// NOTE the SymLoadModule64 function has the peculiarity of accepting a
|
||||||
// both unicode and ASCII strings even though the parameter is PSTR.
|
// both unicode and ASCII strings even though the parameter is PSTR.
|
||||||
base = pSymLoadModule64(process_handle,
|
base = pSymLoadModule64(process_handle,
|
||||||
0,
|
0,
|
||||||
reinterpret_cast<PSTR>(module.szExePath),
|
reinterpret_cast<PSTR>(module.szExePath),
|
||||||
reinterpret_cast<PSTR>(module.szModule),
|
reinterpret_cast<PSTR>(module.szModule),
|
||||||
reinterpret_cast<DWORD64>(module.modBaseAddr),
|
reinterpret_cast<DWORD64>(module.modBaseAddr),
|
||||||
module.modBaseSize);
|
module.modBaseSize);
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
int err = GetLastError();
|
int err = GetLastError();
|
||||||
if (err != ERROR_MOD_NOT_FOUND && err != ERROR_INVALID_HANDLE)
|
if (err != ERROR_MOD_NOT_FOUND && err != ERROR_INVALID_HANDLE)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cont = Module32NextW(snapshot, &module);
|
cont = Module32NextW(snapshot, &module);
|
||||||
}
|
}
|
||||||
CloseHandle(snapshot);
|
CloseHandle(snapshot);
|
||||||
|
|
||||||
symbols_loaded = true;
|
symbols_loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CallStack::SymbolCache* CallStack::symbol_cache_;
|
CallStack::SymbolCache* CallStack::symbol_cache_;
|
||||||
|
|
||||||
bool CallStack::Initialize() {
|
bool CallStack::Initialize() {
|
||||||
// We need to delay load the symbol cache until after
|
// We need to delay load the symbol cache until after
|
||||||
// the MemoryHook heap is alive.
|
// the MemoryHook heap is alive.
|
||||||
symbol_cache_ = new SymbolCache();
|
symbol_cache_ = new SymbolCache();
|
||||||
return LoadDbgHelp();
|
return LoadDbgHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
CallStack::CallStack() {
|
CallStack::CallStack() {
|
||||||
static LONG callstack_id = 0;
|
static LONG callstack_id = 0;
|
||||||
frame_count_ = 0;
|
frame_count_ = 0;
|
||||||
hash_ = 0;
|
hash_ = 0;
|
||||||
id_ = InterlockedIncrement(&callstack_id);
|
id_ = InterlockedIncrement(&callstack_id);
|
||||||
|
|
||||||
LoadDbgHelp();
|
LoadDbgHelp();
|
||||||
CHECK(GetStackTrace());
|
CHECK(GetStackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CallStack::IsEqual(const CallStack &target) {
|
bool CallStack::IsEqual(const CallStack &target) {
|
||||||
if (frame_count_ != target.frame_count_)
|
if (frame_count_ != target.frame_count_)
|
||||||
return false; // They can't be equal if the sizes are different.
|
return false; // They can't be equal if the sizes are different.
|
||||||
|
|
||||||
// Walk the frames array until we
|
// Walk the frames array until we
|
||||||
// either find a mismatch, or until we reach the end of the call stacks.
|
// either find a mismatch, or until we reach the end of the call stacks.
|
||||||
for (int index = 0; index < frame_count_; index++) {
|
for (int index = 0; index < frame_count_; index++) {
|
||||||
if (frames_[index] != target.frames_[index])
|
if (frames_[index] != target.frames_[index])
|
||||||
return false; // Found a mismatch. They are not equal.
|
return false; // Found a mismatch. They are not equal.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reached the end of the call stacks. They are equal.
|
// Reached the end of the call stacks. They are equal.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallStack::AddFrame(DWORD_PTR pc) {
|
void CallStack::AddFrame(DWORD_PTR pc) {
|
||||||
DCHECK(frame_count_ < kMaxTraceFrames);
|
DCHECK(frame_count_ < kMaxTraceFrames);
|
||||||
frames_[frame_count_++] = pc;
|
frames_[frame_count_++] = pc;
|
||||||
|
|
||||||
// Create a unique id for this CallStack.
|
// Create a unique id for this CallStack.
|
||||||
pc = pc + (frame_count_ * 13); // Alter the PC based on position in stack.
|
pc = pc + (frame_count_ * 13); // Alter the PC based on position in stack.
|
||||||
hash_ = ~hash_ + (pc << 15);
|
hash_ = ~hash_ + (pc << 15);
|
||||||
hash_ = hash_ ^ (pc >> 12);
|
hash_ = hash_ ^ (pc >> 12);
|
||||||
hash_ = hash_ + (pc << 2);
|
hash_ = hash_ + (pc << 2);
|
||||||
hash_ = hash_ ^ (pc >> 4);
|
hash_ = hash_ ^ (pc >> 4);
|
||||||
hash_ = hash_ * 2057;
|
hash_ = hash_ * 2057;
|
||||||
hash_ = hash_ ^ (pc >> 16);
|
hash_ = hash_ ^ (pc >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CallStack::GetStackTrace() {
|
bool CallStack::GetStackTrace() {
|
||||||
// Initialize the context record.
|
// Initialize the context record.
|
||||||
CONTEXT context;
|
CONTEXT context;
|
||||||
memset(&context, 0, sizeof(context));
|
memset(&context, 0, sizeof(context));
|
||||||
context.ContextFlags = CONTEXT_FULL;
|
context.ContextFlags = CONTEXT_FULL;
|
||||||
__asm call x
|
__asm call x
|
||||||
__asm x: pop eax
|
__asm x: pop eax
|
||||||
__asm mov context.Eip, eax
|
__asm mov context.Eip, eax
|
||||||
__asm mov context.Ebp, ebp
|
__asm mov context.Ebp, ebp
|
||||||
__asm mov context.Esp, esp
|
__asm mov context.Esp, esp
|
||||||
|
|
||||||
STACKFRAME64 frame;
|
STACKFRAME64 frame;
|
||||||
memset(&frame, 0, sizeof(frame));
|
memset(&frame, 0, sizeof(frame));
|
||||||
|
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
DWORD image_type = IMAGE_FILE_MACHINE_I386;
|
DWORD image_type = IMAGE_FILE_MACHINE_I386;
|
||||||
frame.AddrPC.Offset = context.Eip;
|
frame.AddrPC.Offset = context.Eip;
|
||||||
frame.AddrPC.Mode = AddrModeFlat;
|
frame.AddrPC.Mode = AddrModeFlat;
|
||||||
frame.AddrFrame.Offset = context.Ebp;
|
frame.AddrFrame.Offset = context.Ebp;
|
||||||
frame.AddrFrame.Mode = AddrModeFlat;
|
frame.AddrFrame.Mode = AddrModeFlat;
|
||||||
frame.AddrStack.Offset = context.Esp;
|
frame.AddrStack.Offset = context.Esp;
|
||||||
frame.AddrStack.Mode = AddrModeFlat;
|
frame.AddrStack.Mode = AddrModeFlat;
|
||||||
#elif
|
#elif
|
||||||
NOT IMPLEMENTED!
|
NOT IMPLEMENTED!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HANDLE current_process = GetCurrentProcess();
|
HANDLE current_process = GetCurrentProcess();
|
||||||
HANDLE current_thread = GetCurrentThread();
|
HANDLE current_thread = GetCurrentThread();
|
||||||
|
|
||||||
// Walk the stack.
|
// Walk the stack.
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
{
|
{
|
||||||
AutoLock lock(dbghelp_lock_);
|
AutoLock lock(dbghelp_lock_);
|
||||||
|
|
||||||
while (count < kMaxTraceFrames) {
|
while (count < kMaxTraceFrames) {
|
||||||
count++;
|
count++;
|
||||||
if (!pStackWalk64(image_type,
|
if (!pStackWalk64(image_type,
|
||||||
current_process,
|
current_process,
|
||||||
current_thread,
|
current_thread,
|
||||||
&frame,
|
&frame,
|
||||||
&context,
|
&context,
|
||||||
0,
|
0,
|
||||||
pSymFunctionTableAccess64,
|
pSymFunctionTableAccess64,
|
||||||
pSymGetModuleBase64,
|
pSymGetModuleBase64,
|
||||||
NULL))
|
NULL))
|
||||||
break; // Couldn't trace back through any more frames.
|
break; // Couldn't trace back through any more frames.
|
||||||
|
|
||||||
if (frame.AddrFrame.Offset == 0)
|
if (frame.AddrFrame.Offset == 0)
|
||||||
continue; // End of stack.
|
continue; // End of stack.
|
||||||
|
|
||||||
// Push this frame's program counter onto the provided CallStack.
|
// Push this frame's program counter onto the provided CallStack.
|
||||||
AddFrame((DWORD_PTR)frame.AddrPC.Offset);
|
AddFrame((DWORD_PTR)frame.AddrPC.Offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallStack::ToString(std::string* output) {
|
void CallStack::ToString(std::string* output) {
|
||||||
static const int kStackWalkMaxNameLen = MAX_SYM_NAME;
|
static const int kStackWalkMaxNameLen = MAX_SYM_NAME;
|
||||||
HANDLE current_process = GetCurrentProcess();
|
HANDLE current_process = GetCurrentProcess();
|
||||||
|
|
||||||
if (!LoadSymbols(current_process)) {
|
if (!LoadSymbols(current_process)) {
|
||||||
*output = "Error";
|
*output = "Error";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock lock(dbghelp_lock_);
|
AutoLock lock(dbghelp_lock_);
|
||||||
|
|
||||||
// Iterate through each frame in the call stack.
|
// Iterate through each frame in the call stack.
|
||||||
for (int32 index = 0; index < frame_count_; index++) {
|
for (int32 index = 0; index < frame_count_; index++) {
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
DWORD_PTR intruction_pointer = frame(index);
|
DWORD_PTR intruction_pointer = frame(index);
|
||||||
|
|
||||||
SymbolCache::iterator it;
|
SymbolCache::iterator it;
|
||||||
it = symbol_cache_->find( intruction_pointer );
|
it = symbol_cache_->find( intruction_pointer );
|
||||||
if (it != symbol_cache_->end()) {
|
if (it != symbol_cache_->end()) {
|
||||||
line = it->second;
|
line = it->second;
|
||||||
} else {
|
} else {
|
||||||
// Try to locate a symbol for this frame.
|
// Try to locate a symbol for this frame.
|
||||||
DWORD64 symbol_displacement = 0;
|
DWORD64 symbol_displacement = 0;
|
||||||
ULONG64 buffer[(sizeof(IMAGEHLP_SYMBOL64) +
|
ULONG64 buffer[(sizeof(IMAGEHLP_SYMBOL64) +
|
||||||
sizeof(TCHAR)*kStackWalkMaxNameLen +
|
sizeof(TCHAR)*kStackWalkMaxNameLen +
|
||||||
sizeof(ULONG64) - 1) / sizeof(ULONG64)];
|
sizeof(ULONG64) - 1) / sizeof(ULONG64)];
|
||||||
IMAGEHLP_SYMBOL64* symbol = reinterpret_cast<IMAGEHLP_SYMBOL64*>(buffer);
|
IMAGEHLP_SYMBOL64* symbol = reinterpret_cast<IMAGEHLP_SYMBOL64*>(buffer);
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||||
symbol->MaxNameLength = kStackWalkMaxNameLen;
|
symbol->MaxNameLength = kStackWalkMaxNameLen;
|
||||||
BOOL ok = pSymGetSymFromAddr64(current_process, // hProcess
|
BOOL ok = pSymGetSymFromAddr64(current_process, // hProcess
|
||||||
intruction_pointer, // Address
|
intruction_pointer, // Address
|
||||||
&symbol_displacement, // Displacement
|
&symbol_displacement, // Displacement
|
||||||
symbol); // Symbol
|
symbol); // Symbol
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// Try to locate more source information for the symbol.
|
// Try to locate more source information for the symbol.
|
||||||
IMAGEHLP_LINE64 Line;
|
IMAGEHLP_LINE64 Line;
|
||||||
memset(&Line, 0, sizeof(Line));
|
memset(&Line, 0, sizeof(Line));
|
||||||
Line.SizeOfStruct = sizeof(Line);
|
Line.SizeOfStruct = sizeof(Line);
|
||||||
DWORD line_displacement;
|
DWORD line_displacement;
|
||||||
ok = pSymGetLineFromAddr64(current_process,
|
ok = pSymGetLineFromAddr64(current_process,
|
||||||
intruction_pointer,
|
intruction_pointer,
|
||||||
&line_displacement,
|
&line_displacement,
|
||||||
&Line);
|
&Line);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// Skip junk symbols from our internal stuff.
|
// Skip junk symbols from our internal stuff.
|
||||||
if (strstr(symbol->Name, "CallStack::") ||
|
if (strstr(symbol->Name, "CallStack::") ||
|
||||||
strstr(symbol->Name, "MemoryWatcher::") ||
|
strstr(symbol->Name, "MemoryWatcher::") ||
|
||||||
strstr(symbol->Name, "Perftools_") ||
|
strstr(symbol->Name, "Perftools_") ||
|
||||||
strstr(symbol->Name, "MemoryHook::") ) {
|
strstr(symbol->Name, "MemoryHook::") ) {
|
||||||
// Just record a blank string.
|
// Just record a blank string.
|
||||||
(*symbol_cache_)[intruction_pointer] = std::string("");
|
(*symbol_cache_)[intruction_pointer] = std::string("");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
line += " ";
|
line += " ";
|
||||||
line += static_cast<char*>(Line.FileName);
|
line += static_cast<char*>(Line.FileName);
|
||||||
line += " (";
|
line += " (";
|
||||||
line += IntToString(Line.LineNumber);
|
line += IntToString(Line.LineNumber);
|
||||||
line += "): ";
|
line += "): ";
|
||||||
line += symbol->Name;
|
line += symbol->Name;
|
||||||
line += "\n";
|
line += "\n";
|
||||||
} else {
|
} else {
|
||||||
line += " unknown (0):";
|
line += " unknown (0):";
|
||||||
line += symbol->Name;
|
line += symbol->Name;
|
||||||
line += "\n";
|
line += "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// OK - couldn't get any info. Try for the module.
|
// OK - couldn't get any info. Try for the module.
|
||||||
IMAGEHLP_MODULE64 module_info;
|
IMAGEHLP_MODULE64 module_info;
|
||||||
module_info.SizeOfStruct = sizeof(module_info);
|
module_info.SizeOfStruct = sizeof(module_info);
|
||||||
if (pSymGetModuleInfo64(current_process, intruction_pointer,
|
if (pSymGetModuleInfo64(current_process, intruction_pointer,
|
||||||
&module_info)) {
|
&module_info)) {
|
||||||
line += " (";
|
line += " (";
|
||||||
line += static_cast<char*>(module_info.ModuleName);
|
line += static_cast<char*>(module_info.ModuleName);
|
||||||
line += ")\n";
|
line += ")\n";
|
||||||
} else {
|
} else {
|
||||||
line += " ???\n";
|
line += " ???\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(*symbol_cache_)[intruction_pointer] = line;
|
(*symbol_cache_)[intruction_pointer] = line;
|
||||||
*output += line;
|
*output += line;
|
||||||
}
|
}
|
||||||
*output += "==================\n";
|
*output += "==================\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Lock AllocationStack::freelist_lock_;
|
Lock AllocationStack::freelist_lock_;
|
||||||
AllocationStack* AllocationStack::freelist_ = NULL;
|
AllocationStack* AllocationStack::freelist_ = NULL;
|
||||||
|
|
||||||
void* AllocationStack::operator new(size_t size) {
|
void* AllocationStack::operator new(size_t size) {
|
||||||
DCHECK(size == sizeof(AllocationStack));
|
DCHECK(size == sizeof(AllocationStack));
|
||||||
{
|
{
|
||||||
AutoLock lock(freelist_lock_);
|
AutoLock lock(freelist_lock_);
|
||||||
if (freelist_ != NULL) {
|
if (freelist_ != NULL) {
|
||||||
AllocationStack* stack = freelist_;
|
AllocationStack* stack = freelist_;
|
||||||
freelist_ = freelist_->next_;
|
freelist_ = freelist_->next_;
|
||||||
stack->next_ = NULL;
|
stack->next_ = NULL;
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MemoryHook::Alloc(size);
|
return MemoryHook::Alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AllocationStack::operator delete(void* ptr) {
|
void AllocationStack::operator delete(void* ptr) {
|
||||||
AllocationStack *stack = reinterpret_cast<AllocationStack*>(ptr);
|
AllocationStack *stack = reinterpret_cast<AllocationStack*>(ptr);
|
||||||
AutoLock lock(freelist_lock_);
|
AutoLock lock(freelist_lock_);
|
||||||
DCHECK(stack->next_ == NULL);
|
DCHECK(stack->next_ == NULL);
|
||||||
stack->next_ = freelist_;
|
stack->next_ = freelist_;
|
||||||
freelist_ = stack;
|
freelist_ = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,46 +1,46 @@
|
|||||||
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
# 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
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone(
|
env = env.Clone(
|
||||||
PCRE_DIR = '$WEBKIT_DIR/port/JavaScriptCore/pcre',
|
PCRE_DIR = '$WEBKIT_DIR/port/JavaScriptCore/pcre',
|
||||||
)
|
)
|
||||||
|
|
||||||
env.Prepend(
|
env.Prepend(
|
||||||
CPPPATH = [
|
CPPPATH = [
|
||||||
'$WEBKIT_DIR/port/JavaScriptCore',
|
'$WEBKIT_DIR/port/JavaScriptCore',
|
||||||
'$WEBKIT_DIR/port/JavaScriptCore/pcre',
|
'$WEBKIT_DIR/port/JavaScriptCore/pcre',
|
||||||
'$WEBKIT_DIR/build/JSConfig/WebCore/v8',
|
'$WEBKIT_DIR/build/JSConfig/WebCore/v8',
|
||||||
])
|
])
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
env.Prepend(
|
env.Prepend(
|
||||||
CCFLAGS = [
|
CCFLAGS = [
|
||||||
'/TP',
|
'/TP',
|
||||||
'/wd4127',
|
'/wd4127',
|
||||||
'/wd4355',
|
'/wd4355',
|
||||||
'/wd4510',
|
'/wd4510',
|
||||||
'/wd4512',
|
'/wd4512',
|
||||||
'/wd4610',
|
'/wd4610',
|
||||||
'/wd4706',
|
'/wd4706',
|
||||||
'/wd4800',
|
'/wd4800',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
dir = env.Dir('$PCRE_DIR')
|
dir = env.Dir('$PCRE_DIR')
|
||||||
|
|
||||||
dir.addRepository(env.Dir('#/../webkit/pending'))
|
dir.addRepository(env.Dir('#/../webkit/pending'))
|
||||||
dir.addRepository(env.Dir('#/../third_party/WebKit/JavaScriptCore/pcre'))
|
dir.addRepository(env.Dir('#/../third_party/WebKit/JavaScriptCore/pcre'))
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'$PCRE_DIR/pcre_compile.cpp',
|
'$PCRE_DIR/pcre_compile.cpp',
|
||||||
'$PCRE_DIR/pcre_xclass.cpp',
|
'$PCRE_DIR/pcre_xclass.cpp',
|
||||||
'$PCRE_DIR/pcre_ucp_searchfuncs.cpp',
|
'$PCRE_DIR/pcre_ucp_searchfuncs.cpp',
|
||||||
'$PCRE_DIR/pcre_tables.cpp',
|
'$PCRE_DIR/pcre_tables.cpp',
|
||||||
'$PCRE_DIR/pcre_exec.cpp',
|
'$PCRE_DIR/pcre_exec.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary('JavaScriptCore_pcre', input_files)
|
env.ChromeStaticLibrary('JavaScriptCore_pcre', input_files)
|
||||||
|
|
||||||
|
@@ -1,127 +1,127 @@
|
|||||||
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
# 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
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env = env.Clone()
|
env = env.Clone()
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
env.Prepend(
|
env.Prepend(
|
||||||
CCFLAGS = [
|
CCFLAGS = [
|
||||||
'/TP',
|
'/TP',
|
||||||
|
|
||||||
'/wd4244',
|
'/wd4244',
|
||||||
'/wd4291',
|
'/wd4291',
|
||||||
'/wd4345',
|
'/wd4345',
|
||||||
'/wd4521',
|
'/wd4521',
|
||||||
'/wd4800',
|
'/wd4800',
|
||||||
],)
|
],)
|
||||||
|
|
||||||
input_files = [
|
input_files = [
|
||||||
'$PORT_DIR/css/RGBColor.cpp',
|
'$PORT_DIR/css/RGBColor.cpp',
|
||||||
'$PORT_DIR/history/CachedPage.cpp',
|
'$PORT_DIR/history/CachedPage.cpp',
|
||||||
'$PORT_DIR/platform/TemporaryLinkStubs.cpp',
|
'$PORT_DIR/platform/TemporaryLinkStubs.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
# TODO(erg): Temporarily disabling these until the big webkit merge is
|
# TODO(erg): Temporarily disabling these until the big webkit merge is
|
||||||
# complete; we're just out of date here.
|
# complete; we're just out of date here.
|
||||||
input_files += [
|
input_files += [
|
||||||
'$PORT_DIR/platform/graphics/AffineTransformSkia.cpp',
|
'$PORT_DIR/platform/graphics/AffineTransformSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/ImageSourceSkia.cpp',
|
'$PORT_DIR/platform/graphics/ImageSourceSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/NativeImageSkia.cpp',
|
'$PORT_DIR/platform/graphics/NativeImageSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/PathSkia.cpp',
|
'$PORT_DIR/platform/graphics/PathSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/SkiaUtils.cpp',
|
'$PORT_DIR/platform/graphics/SkiaUtils.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SkiaSupport.cpp',
|
'$PORT_DIR/platform/graphics/svg/SkiaSupport.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/RenderPathSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/RenderPathSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGPaintServerGradientSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGPaintServerGradientSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGPaintServerPatternSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGPaintServerPatternSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGPaintServerSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGPaintServerSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGPaintServerSolidSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGPaintServerSolidSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGResourceClipperSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGResourceClipperSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGResourceFilterSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGResourceFilterSkia.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/bmp/BMPImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/bmp/BMPImageDecoder.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/bmp/BMPImageReader.cpp',
|
'$PORT_DIR/platform/image-decoders/bmp/BMPImageReader.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/gif/GIFImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/gif/GIFImageDecoder.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/gif/GIFImageReader.cpp',
|
'$PORT_DIR/platform/image-decoders/gif/GIFImageReader.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/ico/ICOImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/ico/ICOImageDecoder.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/jpeg/JPEGImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/jpeg/JPEGImageDecoder.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/png/PNGImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/png/PNGImageDecoder.cpp',
|
||||||
'$PORT_DIR/platform/image-decoders/xbm/XBMImageDecoder.cpp',
|
'$PORT_DIR/platform/image-decoders/xbm/XBMImageDecoder.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
# These files aren't win32-specific, they're just files that haven't yet been
|
# These files aren't win32-specific, they're just files that haven't yet been
|
||||||
# made portable.
|
# made portable.
|
||||||
input_files = [
|
input_files = [
|
||||||
'$PORT_DIR/bridge/FrameWin.cpp',
|
'$PORT_DIR/bridge/FrameWin.cpp',
|
||||||
'$PORT_DIR/bridge/HistoryWin.cpp',
|
'$PORT_DIR/bridge/HistoryWin.cpp',
|
||||||
'$PORT_DIR/bridge/PageWin.cpp',
|
'$PORT_DIR/bridge/PageWin.cpp',
|
||||||
'$PORT_DIR/bridge/PluginsWin.cpp',
|
'$PORT_DIR/bridge/PluginsWin.cpp',
|
||||||
'$PORT_DIR/history/BackForwardList.cpp',
|
'$PORT_DIR/history/BackForwardList.cpp',
|
||||||
'$PORT_DIR/loader/IconDatabaseNone.cpp',
|
'$PORT_DIR/loader/IconDatabaseNone.cpp',
|
||||||
'$PORT_DIR/loader/IconLoader.cpp',
|
'$PORT_DIR/loader/IconLoader.cpp',
|
||||||
'$PORT_DIR/page/AXObjectCacheWin.cpp',
|
'$PORT_DIR/page/AXObjectCacheWin.cpp',
|
||||||
'$PORT_DIR/page/DragControllerWin.cpp',
|
'$PORT_DIR/page/DragControllerWin.cpp',
|
||||||
'$PORT_DIR/page/EventHandlerWin.cpp',
|
'$PORT_DIR/page/EventHandlerWin.cpp',
|
||||||
'$PORT_DIR/platform/BString.cpp',
|
'$PORT_DIR/platform/BString.cpp',
|
||||||
'$PORT_DIR/platform/ClipboardUtilitiesWin.cpp',
|
'$PORT_DIR/platform/ClipboardUtilitiesWin.cpp',
|
||||||
'$PORT_DIR/platform/ClipboardWin.cpp',
|
'$PORT_DIR/platform/ClipboardWin.cpp',
|
||||||
'$PORT_DIR/platform/ContextMenuItemWin.cpp',
|
'$PORT_DIR/platform/ContextMenuItemWin.cpp',
|
||||||
'$PORT_DIR/platform/ContextMenuWin.cpp',
|
'$PORT_DIR/platform/ContextMenuWin.cpp',
|
||||||
'$PORT_DIR/platform/CursorWin.cpp',
|
'$PORT_DIR/platform/CursorWin.cpp',
|
||||||
'$PORT_DIR/platform/DragDataWin.cpp',
|
'$PORT_DIR/platform/DragDataWin.cpp',
|
||||||
'$PORT_DIR/platform/DragImageWin.cpp',
|
'$PORT_DIR/platform/DragImageWin.cpp',
|
||||||
'$PORT_DIR/platform/EditorWin.cpp',
|
'$PORT_DIR/platform/EditorWin.cpp',
|
||||||
'$PORT_DIR/platform/FileChooserWin.cpp',
|
'$PORT_DIR/platform/FileChooserWin.cpp',
|
||||||
'$PORT_DIR/platform/FramelessScrollView.cpp',
|
'$PORT_DIR/platform/FramelessScrollView.cpp',
|
||||||
'$PORT_DIR/platform/GKURL.cpp',
|
'$PORT_DIR/platform/GKURL.cpp',
|
||||||
'$PORT_DIR/platform/KeyEventWin.cpp',
|
'$PORT_DIR/platform/KeyEventWin.cpp',
|
||||||
'$PORT_DIR/platform/Language.cpp',
|
'$PORT_DIR/platform/Language.cpp',
|
||||||
'$PORT_DIR/platform/LogWin.cpp',
|
'$PORT_DIR/platform/LogWin.cpp',
|
||||||
'$PORT_DIR/platform/MimeTypeRegistryWin.cpp',
|
'$PORT_DIR/platform/MimeTypeRegistryWin.cpp',
|
||||||
'$PORT_DIR/platform/PasteboardWin.cpp',
|
'$PORT_DIR/platform/PasteboardWin.cpp',
|
||||||
'$PORT_DIR/platform/PlatformMouseEventWin.cpp',
|
'$PORT_DIR/platform/PlatformMouseEventWin.cpp',
|
||||||
'$PORT_DIR/platform/PlatformScrollBarWin.cpp',
|
'$PORT_DIR/platform/PlatformScrollBarWin.cpp',
|
||||||
'$PORT_DIR/platform/PopupMenuWin.cpp',
|
'$PORT_DIR/platform/PopupMenuWin.cpp',
|
||||||
'$PORT_DIR/platform/SSLKeyGeneratorWin.cpp',
|
'$PORT_DIR/platform/SSLKeyGeneratorWin.cpp',
|
||||||
'$PORT_DIR/platform/ScreenWin.cpp',
|
'$PORT_DIR/platform/ScreenWin.cpp',
|
||||||
'$PORT_DIR/platform/ScrollViewWin.cpp',
|
'$PORT_DIR/platform/ScrollViewWin.cpp',
|
||||||
'$PORT_DIR/platform/SearchPopupMenuWin.cpp',
|
'$PORT_DIR/platform/SearchPopupMenuWin.cpp',
|
||||||
'$PORT_DIR/platform/SharedTimerWin.cpp',
|
'$PORT_DIR/platform/SharedTimerWin.cpp',
|
||||||
'$PORT_DIR/platform/SoundWin.cpp',
|
'$PORT_DIR/platform/SoundWin.cpp',
|
||||||
'$PORT_DIR/platform/SystemTimeWin.cpp',
|
'$PORT_DIR/platform/SystemTimeWin.cpp',
|
||||||
'$PORT_DIR/platform/TextBoundariesWin.cpp',
|
'$PORT_DIR/platform/TextBoundariesWin.cpp',
|
||||||
'$PORT_DIR/platform/TextBreakIteratorInternalICUWin.cpp',
|
'$PORT_DIR/platform/TextBreakIteratorInternalICUWin.cpp',
|
||||||
'$PORT_DIR/platform/UniscribeStateTextRun.cpp',
|
'$PORT_DIR/platform/UniscribeStateTextRun.cpp',
|
||||||
'$PORT_DIR/platform/WCDataObject.cpp',
|
'$PORT_DIR/platform/WCDataObject.cpp',
|
||||||
'$PORT_DIR/platform/WheelEventWin.cpp',
|
'$PORT_DIR/platform/WheelEventWin.cpp',
|
||||||
'$PORT_DIR/platform/WidgetWin.cpp',
|
'$PORT_DIR/platform/WidgetWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/FontCacheWin.cpp',
|
'$PORT_DIR/platform/graphics/FontCacheWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/FontCustomPlatformData.cpp',
|
'$PORT_DIR/platform/graphics/FontCustomPlatformData.cpp',
|
||||||
'$PORT_DIR/platform/graphics/FontPlatformDataWin.cpp',
|
'$PORT_DIR/platform/graphics/FontPlatformDataWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/FontWin.cpp',
|
'$PORT_DIR/platform/graphics/FontWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/GlyphPageTreeNodeWin.cpp',
|
'$PORT_DIR/platform/graphics/GlyphPageTreeNodeWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/GraphicsContextSkia.cpp',
|
'$PORT_DIR/platform/graphics/GraphicsContextSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/IconWin.cpp',
|
'$PORT_DIR/platform/graphics/IconWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/ImageBufferSkia.cpp',
|
'$PORT_DIR/platform/graphics/ImageBufferSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/ImageSkia.cpp',
|
'$PORT_DIR/platform/graphics/ImageSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/PlatformContextSkia.cpp',
|
'$PORT_DIR/platform/graphics/PlatformContextSkia.cpp',
|
||||||
'$PORT_DIR/platform/graphics/SimpleFontDataWin.cpp',
|
'$PORT_DIR/platform/graphics/SimpleFontDataWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/SkGraphicsContext.cpp',
|
'$PORT_DIR/platform/graphics/SkGraphicsContext.cpp',
|
||||||
'$PORT_DIR/platform/graphics/SkPaintContext.cpp',
|
'$PORT_DIR/platform/graphics/SkPaintContext.cpp',
|
||||||
'$PORT_DIR/platform/graphics/svg/SVGResourceMaskerSkia.cpp',
|
'$PORT_DIR/platform/graphics/svg/SVGResourceMaskerSkia.cpp',
|
||||||
'$PORT_DIR/platform/network/CookieJarWin.cpp',
|
'$PORT_DIR/platform/network/CookieJarWin.cpp',
|
||||||
'$PORT_DIR/rendering/RenderThemeWin.cpp',
|
'$PORT_DIR/rendering/RenderThemeWin.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
if env['PLATFORM'] == 'win32':
|
if env['PLATFORM'] == 'win32':
|
||||||
# These are extremely win32 specific and will never be ported.
|
# These are extremely win32 specific and will never be ported.
|
||||||
input_files = [
|
input_files = [
|
||||||
'$PORT_DIR/platform/graphics/IntPointWin.cpp',
|
'$PORT_DIR/platform/graphics/IntPointWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/IntRectWin.cpp',
|
'$PORT_DIR/platform/graphics/IntRectWin.cpp',
|
||||||
'$PORT_DIR/platform/graphics/IntSizeWin.cpp',
|
'$PORT_DIR/platform/graphics/IntSizeWin.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
env.ChromeStaticLibrary("port", input_files)
|
env.ChromeStaticLibrary("port", input_files)
|
||||||
|
@@ -1,25 +1,25 @@
|
|||||||
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef Peerable_h
|
#ifndef Peerable_h
|
||||||
#define Peerable_h
|
#define Peerable_h
|
||||||
|
|
||||||
#include <wtf/Noncopyable.h>
|
#include <wtf/Noncopyable.h>
|
||||||
|
|
||||||
#if USE(V8_BINDING)
|
#if USE(V8_BINDING)
|
||||||
|
|
||||||
namespace WebCore {
|
namespace WebCore {
|
||||||
|
|
||||||
class Peerable : Noncopyable {
|
class Peerable : Noncopyable {
|
||||||
public:
|
public:
|
||||||
virtual void setPeer(void* peer) = 0;
|
virtual void setPeer(void* peer) = 0;
|
||||||
virtual void* peer() const = 0;
|
virtual void* peer() const = 0;
|
||||||
protected:
|
protected:
|
||||||
virtual ~Peerable() { }
|
virtual ~Peerable() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USE(V8_BINDING)
|
#endif // USE(V8_BINDING)
|
||||||
#endif // Peerable_h
|
#endif // Peerable_h
|
||||||
|
@@ -1,259 +1,259 @@
|
|||||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
// Copied from base/basictypes.h with some modifications
|
// Copied from base/basictypes.h with some modifications
|
||||||
|
|
||||||
#ifndef V8_PROPERTY_H__
|
#ifndef V8_PROPERTY_H__
|
||||||
#define V8_PROPERTY_H__
|
#define V8_PROPERTY_H__
|
||||||
|
|
||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
#include "v8_proxy.h"
|
#include "v8_proxy.h"
|
||||||
|
|
||||||
namespace WebCore {
|
namespace WebCore {
|
||||||
|
|
||||||
// Returns named property of a collection.
|
// Returns named property of a collection.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> GetNamedPropertyOfCollection(
|
static v8::Handle<v8::Value> GetNamedPropertyOfCollection(
|
||||||
v8::Local<v8::String> name,
|
v8::Local<v8::String> name,
|
||||||
v8::Local<v8::Object> object,
|
v8::Local<v8::Object> object,
|
||||||
v8::Local<v8::Value> data) {
|
v8::Local<v8::Value> data) {
|
||||||
// TODO: assert object is a collection type
|
// TODO: assert object is a collection type
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
||||||
ASSERT(t != V8ClassIndex::NODE);
|
ASSERT(t != V8ClassIndex::NODE);
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
||||||
String prop_name = ToWebCoreString(name);
|
String prop_name = ToWebCoreString(name);
|
||||||
void* result = collection->namedItem(prop_name);
|
void* result = collection->namedItem(prop_name);
|
||||||
if (!result) return v8::Handle<v8::Value>();
|
if (!result) return v8::Handle<v8::Value>();
|
||||||
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
|
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
|
||||||
if (type == V8ClassIndex::NODE)
|
if (type == V8ClassIndex::NODE)
|
||||||
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
||||||
else
|
else
|
||||||
return V8Proxy::ToV8Object(type, result);
|
return V8Proxy::ToV8Object(type, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A template of named property accessor of collections.
|
// A template of named property accessor of collections.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> CollectionNamedPropertyGetter(
|
static v8::Handle<v8::Value> CollectionNamedPropertyGetter(
|
||||||
v8::Local<v8::String> name, const v8::AccessorInfo& info) {
|
v8::Local<v8::String> name, const v8::AccessorInfo& info) {
|
||||||
return GetNamedPropertyOfCollection<C>(name, info.Holder(), info.Data());
|
return GetNamedPropertyOfCollection<C>(name, info.Holder(), info.Data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A template of named property accessor of HTMLSelectElement and
|
// A template of named property accessor of HTMLSelectElement and
|
||||||
// HTMLFormElement.
|
// HTMLFormElement.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> NodeCollectionNamedPropertyGetter(
|
static v8::Handle<v8::Value> NodeCollectionNamedPropertyGetter(
|
||||||
v8::Local<v8::String> name, const v8::AccessorInfo& info) {
|
v8::Local<v8::String> name, const v8::AccessorInfo& info) {
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
||||||
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
||||||
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
||||||
String prop_name = ToWebCoreString(name);
|
String prop_name = ToWebCoreString(name);
|
||||||
void* result = collection->namedItem(prop_name);
|
void* result = collection->namedItem(prop_name);
|
||||||
if (!result) return v8::Handle<v8::Value>();
|
if (!result) return v8::Handle<v8::Value>();
|
||||||
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
|
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
|
||||||
if (type == V8ClassIndex::NODE)
|
if (type == V8ClassIndex::NODE)
|
||||||
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
||||||
else
|
else
|
||||||
return V8Proxy::ToV8Object(type, result);
|
return V8Proxy::ToV8Object(type, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A template returns whether a collection has a named property.
|
// A template returns whether a collection has a named property.
|
||||||
// This function does not cause JS heap allocation.
|
// This function does not cause JS heap allocation.
|
||||||
template <class C>
|
template <class C>
|
||||||
static bool HasNamedPropertyOfCollection(v8::Local<v8::String> name,
|
static bool HasNamedPropertyOfCollection(v8::Local<v8::String> name,
|
||||||
v8::Local<v8::Object> object,
|
v8::Local<v8::Object> object,
|
||||||
v8::Local<v8::Value> data) {
|
v8::Local<v8::Value> data) {
|
||||||
// TODO: assert object is a collection type
|
// TODO: assert object is a collection type
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
||||||
|
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
||||||
String prop_name = ToWebCoreString(name);
|
String prop_name = ToWebCoreString(name);
|
||||||
void* result = collection->namedItem(prop_name);
|
void* result = collection->namedItem(prop_name);
|
||||||
return result != NULL;
|
return result != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns the property at the index of a collection.
|
// Returns the property at the index of a collection.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> GetIndexedPropertyOfCollection(
|
static v8::Handle<v8::Value> GetIndexedPropertyOfCollection(
|
||||||
uint32_t index, v8::Local<v8::Object> object, v8::Local<v8::Value> data) {
|
uint32_t index, v8::Local<v8::Object> object, v8::Local<v8::Value> data) {
|
||||||
// TODO, assert that object must be a collection type
|
// TODO, assert that object must be a collection type
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
||||||
ASSERT(t != V8ClassIndex::NODE);
|
ASSERT(t != V8ClassIndex::NODE);
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
||||||
void* result = collection->item(index);
|
void* result = collection->item(index);
|
||||||
if (!result) return v8::Handle<v8::Value>();
|
if (!result) return v8::Handle<v8::Value>();
|
||||||
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
|
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
|
||||||
if (type == V8ClassIndex::NODE)
|
if (type == V8ClassIndex::NODE)
|
||||||
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
||||||
else
|
else
|
||||||
return V8Proxy::ToV8Object(type, result);
|
return V8Proxy::ToV8Object(type, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A template of index interceptor of collections.
|
// A template of index interceptor of collections.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> CollectionIndexedPropertyGetter(
|
static v8::Handle<v8::Value> CollectionIndexedPropertyGetter(
|
||||||
uint32_t index, const v8::AccessorInfo& info) {
|
uint32_t index, const v8::AccessorInfo& info) {
|
||||||
return GetIndexedPropertyOfCollection<C>(index, info.Holder(), info.Data());
|
return GetIndexedPropertyOfCollection<C>(index, info.Holder(), info.Data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A template of index interceptor of HTMLSelectElement and HTMLFormElement.
|
// A template of index interceptor of HTMLSelectElement and HTMLFormElement.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> NodeCollectionIndexedPropertyGetter(
|
static v8::Handle<v8::Value> NodeCollectionIndexedPropertyGetter(
|
||||||
uint32_t index, const v8::AccessorInfo& info) {
|
uint32_t index, const v8::AccessorInfo& info) {
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
||||||
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
||||||
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
||||||
void* result = collection->item(index);
|
void* result = collection->item(index);
|
||||||
if (!result) return v8::Handle<v8::Value>();
|
if (!result) return v8::Handle<v8::Value>();
|
||||||
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
|
V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
|
||||||
if (type == V8ClassIndex::NODE)
|
if (type == V8ClassIndex::NODE)
|
||||||
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
|
||||||
else
|
else
|
||||||
return V8Proxy::ToV8Object(type, result);
|
return V8Proxy::ToV8Object(type, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get an array containing the names of indexed properties of
|
// Get an array containing the names of indexed properties of
|
||||||
// HTMLSelectElement and HTMLFormElement.
|
// HTMLSelectElement and HTMLFormElement.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Array> NodeCollectionIndexedPropertyEnumerator(
|
static v8::Handle<v8::Array> NodeCollectionIndexedPropertyEnumerator(
|
||||||
const v8::AccessorInfo& info) {
|
const v8::AccessorInfo& info) {
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
||||||
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
|
||||||
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
|
||||||
int length = collection->length();
|
int length = collection->length();
|
||||||
v8::Handle<v8::Array> properties = v8::Array::New(length);
|
v8::Handle<v8::Array> properties = v8::Array::New(length);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
// TODO(ager): Do we need to check that the item function returns
|
// TODO(ager): Do we need to check that the item function returns
|
||||||
// a non-null value for this index?
|
// a non-null value for this index?
|
||||||
v8::Handle<v8::Integer> integer = v8::Integer::New(i);
|
v8::Handle<v8::Integer> integer = v8::Integer::New(i);
|
||||||
properties->Set(integer, integer);
|
properties->Set(integer, integer);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get an array containing the names of indexed properties in a collection.
|
// Get an array containing the names of indexed properties in a collection.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Array> CollectionIndexedPropertyEnumerator(
|
static v8::Handle<v8::Array> CollectionIndexedPropertyEnumerator(
|
||||||
const v8::AccessorInfo& info) {
|
const v8::AccessorInfo& info) {
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(info.Holder());
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(info.Holder());
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, info.Holder());
|
C* collection = V8Proxy::ToNativeObject<C>(t, info.Holder());
|
||||||
int length = collection->length();
|
int length = collection->length();
|
||||||
v8::Handle<v8::Array> properties = v8::Array::New(length);
|
v8::Handle<v8::Array> properties = v8::Array::New(length);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
// TODO(ager): Do we need to check that the item function returns
|
// TODO(ager): Do we need to check that the item function returns
|
||||||
// a non-null value for this index?
|
// a non-null value for this index?
|
||||||
v8::Handle<v8::Integer> integer = v8::Integer::New(i);
|
v8::Handle<v8::Integer> integer = v8::Integer::New(i);
|
||||||
properties->Set(integer, integer);
|
properties->Set(integer, integer);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns whether a collection has a property at a given index.
|
// Returns whether a collection has a property at a given index.
|
||||||
// This function does not cause JS heap allocation.
|
// This function does not cause JS heap allocation.
|
||||||
template <class C>
|
template <class C>
|
||||||
static bool HasIndexedPropertyOfCollection(uint32_t index,
|
static bool HasIndexedPropertyOfCollection(uint32_t index,
|
||||||
v8::Local<v8::Object> object,
|
v8::Local<v8::Object> object,
|
||||||
v8::Local<v8::Value> data) {
|
v8::Local<v8::Value> data) {
|
||||||
// TODO, assert that object must be a collection type
|
// TODO, assert that object must be a collection type
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
ASSERT(V8Proxy::MaybeDOMWrapper(object));
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
C* collection = V8Proxy::ToNativeObject<C>(t, object);
|
||||||
void* result = collection->item(index);
|
void* result = collection->item(index);
|
||||||
return result != NULL;
|
return result != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A template for indexed getters on collections of strings that should return
|
// A template for indexed getters on collections of strings that should return
|
||||||
// null if the resulting string is a null string.
|
// null if the resulting string is a null string.
|
||||||
template <class C>
|
template <class C>
|
||||||
static v8::Handle<v8::Value> CollectionStringOrNullIndexedPropertyGetter(
|
static v8::Handle<v8::Value> CollectionStringOrNullIndexedPropertyGetter(
|
||||||
uint32_t index, const v8::AccessorInfo& info) {
|
uint32_t index, const v8::AccessorInfo& info) {
|
||||||
// TODO, assert that object must be a collection type
|
// TODO, assert that object must be a collection type
|
||||||
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
ASSERT(V8Proxy::MaybeDOMWrapper(info.Holder()));
|
||||||
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(info.Holder());
|
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(info.Holder());
|
||||||
C* collection = V8Proxy::ToNativeObject<C>(t, info.Holder());
|
C* collection = V8Proxy::ToNativeObject<C>(t, info.Holder());
|
||||||
String result = collection->item(index);
|
String result = collection->item(index);
|
||||||
return v8StringOrNull(result);
|
return v8StringOrNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add indexed getter to the function template for a collection.
|
// Add indexed getter to the function template for a collection.
|
||||||
template <class T>
|
template <class T>
|
||||||
static void SetCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc,
|
static void SetCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc,
|
||||||
V8ClassIndex::V8WrapperType type) {
|
V8ClassIndex::V8WrapperType type) {
|
||||||
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
||||||
CollectionIndexedPropertyGetter<T>,
|
CollectionIndexedPropertyGetter<T>,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
CollectionIndexedPropertyEnumerator<T>,
|
CollectionIndexedPropertyEnumerator<T>,
|
||||||
v8::External::New(reinterpret_cast<void*>(type)));
|
v8::External::New(reinterpret_cast<void*>(type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add named getter to the function template for a collection.
|
// Add named getter to the function template for a collection.
|
||||||
template <class T>
|
template <class T>
|
||||||
static void SetCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc,
|
static void SetCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc,
|
||||||
V8ClassIndex::V8WrapperType type) {
|
V8ClassIndex::V8WrapperType type) {
|
||||||
desc->InstanceTemplate()->SetNamedPropertyHandler(
|
desc->InstanceTemplate()->SetNamedPropertyHandler(
|
||||||
CollectionNamedPropertyGetter<T>,
|
CollectionNamedPropertyGetter<T>,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
v8::External::New(reinterpret_cast<void*>(type)));
|
v8::External::New(reinterpret_cast<void*>(type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add named and indexed getters to the function template for a collection.
|
// Add named and indexed getters to the function template for a collection.
|
||||||
template <class T>
|
template <class T>
|
||||||
static void SetCollectionIndexedAndNamedGetters(
|
static void SetCollectionIndexedAndNamedGetters(
|
||||||
v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type) {
|
v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type) {
|
||||||
// If we interceptor before object, accessing 'length' can trigger
|
// If we interceptor before object, accessing 'length' can trigger
|
||||||
// a webkit assertion error.
|
// a webkit assertion error.
|
||||||
// (see fast/dom/HTMLDocument/document-special-properties.html
|
// (see fast/dom/HTMLDocument/document-special-properties.html
|
||||||
desc->InstanceTemplate()->SetNamedPropertyHandler(
|
desc->InstanceTemplate()->SetNamedPropertyHandler(
|
||||||
CollectionNamedPropertyGetter<T>,
|
CollectionNamedPropertyGetter<T>,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
v8::External::New(reinterpret_cast<void*>(type)));
|
v8::External::New(reinterpret_cast<void*>(type)));
|
||||||
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
||||||
CollectionIndexedPropertyGetter<T>,
|
CollectionIndexedPropertyGetter<T>,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
CollectionIndexedPropertyEnumerator<T>,
|
CollectionIndexedPropertyEnumerator<T>,
|
||||||
v8::External::New(reinterpret_cast<void*>(type)));
|
v8::External::New(reinterpret_cast<void*>(type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add indexed getter returning a string or null to a function template
|
// Add indexed getter returning a string or null to a function template
|
||||||
// for a collection.
|
// for a collection.
|
||||||
template <class T>
|
template <class T>
|
||||||
static void SetCollectionStringOrNullIndexedGetter(
|
static void SetCollectionStringOrNullIndexedGetter(
|
||||||
v8::Handle<v8::FunctionTemplate> desc) {
|
v8::Handle<v8::FunctionTemplate> desc) {
|
||||||
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
desc->InstanceTemplate()->SetIndexedPropertyHandler(
|
||||||
CollectionStringOrNullIndexedPropertyGetter<T>,
|
CollectionStringOrNullIndexedPropertyGetter<T>,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
CollectionIndexedPropertyEnumerator<T>);
|
CollectionIndexedPropertyEnumerator<T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace WebCore
|
} // namespace WebCore
|
||||||
|
|
||||||
#endif // V8_PROPERTY_H__
|
#endif // V8_PROPERTY_H__
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user