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

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

Issue 266353003: aw: Ubercomp mega patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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),
24 last_egl_context_(eglGetCurrentContext()) { 24 last_egl_context_(eglGetCurrentContext()) {
25 DCHECK(last_egl_context_); 25 DCHECK(last_egl_context_);
26 26
27 gl_surface_ = new AwGLSurface; 27 gl_surface_ = new AwGLSurface;
28 bool success = 28 bool success =
29 shared_renderer_state_->GetCompositor()-> 29 shared_renderer_state_->GetCompositor()->
30 InitializeHwDraw(gl_surface_); 30 InitializeHwDraw(gl_surface_);
31 DCHECK(success); 31 DCHECK(success);
32 } 32 }
33 33
34 HardwareRenderer::~HardwareRenderer() { 34 HardwareRendererLegacy::~HardwareRendererLegacy() {
35 draw_gl_input_ = shared_renderer_state_->PassDrawGLInput();
35 shared_renderer_state_->GetCompositor()->ReleaseHwDraw(); 36 shared_renderer_state_->GetCompositor()->ReleaseHwDraw();
36 gl_surface_ = NULL; 37 gl_surface_ = NULL;
37 } 38 }
38 39
39 bool HardwareRenderer::DrawGL(bool stencil_enabled, 40 bool HardwareRendererLegacy::DrawGL(bool stencil_enabled,
40 int framebuffer_binding_ext, 41 int framebuffer_binding_ext,
41 AwDrawGLInfo* draw_info, 42 AwDrawGLInfo* draw_info,
42 DrawGLResult* result) { 43 DrawGLResult* result) {
43 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); 44 TRACE_EVENT0("android_webview", "HardwareRendererLegacy::DrawGL");
44 45
45 // We need to watch if the current Android context has changed and enforce 46 // We need to watch if the current Android context has changed and enforce
46 // a clean-up in the compositor. 47 // a clean-up in the compositor.
47 EGLContext current_context = eglGetCurrentContext(); 48 EGLContext current_context = eglGetCurrentContext();
48 if (!current_context) { 49 if (!current_context) {
49 DLOG(ERROR) << "DrawGL called without EGLContext"; 50 DLOG(ERROR) << "DrawGL called without EGLContext";
50 return false; 51 return false;
51 } 52 }
52 53
53 // TODO(boliu): Handle context loss. 54 // TODO(boliu): Handle context loss.
54 if (last_egl_context_ != current_context) 55 if (last_egl_context_ != current_context)
55 DLOG(WARNING) << "EGLContextChanged"; 56 DLOG(WARNING) << "EGLContextChanged";
56 57
57 if (draw_info->mode != AwDrawGLInfo::kModeDraw) 58 if (draw_info->mode != AwDrawGLInfo::kModeDraw)
58 return false; 59 return false;
59 60
60 // Should only need to access SharedRendererState in kModeDraw and kModeSync. 61 // Should only need to access SharedRendererState in kModeDraw and kModeSync.
61 const DrawGLInput input = shared_renderer_state_->GetDrawGLInput(); 62 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput();
63 if (input.get())
64 draw_gl_input_ = input.Pass();
62 SetCompositorMemoryPolicy(); 65 SetCompositorMemoryPolicy();
63 66
64 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); 67 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext);
65 68
66 gfx::Transform transform; 69 gfx::Transform transform;
67 transform.matrix().setColMajorf(draw_info->transform); 70 transform.matrix().setColMajorf(draw_info->transform);
68 transform.Translate(input.scroll_offset.x(), input.scroll_offset.y()); 71 transform.Translate(draw_gl_input_->scroll_offset.x(),
72 draw_gl_input_->scroll_offset.y());
69 gfx::Rect clip_rect(draw_info->clip_left, 73 gfx::Rect clip_rect(draw_info->clip_left,
70 draw_info->clip_top, 74 draw_info->clip_top,
71 draw_info->clip_right - draw_info->clip_left, 75 draw_info->clip_right - draw_info->clip_left,
72 draw_info->clip_bottom - draw_info->clip_top); 76 draw_info->clip_bottom - draw_info->clip_top);
73 77
74 gfx::Rect viewport(draw_info->width, draw_info->height); 78 gfx::Rect viewport(draw_info->width, draw_info->height);
75 if (!draw_info->is_layer) { 79 if (!draw_info->is_layer) {
76 gfx::RectF view_rect(input.width, input.height); 80 gfx::RectF view_rect(draw_gl_input_->width, draw_gl_input_->height);
77 transform.TransformRect(&view_rect); 81 transform.TransformRect(&view_rect);
78 viewport.Intersect(gfx::ToEnclosingRect(view_rect)); 82 viewport.Intersect(gfx::ToEnclosingRect(view_rect));
79 } 83 }
80 84
81 bool did_draw = shared_renderer_state_->GetCompositor()->DemandDrawHw( 85 cc::CompositorFrame frame;
82 gfx::Size(draw_info->width, draw_info->height), 86 bool did_draw = shared_renderer_state_->GetCompositor()->
83 transform, 87 DemandDrawHw(
84 viewport, 88 gfx::Size(draw_info->width, draw_info->height),
85 clip_rect, 89 transform,
86 stencil_enabled); 90 viewport,
91 clip_rect,
92 framebuffer_binding_ext,
93 &frame);
87 gl_surface_->ResetBackingFrameBufferObject(); 94 gl_surface_->ResetBackingFrameBufferObject();
88 95
89 if (did_draw) { 96 if (did_draw) {
90 result->frame_id = input.frame_id; 97 result->frame_id = draw_gl_input_->frame_id;
91 result->clip_contains_visible_rect = 98 result->clip_contains_visible_rect =
92 clip_rect.Contains(input.global_visible_rect); 99 clip_rect.Contains(draw_gl_input_->global_visible_rect);
93 } 100 }
94 return did_draw; 101 return did_draw;
95 } 102 }
96 103
97 void HardwareRenderer::SetCompositorMemoryPolicy() { 104 void HardwareRendererLegacy::SetCompositorMemoryPolicy() {
98 if (shared_renderer_state_->IsMemoryPolicyDirty()) { 105 if (shared_renderer_state_->IsMemoryPolicyDirty()) {
99 content::SynchronousCompositorMemoryPolicy policy = 106 content::SynchronousCompositorMemoryPolicy policy =
100 shared_renderer_state_->GetMemoryPolicy(); 107 shared_renderer_state_->GetMemoryPolicy();
101 // Memory policy is set by BrowserViewRenderer on UI thread. 108 // Memory policy is set by BrowserViewRenderer on UI thread.
102 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(policy); 109 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(policy);
103 shared_renderer_state_->SetMemoryPolicyDirty(false); 110 shared_renderer_state_->SetMemoryPolicyDirty(false);
104 } 111 }
105 } 112 }
106 113
107 } // namespace android_webview 114 } // namespace android_webview
115
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