summaryrefslogtreecommitdiffstats
path: root/skia/ext/platform_device.cc
blob: 6292273a8b51169f67d7290e1a356cc0ca8238d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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 "base/logging.h"
#include "skia/ext/platform_device.h"

#include "third_party/skia/include/core/SkMetaData.h"

namespace skia {

namespace {

const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour";
const char* kDraftModeKey = "CrDraftMode";

#if defined(OS_MACOSX) || defined(OS_WIN)
const char* kIsPreviewMetafileKey = "CrIsPreviewMetafile";
#endif

void SetBoolMetaData(const SkCanvas& canvas, const char* key,  bool value) {
  SkMetaData& meta = skia::getMetaData(canvas);
  meta.setBool(key, value);
}

bool GetBoolMetaData(const SkCanvas& canvas, const char* key) {
  bool value;
  SkMetaData& meta = skia::getMetaData(canvas);
  if (!meta.findBool(key, &value))
    value = false;
  return value;
}

}  // namespace

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;
}

SkMetaData& getMetaData(const SkCanvas& canvas) {
  SkDevice* device = canvas.getDevice();
  DCHECK(device != NULL);
  return device->getMetaData();
}

void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode) {
  SetBoolMetaData(canvas, kDraftModeKey, draft_mode);
}

bool IsDraftMode(const SkCanvas& canvas) {
  return GetBoolMetaData(canvas, kDraftModeKey);
}

#if defined(OS_MACOSX) || defined(OS_WIN)
void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) {
  SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview);
}

bool IsPreviewMetafile(const SkCanvas& canvas) {
  return GetBoolMetaData(canvas, kIsPreviewMetafileKey);
}
#endif

bool PlatformDevice::IsNativeFontRenderingAllowed() {
  return true;
}

bool PlatformDevice::AlphaBlendUsed() const {
  return false;
}

}  // namespace skia