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

Side by Side Diff: android_webview/browser/hardware_renderer_legacy.cc

Issue 287993004: [Android WebView] Implement Ubercomp for Render Thread support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix clang compile Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/hardware_renderer.h" 5 #include "android_webview/browser/hardware_renderer_legacy.h"
6 6
7 #include "android_webview/browser/aw_gl_surface.h" 7 #include "android_webview/browser/aw_gl_surface.h"
8 #include "android_webview/browser/browser_view_renderer_client.h" 8 #include "android_webview/browser/shared_renderer_state.h"
9 #include "android_webview/public/browser/draw_gl.h" 9 #include "android_webview/public/browser/draw_gl.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "cc/output/compositor_frame.h"
12 #include "content/public/browser/android/synchronous_compositor.h" 13 #include "content/public/browser/android/synchronous_compositor.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "gpu/command_buffer/service/shader_translator_cache.h"
15 #include "ui/gfx/geometry/rect_conversions.h" 15 #include "ui/gfx/geometry/rect_conversions.h"
16 #include "ui/gfx/geometry/rect_f.h" 16 #include "ui/gfx/geometry/rect_f.h"
17 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
18 #include "ui/gl/gl_bindings.h" 18 #include "ui/gl/gl_bindings.h"
19 19
20 namespace android_webview { 20 namespace android_webview {
21 21
22 HardwareRenderer::HardwareRenderer(SharedRendererState* state) 22 HardwareRendererLegacy::HardwareRendererLegacy(SharedRendererState* state)
23 : shared_renderer_state_(state), 23 : shared_renderer_state_(state), last_egl_context_(eglGetCurrentContext()) {
24 last_egl_context_(eglGetCurrentContext()) {
25 DCHECK(last_egl_context_); 24 DCHECK(last_egl_context_);
26 25
27 gl_surface_ = new AwGLSurface; 26 gl_surface_ = new AwGLSurface;
28 bool success = 27 bool success =
29 shared_renderer_state_->GetCompositor()-> 28 shared_renderer_state_->GetCompositor()->InitializeHwDraw(gl_surface_);
30 InitializeHwDraw(gl_surface_);
31 DCHECK(success); 29 DCHECK(success);
32 } 30 }
33 31
34 HardwareRenderer::~HardwareRenderer() { 32 HardwareRendererLegacy::~HardwareRendererLegacy() {
33 draw_gl_input_ = shared_renderer_state_->PassDrawGLInput();
35 shared_renderer_state_->GetCompositor()->ReleaseHwDraw(); 34 shared_renderer_state_->GetCompositor()->ReleaseHwDraw();
36 gl_surface_ = NULL; 35 gl_surface_ = NULL;
37 } 36 }
38 37
39 bool HardwareRenderer::DrawGL(bool stencil_enabled, 38 bool HardwareRendererLegacy::DrawGL(bool stencil_enabled,
40 int framebuffer_binding_ext, 39 int framebuffer_binding_ext,
41 AwDrawGLInfo* draw_info, 40 AwDrawGLInfo* draw_info,
42 DrawGLResult* result) { 41 DrawGLResult* result) {
43 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); 42 TRACE_EVENT0("android_webview", "HardwareRendererLegacy::DrawGL");
44 43
45 // We need to watch if the current Android context has changed and enforce 44 // We need to watch if the current Android context has changed and enforce
46 // a clean-up in the compositor. 45 // a clean-up in the compositor.
47 EGLContext current_context = eglGetCurrentContext(); 46 EGLContext current_context = eglGetCurrentContext();
48 if (!current_context) { 47 if (!current_context) {
49 DLOG(ERROR) << "DrawGL called without EGLContext"; 48 DLOG(ERROR) << "DrawGL called without EGLContext";
50 return false; 49 return false;
51 } 50 }
52 51
53 // TODO(boliu): Handle context loss. 52 // TODO(boliu): Handle context loss.
54 if (last_egl_context_ != current_context) 53 if (last_egl_context_ != current_context)
55 DLOG(WARNING) << "EGLContextChanged"; 54 DLOG(WARNING) << "EGLContextChanged";
56 55
57 if (draw_info->mode != AwDrawGLInfo::kModeDraw)
58 return false;
59
60 // Should only need to access SharedRendererState in kModeDraw and kModeSync. 56 // Should only need to access SharedRendererState in kModeDraw and kModeSync.
61 const DrawGLInput input = shared_renderer_state_->GetDrawGLInput(); 57 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput();
58 if (input.get())
59 draw_gl_input_ = input.Pass();
62 SetCompositorMemoryPolicy(); 60 SetCompositorMemoryPolicy();
63 61
64 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); 62 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext);
65 63
66 gfx::Transform transform; 64 gfx::Transform transform;
67 transform.matrix().setColMajorf(draw_info->transform); 65 transform.matrix().setColMajorf(draw_info->transform);
68 transform.Translate(input.scroll_offset.x(), input.scroll_offset.y()); 66 transform.Translate(draw_gl_input_->scroll_offset.x(),
67 draw_gl_input_->scroll_offset.y());
69 gfx::Rect clip_rect(draw_info->clip_left, 68 gfx::Rect clip_rect(draw_info->clip_left,
70 draw_info->clip_top, 69 draw_info->clip_top,
71 draw_info->clip_right - draw_info->clip_left, 70 draw_info->clip_right - draw_info->clip_left,
72 draw_info->clip_bottom - draw_info->clip_top); 71 draw_info->clip_bottom - draw_info->clip_top);
73 72
74 gfx::Rect viewport(draw_info->width, draw_info->height); 73 gfx::Rect viewport(draw_info->width, draw_info->height);
75 if (!draw_info->is_layer) { 74 if (!draw_info->is_layer) {
76 gfx::RectF view_rect(input.width, input.height); 75 gfx::RectF view_rect(draw_gl_input_->width, draw_gl_input_->height);
77 transform.TransformRect(&view_rect); 76 transform.TransformRect(&view_rect);
78 viewport.Intersect(gfx::ToEnclosingRect(view_rect)); 77 viewport.Intersect(gfx::ToEnclosingRect(view_rect));
79 } 78 }
80 79
81 bool did_draw = shared_renderer_state_->GetCompositor()->DemandDrawHw( 80 scoped_ptr<cc::CompositorFrame> frame =
82 gfx::Size(draw_info->width, draw_info->height), 81 shared_renderer_state_->GetCompositor()->DemandDrawHw(
83 transform, 82 gfx::Size(draw_info->width, draw_info->height),
84 viewport, 83 transform,
85 clip_rect, 84 viewport,
86 stencil_enabled); 85 clip_rect,
86 framebuffer_binding_ext);
87 gl_surface_->ResetBackingFrameBufferObject(); 87 gl_surface_->ResetBackingFrameBufferObject();
88 88
89 if (did_draw) { 89 if (frame.get()) {
90 result->frame_id = input.frame_id;
91 result->clip_contains_visible_rect = 90 result->clip_contains_visible_rect =
92 clip_rect.Contains(input.global_visible_rect); 91 clip_rect.Contains(draw_gl_input_->global_visible_rect);
93 } 92 }
94 return did_draw; 93 return !!frame.get();
95 } 94 }
96 95
97 void HardwareRenderer::SetCompositorMemoryPolicy() { 96 void HardwareRendererLegacy::SetCompositorMemoryPolicy() {
98 if (shared_renderer_state_->IsMemoryPolicyDirty()) { 97 if (shared_renderer_state_->IsMemoryPolicyDirty()) {
99 content::SynchronousCompositorMemoryPolicy policy = 98 content::SynchronousCompositorMemoryPolicy policy =
100 shared_renderer_state_->GetMemoryPolicy(); 99 shared_renderer_state_->GetMemoryPolicy();
101 // Memory policy is set by BrowserViewRenderer on UI thread. 100 // Memory policy is set by BrowserViewRenderer on UI thread.
102 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(policy); 101 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(policy);
103 shared_renderer_state_->SetMemoryPolicyDirty(false); 102 shared_renderer_state_->SetMemoryPolicyDirty(false);
104 } 103 }
105 } 104 }
106 105
107 } // namespace android_webview 106 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/hardware_renderer_legacy.h ('k') | android_webview/browser/parent_output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698