summaryrefslogtreecommitdiffstats
path: root/ui/gfx/compositor/compositor_cc.h
blob: 1bd4b5826fc650b1bd6e0a737244c972e822c07c (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
108
109
110
111
112
113
114
115
116
117
118
119
// 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.

#ifndef UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_
#define UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_
#pragma once

#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/size.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerTreeView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerTreeViewClient.h"

namespace gfx {
class Rect;
class GLContext;
class GLSurface;
class GLShareGroup;
}

namespace ui {

class COMPOSITOR_EXPORT SharedResourcesCC : public SharedResources {
 public:
  static SharedResourcesCC* GetInstance();

  virtual bool MakeSharedContextCurrent();
  virtual void* GetDisplay();

  gfx::GLShareGroup* GetShareGroup();

 private:
  friend struct DefaultSingletonTraits<SharedResourcesCC>;

  SharedResourcesCC();
  virtual ~SharedResourcesCC();

  bool Initialize();
  void Destroy();

  bool initialized_;

  scoped_refptr<gfx::GLContext> context_;
  scoped_refptr<gfx::GLSurface> surface_;

  DISALLOW_COPY_AND_ASSIGN(SharedResourcesCC);
};

class COMPOSITOR_EXPORT TextureCC : public Texture {
 public:
  TextureCC();

  // Texture implementation.
  virtual void SetCanvas(const SkCanvas& canvas,
                         const gfx::Point& origin,
                         const gfx::Size& overall_size) OVERRIDE;

  virtual void Draw(const ui::TextureDrawParams& params,
                    const gfx::Rect& clip_bounds_in_texture) OVERRIDE;

  virtual void Update() = 0;
  unsigned int texture_id() const { return texture_id_; }
  bool flipped() const { return flipped_; }

 protected:
  unsigned int texture_id_;
  bool flipped_;
  DISALLOW_COPY_AND_ASSIGN(TextureCC);
};

class COMPOSITOR_EXPORT CompositorCC : public Compositor,
                                       public WebKit::WebLayerTreeViewClient,
                                       public WebKit::WebLayerClient {
 public:
  CompositorCC(CompositorDelegate* delegate,
               gfx::AcceleratedWidget widget,
               const gfx::Size& size);
  virtual ~CompositorCC();

  static void InitializeThread();
  static void TerminateThread();

 protected:
  // Compositor implementation.
  virtual Texture* CreateTexture() OVERRIDE;
  virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
  virtual void ScheduleDraw() OVERRIDE;
  virtual void OnNotifyStart(bool clear) OVERRIDE;
  virtual void OnNotifyEnd() OVERRIDE;
  virtual void OnWidgetSizeChanged() OVERRIDE;
  virtual void OnRootLayerChanged() OVERRIDE;
  virtual void DrawTree() OVERRIDE;

  // WebLayerTreeViewClient implementation.
  virtual void animateAndLayout(double frameBeginTime) OVERRIDE;
  virtual void applyScrollDelta(const WebKit::WebSize&) OVERRIDE;
  virtual WebKit::WebGraphicsContext3D* createContext3D() OVERRIDE;
  virtual void didRebindGraphicsContext(bool success) OVERRIDE;
  virtual void scheduleComposite() OVERRIDE;

  // WebLayerClient implementation.
  virtual void notifyNeedsComposite() OVERRIDE;

 private:
  gfx::AcceleratedWidget widget_;
  WebKit::WebLayer root_web_layer_;
  WebKit::WebLayerTreeView host_;

  DISALLOW_COPY_AND_ASSIGN(CompositorCC);
};

}  // namespace ui

#endif  // UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_