| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | |
| 6 #define UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "ui/gfx/compositor/compositor.h" | |
| 14 #include "ui/gfx/gl/scoped_make_current.h" | |
| 15 #include "ui/gfx/size.h" | |
| 16 | |
| 17 namespace gfx { | |
| 18 class GLContext; | |
| 19 class GLSurface; | |
| 20 class Rect; | |
| 21 } | |
| 22 | |
| 23 namespace ui { | |
| 24 | |
| 25 class CompositorGL; | |
| 26 class TextureProgramGL; | |
| 27 | |
| 28 // We share resources (such as shaders) between different Compositors via | |
| 29 // GLContext sharing so that we only have to create/destroy them once. | |
| 30 class COMPOSITOR_EXPORT SharedResourcesGL : public SharedResources { | |
| 31 public: | |
| 32 static SharedResourcesGL* GetInstance(); | |
| 33 | |
| 34 virtual gfx::ScopedMakeCurrent* GetScopedMakeCurrent() OVERRIDE; | |
| 35 | |
| 36 // Creates a context that shares the resources hosted by this singleton. | |
| 37 scoped_refptr<gfx::GLContext> CreateContext(gfx::GLSurface* surface); | |
| 38 | |
| 39 virtual void* GetDisplay() OVERRIDE; | |
| 40 | |
| 41 ui::TextureProgramGL* program_no_swizzle() { | |
| 42 return program_no_swizzle_.get(); | |
| 43 } | |
| 44 | |
| 45 ui::TextureProgramGL* program_swizzle() { | |
| 46 return program_swizzle_.get(); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 friend struct DefaultSingletonTraits<SharedResourcesGL>; | |
| 51 | |
| 52 SharedResourcesGL(); | |
| 53 virtual ~SharedResourcesGL(); | |
| 54 | |
| 55 bool Initialize(); | |
| 56 void Destroy(); | |
| 57 | |
| 58 bool initialized_; | |
| 59 | |
| 60 scoped_refptr<gfx::GLContext> context_; | |
| 61 scoped_refptr<gfx::GLSurface> surface_; | |
| 62 | |
| 63 scoped_ptr<ui::TextureProgramGL> program_swizzle_; | |
| 64 scoped_ptr<ui::TextureProgramGL> program_no_swizzle_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(SharedResourcesGL); | |
| 67 }; | |
| 68 | |
| 69 class COMPOSITOR_EXPORT TextureGL : public Texture { | |
| 70 public: | |
| 71 TextureGL(); | |
| 72 | |
| 73 virtual void SetCanvas(const SkCanvas& canvas, | |
| 74 const gfx::Point& origin, | |
| 75 const gfx::Size& overall_size) OVERRIDE; | |
| 76 | |
| 77 virtual void Draw(const ui::TextureDrawParams& params, | |
| 78 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; | |
| 79 | |
| 80 const gfx::Size& size() const { return size_; } | |
| 81 | |
| 82 protected: | |
| 83 explicit TextureGL(const gfx::Size& size); | |
| 84 virtual ~TextureGL(); | |
| 85 | |
| 86 // Actually draws the texture. | |
| 87 // Only the region defined by draw_bounds will be drawn. | |
| 88 void DrawInternal(const TextureProgramGL& program, | |
| 89 const ui::TextureDrawParams& params, | |
| 90 const gfx::Rect& clip_bounds_in_texture); | |
| 91 | |
| 92 unsigned int texture_id_; | |
| 93 gfx::Size size_; | |
| 94 | |
| 95 private: | |
| 96 DISALLOW_COPY_AND_ASSIGN(TextureGL); | |
| 97 }; | |
| 98 | |
| 99 class COMPOSITOR_EXPORT CompositorGL : public Compositor { | |
| 100 public: | |
| 101 CompositorGL(CompositorDelegate* delegate, | |
| 102 gfx::AcceleratedWidget widget, | |
| 103 const gfx::Size& size); | |
| 104 virtual ~CompositorGL(); | |
| 105 | |
| 106 // Overridden from Compositor. | |
| 107 virtual bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) OVERRIDE; | |
| 108 | |
| 109 void MakeCurrent(); | |
| 110 gfx::Size GetSize(); | |
| 111 | |
| 112 protected: | |
| 113 virtual void OnWidgetSizeChanged() OVERRIDE; | |
| 114 | |
| 115 private: | |
| 116 // Overridden from Compositor. | |
| 117 virtual Texture* CreateTexture() OVERRIDE; | |
| 118 virtual void OnNotifyStart(bool clear) OVERRIDE; | |
| 119 virtual void OnNotifyEnd() OVERRIDE; | |
| 120 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; | |
| 121 | |
| 122 // The GL context used for compositing. | |
| 123 scoped_refptr<gfx::GLSurface> gl_surface_; | |
| 124 scoped_refptr<gfx::GLContext> gl_context_; | |
| 125 | |
| 126 // Keep track of whether compositing has started or not. | |
| 127 bool started_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | |
| 130 }; | |
| 131 | |
| 132 } // namespace ui | |
| 133 | |
| 134 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | |
| OLD | NEW |