提交 ff48ddb6 编写于 作者: A Adam Barth

Add the ability to dispose host objects

Some host objects hold on to a lot of state and take time to tear down. This
patch adds the ability to dispose them eagerly to release resources faster.
上级 79b455aa
......@@ -25,6 +25,10 @@ Scene::Scene(std::unique_ptr<sky::compositor::Layer> rootLayer,
Scene::~Scene() {}
void Scene::dispose() {
ClearDartWrapper();
}
std::unique_ptr<sky::compositor::LayerTree> Scene::takeLayerTree() {
return std::move(m_layerTree);
}
......
......@@ -28,6 +28,8 @@ class Scene : public RefCounted<Scene>, public DartWrappable {
std::unique_ptr<sky::compositor::LayerTree> takeLayerTree();
void dispose();
private:
explicit Scene(std::unique_ptr<sky::compositor::Layer> rootLayer,
uint32_t rasterizerTracingThreshold);
......
......@@ -4,4 +4,5 @@
// An opaque handle to a composited scene.
interface Scene {
void dispose();
};
......@@ -131,7 +131,9 @@ PassRefPtr<Scene> SceneBuilder::build()
m_currentLayer = nullptr;
int32_t threshold = m_currentRasterizerTracingThreshold;
m_currentRasterizerTracingThreshold = 0;
return Scene::create(std::move(m_rootLayer), threshold);
RefPtr<Scene> scene = Scene::create(std::move(m_rootLayer), threshold);
ClearDartWrapper();
return scene.release();
}
} // namespace blink
......@@ -20,4 +20,8 @@ int CanvasImage::height() const {
return image_->height();
}
void CanvasImage::dispose() {
ClearDartWrapper();
}
} // namespace blink
......@@ -20,6 +20,7 @@ class CanvasImage final : public RefCounted<CanvasImage>,
int width() const;
int height() const;
void dispose();
SkImage* image() const { return image_.get(); }
void setImage(PassRefPtr<SkImage> image) { image_ = image; }
......
......@@ -9,4 +9,6 @@
// TODO(ianh): convert this to a Size
readonly attribute long width; // width in number of image pixels
readonly attribute long height; // height in number of image pixels
void dispose();
};
......@@ -28,4 +28,9 @@ void Picture::playback(Canvas* canvas)
m_picture->playback(canvas->skCanvas());
}
void Picture::dispose()
{
ClearDartWrapper();
}
} // namespace blink
......@@ -23,6 +23,7 @@ public:
SkPicture* toSkia() const { return m_picture.get(); }
void playback(Canvas* canvas);
void dispose();
private:
explicit Picture(PassRefPtr<SkPicture> skPicture);
......
......@@ -7,4 +7,6 @@ interface Picture {
// canvas. Using the Canvas drawPicture entry point gives the destination
// canvas the option of just taking a ref.
void playback(Canvas canvas);
void dispose();
};
......@@ -34,7 +34,9 @@ PassRefPtr<Picture> PictureRecorder::endRecording()
RefPtr<Picture> picture = Picture::create(
adoptRef(m_pictureRecorder.endRecording()));
m_canvas->clearSkCanvas();
m_canvas->ClearDartWrapper();
m_canvas = nullptr;
ClearDartWrapper();
return picture.release();
}
......@@ -45,7 +47,9 @@ PassRefPtr<Drawable> PictureRecorder::endRecordingAsDrawable()
RefPtr<Drawable> drawable = Drawable::create(
adoptRef(m_pictureRecorder.endRecordingAsDrawable()));
m_canvas->clearSkCanvas();
m_canvas->ClearDartWrapper();
m_canvas = nullptr;
ClearDartWrapper();
return drawable.release();
}
......
......@@ -4,7 +4,6 @@
[
Constructor()
] interface PictureRecorder {
readonly attribute boolean isRecording;
Picture endRecording();
Drawable endRecordingAsDrawable();
};
......@@ -63,6 +63,16 @@ void DartWrappable::AssociateWithDartWrapper(Dart_NativeArguments args) {
wrapper, this, info.size_in_bytes, &FinalizeDartWrapper);
}
void DartWrappable::ClearDartWrapper() {
DCHECK(dart_wrapper_);
Dart_Handle wrapper = Dart_HandleFromWeakPersistent(dart_wrapper_);
CHECK(!LogIfError(Dart_SetNativeInstanceField(wrapper, kPeerIndex, 0)));
CHECK(!LogIfError(Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex, 0)));
Dart_DeleteWeakPersistentHandle(Dart_CurrentIsolate(), dart_wrapper_);
dart_wrapper_ = nullptr;
GetDartWrapperInfo().deref_object(this);
}
void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data,
Dart_WeakPersistentHandle wrapper,
void* peer) {
......
......@@ -41,6 +41,7 @@ class DartWrappable {
Dart_Handle CreateDartWrapper(DartState* dart_state);
void AssociateWithDartWrapper(Dart_NativeArguments args);
void ClearDartWrapper(); // Warning: Might delete this.
Dart_WeakPersistentHandle dart_wrapper() const { return dart_wrapper_; }
protected:
......
......@@ -13,15 +13,15 @@
#include "mojo/data_pipe_utils/data_pipe_utils.h"
#include "mojo/public/cpp/application/connect.h"
#include "services/asset_bundle/asset_unpacker_job.h"
#include "sky/engine/public/platform/WebInputEvent.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/platform/WebInputEvent.h"
#include "sky/engine/public/web/Sky.h"
#include "sky/engine/public/web/WebRuntimeFeatures.h"
#include "sky/shell/dart/dart_library_provider_files.h"
#include "sky/shell/dart/dart_library_provider_network.h"
#include "sky/shell/service_provider.h"
#include "sky/shell/switches.h"
#include "sky/shell/switches.h"
#include "sky/shell/ui/animator.h"
#include "sky/shell/ui/internals.h"
#include "sky/shell/ui/platform_impl.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册