Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: ui/accelerated_widget_mac/io_surface_texture.h

Issue 1420533005: Mac: Kill lots of AcceleratedWidget code (with fire) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback 2 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_
6 #define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_
7
8 #include <deque>
9 #include <list>
10 #include <vector>
11
12 #import <Cocoa/Cocoa.h>
13 #include <IOSurface/IOSurface.h>
14 #include <QuartzCore/QuartzCore.h>
15
16 #include "base/callback.h"
17 #include "base/lazy_instance.h"
18 #include "base/mac/scoped_cftyperef.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/time/time.h"
22 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/native_widget_types.h"
24
25 class SkBitmap;
26
27 namespace gfx {
28 class Rect;
29 }
30
31 namespace ui {
32
33 class IOSurfaceContext;
34 class RenderWidgetHostViewFrameSubscriber;
35 class RenderWidgetHostViewMac;
36
37 // This class manages an OpenGL context and IOSurfaceTexture for the accelerated
38 // compositing code path. The GL context is attached to
39 // RenderWidgetHostViewCocoa for blitting the IOSurfaceTexture.
40 class IOSurfaceTexture
41 : public base::RefCounted<IOSurfaceTexture> {
42 public:
43 static scoped_refptr<IOSurfaceTexture> Create(
44 bool needs_gl_finish_workaround,
45 bool use_ns_apis);
46
47 // Returns true if there is no need to call SetIOSurface with the provided
48 // values.
49 bool IsUpToDate(
50 IOSurfaceID io_surface_id, const gfx::Size& pixel_size) const;
51
52 // Set IOSurfaceTexture that will be drawn on the next NSView drawRect.
53 bool SetIOSurface(
54 IOSurfaceID io_surface_id,
55 const gfx::Size& pixel_size) WARN_UNUSED_RESULT;
56
57 // Blit the IOSurface to the rectangle specified by |window_rect| in DIPs,
58 // with the origin in the lower left corner. If the window rect's size is
59 // larger than the IOSurface, the remaining right and bottom edges will be
60 // white. |window_scale_factor| is 1 in normal views, 2 in HiDPI views.
61 bool DrawIOSurface() WARN_UNUSED_RESULT;
62 bool DrawIOSurfaceWithDamageRect(gfx::Rect damage_rect) WARN_UNUSED_RESULT;
63
64 // Returns true if the offscreen context used by this surface has been
65 // poisoned.
66 bool HasBeenPoisoned() const;
67
68 private:
69 friend class base::RefCounted<IOSurfaceTexture>;
70
71 IOSurfaceTexture(
72 const scoped_refptr<IOSurfaceContext>& context,
73 bool use_ns_apis,
74 bool needs_gl_finish_workaround);
75 ~IOSurfaceTexture();
76
77 // Unref the IOSurfaceTexture and delete the associated GL texture. If the GPU
78 // process is no longer referencing it, this will delete the IOSurface.
79 void ReleaseIOSurfaceAndTexture();
80
81 // Check for GL errors and store the result in error_. Only return new
82 // errors
83 GLenum GetAndSaveGLError();
84
85 // Offscreen context used for all operations other than drawing to the
86 // screen. This is in the same share group as the contexts used for
87 // drawing, and is the same for all IOSurfaces in all windows.
88 scoped_refptr<IOSurfaceContext> offscreen_context_;
89
90 // The IOSurface and its non-rounded size.
91 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
92 gfx::Size pixel_size_;
93
94 // The "live" OpenGL texture referring to this IOSurfaceRef. Note
95 // that per the CGLTexImageIOSurface2D API we do not need to
96 // explicitly update this texture's contents once created. All we
97 // need to do is ensure it is re-bound before attempting to draw
98 // with it.
99 GLuint texture_;
100
101 // Error saved by GetAndSaveGLError
102 GLint gl_error_;
103
104 // Aggressive IOSurface eviction logic. When using CoreAnimation, IOSurfaces
105 // are used only transiently to transfer from the GPU process to the browser
106 // process. Once the IOSurface has been drawn to its CALayer, the CALayer
107 // will not need updating again until its view is hidden and re-shown.
108 // Aggressively evict surfaces when more than 8 (the number allowed by the
109 // memory manager for fast tab switching) are allocated.
110 enum {
111 kMaximumUnevictedSurfaces = 8,
112 };
113 typedef std::list<IOSurfaceTexture*> EvictionQueue;
114 void EvictionMarkUpdated();
115 void EvictionMarkEvicted();
116 EvictionQueue::iterator eviction_queue_iterator_;
117 bool eviction_has_been_drawn_since_updated_;
118
119 const bool needs_gl_finish_workaround_;
120
121 // Set if this is for access through NS APIs.
122 const bool using_ns_apis_;
123
124 static void EvictionScheduleDoEvict();
125 static void EvictionDoEvict();
126 static base::LazyInstance<EvictionQueue> eviction_queue_;
127 static bool eviction_scheduled_;
128 };
129
130 } // namespace ui
131
132 #endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_
OLDNEW
« no previous file with comments | « ui/accelerated_widget_mac/io_surface_layer.mm ('k') | ui/accelerated_widget_mac/io_surface_texture.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698