diff options
author | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
---|---|---|
committer | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
commit | 62f2e80c79f7d660d7871b14287cef9082fcc32f (patch) | |
tree | 310edb9b2c0aa8409defc654979719cb4d8a4059 /skia/ext/platform_device.cc | |
parent | c89b244483969aa8859a1d4bb3396f6ceb54f875 (diff) | |
download | chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.zip chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.gz chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.bz2 |
This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata.
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Review URL: http://codereview.chromium.org/7019013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/platform_device.cc')
-rw-r--r-- | skia/ext/platform_device.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/skia/ext/platform_device.cc b/skia/ext/platform_device.cc new file mode 100644 index 0000000..eff5d4f --- /dev/null +++ b/skia/ext/platform_device.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/platform_device.h" + +#include "third_party/skia/include/core/SkMetaData.h" + +namespace skia { + +namespace { +const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; +} + +void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { + SkMetaData& meta_data = device->getMetaData(); + meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); +} + +PlatformDevice* GetPlatformDevice(SkDevice* device) { + SkMetaData& meta_data = device->getMetaData(); + PlatformDevice* device_behaviour = NULL; + if (meta_data.findPtr(kDevicePlatformBehaviour, + reinterpret_cast<void**>(&device_behaviour))) + return device_behaviour; + + return NULL; +} + +PlatformSurface BeginPlatformPaint(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->BeginPlatformPaint(); + + return 0; +} + +void EndPlatformPaint(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->EndPlatformPaint(); +} + +bool IsVectorial(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->IsVectorial(); + + return device->getDeviceCapabilities() & SkDevice::kVector_Capability; +} + +bool IsNativeFontRenderingAllowed(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->IsNativeFontRenderingAllowed(); + + return false; +} + +void DrawToNativeContext(SkDevice* device, PlatformSurface context, + int x, int y, const PlatformRect* src_rect) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + platform_device->DrawToNativeContext(context, x, y, src_rect); +} + +void MakeOpaque(SkDevice* device, int x, int y, int width, int height) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + platform_device->MakeOpaque(x, y, width, height); +} + +} // namespace skia + |