OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/browser/in_process_view_renderer.h" | 5 #include "android_webview/browser/in_process_view_renderer.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "android_webview/browser/aw_gl_surface.h" | 9 #include "android_webview/browser/aw_gl_surface.h" |
10 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 using base::android::AttachCurrentThread; | 37 using base::android::AttachCurrentThread; |
38 using base::android::JavaRef; | 38 using base::android::JavaRef; |
39 using base::android::ScopedJavaLocalRef; | 39 using base::android::ScopedJavaLocalRef; |
40 using content::BrowserThread; | 40 using content::BrowserThread; |
41 | 41 |
42 namespace android_webview { | 42 namespace android_webview { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 | |
47 const void* kUserDataKey = &kUserDataKey; | 46 const void* kUserDataKey = &kUserDataKey; |
48 | 47 |
49 class UserData : public content::WebContents::Data { | 48 class UserData : public content::WebContents::Data { |
50 public: | 49 public: |
51 UserData(InProcessViewRenderer* ptr) : instance_(ptr) {} | 50 UserData(InProcessViewRenderer* ptr) : instance_(ptr) {} |
52 virtual ~UserData() { | 51 virtual ~UserData() { |
53 instance_->WebContentsGone(); | 52 instance_->WebContentsGone(); |
54 } | 53 } |
55 | 54 |
56 static InProcessViewRenderer* GetInstance(content::WebContents* contents) { | 55 static InProcessViewRenderer* GetInstance(content::WebContents* contents) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 switches::kDisableWebViewGLMode); | 131 switches::kDisableWebViewGLMode); |
133 return g_hw_enabled; | 132 return g_hw_enabled; |
134 } | 133 } |
135 | 134 |
136 // Provides software rendering functions from the Android glue layer. | 135 // Provides software rendering functions from the Android glue layer. |
137 // Allows preventing extra copies of data when rendering. | 136 // Allows preventing extra copies of data when rendering. |
138 AwDrawSWFunctionTable* g_sw_draw_functions = NULL; | 137 AwDrawSWFunctionTable* g_sw_draw_functions = NULL; |
139 | 138 |
140 const int64 kFallbackTickTimeoutInMilliseconds = 20; | 139 const int64 kFallbackTickTimeoutInMilliseconds = 20; |
141 | 140 |
142 | |
143 // Used to calculate memory and resource allocation. Determined experimentally. | 141 // Used to calculate memory and resource allocation. Determined experimentally. |
144 size_t g_memory_multiplier = 10; | 142 size_t g_memory_multiplier = 10; |
145 size_t g_num_gralloc_limit = 150; | 143 size_t g_num_gralloc_limit = 150; |
146 const size_t kBytesPerPixel = 4; | 144 const size_t kBytesPerPixel = 4; |
147 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; | 145 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; |
148 | 146 |
| 147 base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager = |
| 148 LAZY_INSTANCE_INITIALIZER; |
| 149 |
149 class ScopedAllowGL { | 150 class ScopedAllowGL { |
150 public: | 151 public: |
151 ScopedAllowGL(); | 152 ScopedAllowGL(); |
152 ~ScopedAllowGL(); | 153 ~ScopedAllowGL(); |
153 | 154 |
154 static bool IsAllowed() { | 155 static bool IsAllowed() { |
155 return BrowserThread::CurrentlyOn(BrowserThread::UI) && allow_gl; | 156 return g_view_renderer_manager.Get().OnRenderThread() && allow_gl; |
156 } | 157 } |
157 | 158 |
158 private: | 159 private: |
159 static bool allow_gl; | 160 static bool allow_gl; |
160 | 161 |
161 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); | 162 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); |
162 }; | 163 }; |
163 | 164 |
164 ScopedAllowGL::ScopedAllowGL() { | 165 ScopedAllowGL::ScopedAllowGL() { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 166 DCHECK(g_view_renderer_manager.Get().OnRenderThread()); |
166 DCHECK(!allow_gl); | 167 DCHECK(!allow_gl); |
167 allow_gl = true; | 168 allow_gl = true; |
168 } | 169 } |
169 | 170 |
170 ScopedAllowGL::~ScopedAllowGL() { | 171 ScopedAllowGL::~ScopedAllowGL() { |
171 allow_gl = false; | 172 allow_gl = false; |
172 } | 173 } |
173 | 174 |
174 bool ScopedAllowGL::allow_gl = false; | 175 bool ScopedAllowGL::allow_gl = false; |
175 | 176 |
176 base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager = | |
177 LAZY_INSTANCE_INITIALIZER; | |
178 | |
179 void RequestProcessGLOnUIThread() { | 177 void RequestProcessGLOnUIThread() { |
180 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 178 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
181 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
182 BrowserThread::UI, FROM_HERE, base::Bind(&RequestProcessGLOnUIThread)); | 180 BrowserThread::UI, FROM_HERE, base::Bind(&RequestProcessGLOnUIThread)); |
183 return; | 181 return; |
184 } | 182 } |
185 | 183 |
186 InProcessViewRenderer* renderer = static_cast<InProcessViewRenderer*>( | 184 InProcessViewRenderer* renderer = static_cast<InProcessViewRenderer*>( |
187 g_view_renderer_manager.Get().GetMostRecentlyDrawn()); | 185 g_view_renderer_manager.Get().GetMostRecentlyDrawn()); |
188 if (!renderer || !renderer->RequestProcessGL()) { | 186 if (!renderer || !renderer->RequestProcessGL()) { |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 base::StringAppendF(&str, | 1096 base::StringAppendF(&str, |
1099 "surface width height: [%d %d] ", | 1097 "surface width height: [%d %d] ", |
1100 draw_info->width, | 1098 draw_info->width, |
1101 draw_info->height); | 1099 draw_info->height); |
1102 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 1100 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
1103 } | 1101 } |
1104 return str; | 1102 return str; |
1105 } | 1103 } |
1106 | 1104 |
1107 } // namespace android_webview | 1105 } // namespace android_webview |
OLD | NEW |