summaryrefslogtreecommitdiffstats
path: root/ui/gfx/ozone/surface_factory_ozone.cc
blob: 5ba8de0c537be90ed7e64f14adc89cded6d0de40 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2013 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 "ui/gfx/ozone/surface_factory_ozone.h"

#include <stdlib.h>

#include "base/command_line.h"
#include "ui/gfx/ozone/impl/file_surface_factory_ozone.h"
#include "ui/gfx/ozone/impl/software_surface_factory_ozone.h"

namespace gfx {

// static
SurfaceFactoryOzone* SurfaceFactoryOzone::impl_ = NULL;

class SurfaceFactoryOzoneStub : public SurfaceFactoryOzone {
 public:
  SurfaceFactoryOzoneStub() {}
  virtual ~SurfaceFactoryOzoneStub() {}

  virtual HardwareState InitializeHardware() OVERRIDE { return INITIALIZED; }
  virtual void ShutdownHardware() OVERRIDE {}
  virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE { return 0; }
  virtual gfx::AcceleratedWidget RealizeAcceleratedWidget(
      gfx::AcceleratedWidget w) OVERRIDE {
    return 0;
  }
  virtual bool LoadEGLGLES2Bindings(
      AddGLLibraryCallback add_gl_library,
      SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE {
    return true;
  }
  virtual bool AttemptToResizeAcceleratedWidget(
      gfx::AcceleratedWidget w,
      const gfx::Rect& bounds) OVERRIDE {
    return false;
  }
  virtual gfx::VSyncProvider* GetVSyncProvider(
      gfx::AcceleratedWidget w) OVERRIDE {
    return NULL;
  }
};

SurfaceFactoryOzone::SurfaceFactoryOzone() {
}

SurfaceFactoryOzone::~SurfaceFactoryOzone() {
}

SurfaceFactoryOzone* SurfaceFactoryOzone::GetInstance() {
  if (!impl_) {
    const char kOzoneFileSurface[] = "ozone-dump-file";
    CommandLine* cmd = CommandLine::ForCurrentProcess();
    if (cmd->HasSwitch(kOzoneFileSurface)) {
      base::FilePath location = cmd->GetSwitchValuePath(kOzoneFileSurface);
      if (location.empty())
        location = base::FilePath("/dev/null");
      impl_ = new FileSurfaceFactoryOzone(location);
    } else {
      LOG(WARNING) << "No SurfaceFactoryOzone implementation set. Using default"
                      " gfx::SoftwareSurfaceFactoryOzone.";
      impl_ = new SoftwareSurfaceFactoryOzone();
    }
  }
  return impl_;
}

void SurfaceFactoryOzone::SetInstance(SurfaceFactoryOzone* impl) {
  impl_ = impl;
}

const char* SurfaceFactoryOzone::DefaultDisplaySpec() {
  char* envvar = getenv("ASH_DISPLAY_SPEC");
  if (envvar)
    return envvar;
  return  "720x1280*2";
}

gfx::Screen* SurfaceFactoryOzone::CreateDesktopScreen() {
  return NULL;
}

intptr_t SurfaceFactoryOzone::GetNativeDisplay() {
  return 0;
}

bool SurfaceFactoryOzone::SchedulePageFlip(gfx::AcceleratedWidget w) {
  return true;
}

SkCanvas* SurfaceFactoryOzone::GetCanvasForWidget(gfx::AcceleratedWidget w) {
  return NULL;
}

const int32* SurfaceFactoryOzone::GetEGLSurfaceProperties(
    const int32* desired_attributes) {
  return desired_attributes;
}

// static
SurfaceFactoryOzone* SurfaceFactoryOzone::CreateTestHelper() {
  return new SurfaceFactoryOzoneStub;
}

}  // namespace gfx