Commit a3434da0 authored by boliu's avatar boliu Committed by Commit bot

aw: Clean up browser_view_renderer.cc/h

* Remove unneeded includes, using, etc
* Use base::debug::ConvertableToTraceFormat
* Fix up some comments
* Make const a global var

BUG=

Review URL: https://codereview.chromium.org/649683004

Cr-Commit-Position: refs/heads/master@{#299416}
parent ac4df1c4
...@@ -7,17 +7,13 @@ ...@@ -7,17 +7,13 @@
#include "android_webview/browser/browser_view_renderer_client.h" #include "android_webview/browser/browser_view_renderer_client.h"
#include "android_webview/browser/shared_renderer_state.h" #include "android_webview/browser/shared_renderer_state.h"
#include "android_webview/common/aw_switches.h" #include "android_webview/common/aw_switches.h"
#include "android_webview/public/browser/draw_gl.h"
#include "base/android/jni_android.h"
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event_argument.h"
#include "base/json/json_writer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "gpu/command_buffer/service/gpu_switches.h" #include "gpu/command_buffer/service/gpu_switches.h"
...@@ -27,10 +23,6 @@ ...@@ -27,10 +23,6 @@
#include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkPictureRecorder.h"
#include "ui/gfx/vector2d_conversions.h" #include "ui/gfx/vector2d_conversions.h"
using base::android::AttachCurrentThread;
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
using content::BrowserThread;
using content::SynchronousCompositorMemoryPolicy; using content::SynchronousCompositorMemoryPolicy;
namespace android_webview { namespace android_webview {
...@@ -48,30 +40,9 @@ uint64 g_memory_override_in_bytes = 0u; ...@@ -48,30 +40,9 @@ uint64 g_memory_override_in_bytes = 0u;
// Used to calculate tile allocation. Determined experimentally. // Used to calculate tile allocation. Determined experimentally.
const size_t kTileMultiplier = 12; const size_t kTileMultiplier = 12;
const size_t kTileAllocationStep = 20; const size_t kTileAllocationStep = 20;
// This will be set by static function CalculateTileMemoryPolicy() during init. // Use chrome's default tile size, which varies from 256 to 512.
// See AwMainDelegate::BasicStartupComplete. // Be conservative here and use the smallest tile size possible.
size_t g_tile_area; const size_t kTileArea = 256 * 256;
class TracedValue : public base::debug::ConvertableToTraceFormat {
public:
explicit TracedValue(base::Value* value) : value_(value) {}
static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue(
base::Value* value) {
return scoped_refptr<base::debug::ConvertableToTraceFormat>(
new TracedValue(value));
}
virtual void AppendAsTraceFormat(std::string* out) const override {
std::string tmp;
base::JSONWriter::Write(value_.get(), &tmp);
*out += tmp;
}
private:
virtual ~TracedValue() {}
scoped_ptr<base::Value> value_;
DISALLOW_COPY_AND_ASSIGN(TracedValue);
};
} // namespace } // namespace
...@@ -90,10 +61,6 @@ void BrowserViewRenderer::CalculateTileMemoryPolicy() { ...@@ -90,10 +61,6 @@ void BrowserViewRenderer::CalculateTileMemoryPolicy() {
g_memory_override_in_bytes *= 1024 * 1024; g_memory_override_in_bytes *= 1024 * 1024;
} }
// Use chrome's default tile size, which varies from 256 to 512.
// Be conservative here and use the smallest tile size possible.
g_tile_area = 256 * 256;
// Also use a high tile limit since there are no file descriptor issues. // Also use a high tile limit since there are no file descriptor issues.
GlobalTileManager::GetInstance()->SetTileLimit(1000); GlobalTileManager::GetInstance()->SetTileLimit(1000);
} }
...@@ -137,7 +104,7 @@ BrowserViewRenderer::~BrowserViewRenderer() { ...@@ -137,7 +104,7 @@ BrowserViewRenderer::~BrowserViewRenderer() {
// This function updates the resource allocation in GlobalTileManager. // This function updates the resource allocation in GlobalTileManager.
void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { void BrowserViewRenderer::TrimMemory(const int level, const bool visible) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(ui_task_runner_->BelongsToCurrentThread());
// Constants from Android ComponentCallbacks2. // Constants from Android ComponentCallbacks2.
enum { enum {
TRIM_MEMORY_RUNNING_LOW = 10, TRIM_MEMORY_RUNNING_LOW = 10,
...@@ -180,7 +147,7 @@ BrowserViewRenderer::CalculateDesiredMemoryPolicy() { ...@@ -180,7 +147,7 @@ BrowserViewRenderer::CalculateDesiredMemoryPolicy() {
if (g_memory_override_in_bytes) if (g_memory_override_in_bytes)
policy.bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); policy.bytes_limit = static_cast<size_t>(g_memory_override_in_bytes);
size_t tiles = width * height * kTileMultiplier / g_tile_area; size_t tiles = width * height * kTileMultiplier / kTileArea;
// Round up to a multiple of kTileAllocationStep. The minimum number of tiles // Round up to a multiple of kTileAllocationStep. The minimum number of tiles
// is also kTileAllocationStep. // is also kTileAllocationStep.
tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep;
...@@ -619,9 +586,7 @@ void BrowserViewRenderer::UpdateRootLayerState( ...@@ -619,9 +586,7 @@ void BrowserViewRenderer::UpdateRootLayerState(
"BrowserViewRenderer::UpdateRootLayerState", "BrowserViewRenderer::UpdateRootLayerState",
TRACE_EVENT_SCOPE_THREAD, TRACE_EVENT_SCOPE_THREAD,
"state", "state",
TracedValue::FromValue( RootLayerStateAsValue(total_scroll_offset_dip, scrollable_size_dip));
RootLayerStateAsValue(total_scroll_offset_dip, scrollable_size_dip)
.release()));
DCHECK_GT(dip_scale_, 0); DCHECK_GT(dip_scale_, 0);
...@@ -640,10 +605,12 @@ void BrowserViewRenderer::UpdateRootLayerState( ...@@ -640,10 +605,12 @@ void BrowserViewRenderer::UpdateRootLayerState(
SetTotalRootLayerScrollOffset(total_scroll_offset_dip); SetTotalRootLayerScrollOffset(total_scroll_offset_dip);
} }
scoped_ptr<base::Value> BrowserViewRenderer::RootLayerStateAsValue( scoped_refptr<base::debug::ConvertableToTraceFormat>
BrowserViewRenderer::RootLayerStateAsValue(
const gfx::Vector2dF& total_scroll_offset_dip, const gfx::Vector2dF& total_scroll_offset_dip,
const gfx::SizeF& scrollable_size_dip) { const gfx::SizeF& scrollable_size_dip) {
scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); scoped_refptr<base::debug::TracedValue> state =
new base::debug::TracedValue();
state->SetDouble("total_scroll_offset_dip.x", total_scroll_offset_dip.x()); state->SetDouble("total_scroll_offset_dip.x", total_scroll_offset_dip.x());
state->SetDouble("total_scroll_offset_dip.y", total_scroll_offset_dip.y()); state->SetDouble("total_scroll_offset_dip.y", total_scroll_offset_dip.y());
...@@ -655,7 +622,7 @@ scoped_ptr<base::Value> BrowserViewRenderer::RootLayerStateAsValue( ...@@ -655,7 +622,7 @@ scoped_ptr<base::Value> BrowserViewRenderer::RootLayerStateAsValue(
state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height());
state->SetDouble("page_scale_factor", page_scale_factor_); state->SetDouble("page_scale_factor", page_scale_factor_);
return state.PassAs<base::Value>(); return state;
} }
void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
...@@ -780,7 +747,7 @@ void BrowserViewRenderer::SkippedCompositeInDraw() { ...@@ -780,7 +747,7 @@ void BrowserViewRenderer::SkippedCompositeInDraw() {
EnsureContinuousInvalidation(false, true); EnsureContinuousInvalidation(false, true);
} }
std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const { std::string BrowserViewRenderer::ToString() const {
std::string str; std::string str;
base::StringAppendF(&str, "is_paused: %d ", is_paused_); base::StringAppendF(&str, "is_paused: %d ", is_paused_);
base::StringAppendF(&str, "view_visible: %d ", view_visible_); base::StringAppendF(&str, "view_visible: %d ", view_visible_);
...@@ -804,19 +771,6 @@ std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const { ...@@ -804,19 +771,6 @@ std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
base::StringAppendF( base::StringAppendF(
&str, "on_new_picture_enable: %d ", on_new_picture_enable_); &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
base::StringAppendF(&str, "clear_view: %d ", clear_view_); base::StringAppendF(&str, "clear_view: %d ", clear_view_);
if (draw_info) {
base::StringAppendF(&str,
"clip left top right bottom: [%d %d %d %d] ",
draw_info->clip_left,
draw_info->clip_top,
draw_info->clip_right,
draw_info->clip_bottom);
base::StringAppendF(&str,
"surface width height: [%d %d] ",
draw_info->width,
draw_info->height);
base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
}
return str; return str;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/values.h" #include "base/debug/trace_event.h"
#include "content/public/browser/android/synchronous_compositor.h" #include "content/public/browser/android/synchronous_compositor.h"
#include "content/public/browser/android/synchronous_compositor_client.h" #include "content/public/browser/android/synchronous_compositor_client.h"
#include "skia/ext/refptr.h" #include "skia/ext/refptr.h"
...@@ -21,11 +21,8 @@ ...@@ -21,11 +21,8 @@
class SkCanvas; class SkCanvas;
class SkPicture; class SkPicture;
struct AwDrawGLInfo;
struct AwDrawSWFunctionTable;
namespace content { namespace content {
class ContentViewCore;
struct SynchronousCompositorMemoryPolicy; struct SynchronousCompositorMemoryPolicy;
class WebContents; class WebContents;
} }
...@@ -158,7 +155,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, ...@@ -158,7 +155,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
bool CompositeSW(SkCanvas* canvas); bool CompositeSW(SkCanvas* canvas);
void DidComposite(); void DidComposite();
void SkippedCompositeInDraw(); void SkippedCompositeInDraw();
scoped_ptr<base::Value> RootLayerStateAsValue( scoped_refptr<base::debug::ConvertableToTraceFormat> RootLayerStateAsValue(
const gfx::Vector2dF& total_scroll_offset_dip, const gfx::Vector2dF& total_scroll_offset_dip,
const gfx::SizeF& scrollable_size_dip); const gfx::SizeF& scrollable_size_dip);
...@@ -185,8 +182,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, ...@@ -185,8 +182,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy(); content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy();
// For debug tracing or logging. Return the string representation of this // For debug tracing or logging. Return the string representation of this
// view renderer's state and the |draw_info| if provided. // view renderer's state.
std::string ToString(AwDrawGLInfo* draw_info) const; std::string ToString() const;
BrowserViewRendererClient* client_; BrowserViewRendererClient* client_;
SharedRendererState* shared_renderer_state_; SharedRendererState* shared_renderer_state_;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
struct AwDrawSWFunctionTable;
namespace android_webview { namespace android_webview {
// Native side of java-class of same name. // Native side of java-class of same name.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment