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

Unified Diff: components/exo/surface.h

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on improved shared memory support Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/exo/surface.h
diff --git a/components/exo/surface.h b/components/exo/surface.h
new file mode 100644
index 0000000000000000000000000000000000000000..cf160378a2398aaf7cafb7546733b045547bb1fb
--- /dev/null
+++ b/components/exo/surface.h
@@ -0,0 +1,121 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_EXO_SURFACE_H_
+#define COMPONENTS_EXO_SURFACE_H_
+
+#include <list>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "cc/base/region.h"
+#include "cc/resources/texture_mailbox.h"
+#include "ui/compositor/compositor_observer.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/views/view.h"
+
+namespace base {
+namespace trace_event {
+class TracedValue;
+}
+}
+
+namespace cc {
+class SingleReleaseCallback;
+}
+
+namespace exo {
+class Buffer;
+class SurfaceDelegate;
+
+// This class represents a rectangular area that is displayed on the screen.
+// It has a location, size and pixel contents.
+class Surface : public views::View, public ui::CompositorObserver {
+ public:
+ Surface();
+ ~Surface() override;
+
+ // Set a buffer as the content of this surface. A buffer can only be attached
+ // to one surface at a time.
+ void Attach(Buffer* buffer, const gfx::Point& point);
+
+ // Describe the regions where the pending buffer is different from the
+ // current surface contents, and where the surface therefore needs to be
+ // repainted.
+ void Damage(const gfx::Rect& rect);
+
+ // Request notification when the next frame is displayed. Useful for
+ // throttling redrawing operations, and driving animations.
+ using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>;
+ void RequestFrameCallback(const FrameCallback& callback);
+
+ // This sets the region of the surface that contains opaque content.
+ void SetOpaqueRegion(const cc::Region& region);
+
+ // Surface state (damage regions, attached buffers, etc.) is double-buffered.
+ // A Commit() call atomically applies all pending state, replacing the
+ // current state.
+ void Commit();
+
+ // Set the surface delegate.
+ void SetSurfaceDelegate(SurfaceDelegate* delegate);
+
+ // Returns a trace value representing the state of the surface.
+ scoped_refptr<base::trace_event::TracedValue> AsTracedValue() const;
+
+ bool HasPendingDamageForTesting() const { return !pending_damage_.IsEmpty(); }
+
+ // Overridden from views::View:
+ gfx::Size GetPreferredSize() const override;
+
+ // Overridden from ui::CompositorObserver:
+ void OnCompositingDidCommit(ui::Compositor* compositor) override;
+ void OnCompositingStarted(ui::Compositor* compositor,
+ base::TimeTicks start_time) override;
+ void OnCompositingEnded(ui::Compositor* compositor) override {}
+ void OnCompositingAborted(ui::Compositor* compositor) override {}
+ void OnCompositingLockStateChanged(ui::Compositor* compositor) override {}
+ void OnCompositingShuttingDown(ui::Compositor* compositor) override;
+
+ private:
+ // The mailbox to be used by |layer_| after next call to Commit().
+ cc::TextureMailbox pending_mailbox_;
+
+ // The callback to release the pending mailbox. This is set when Attach()
+ // is called, we give it to the Layer when Commit() is called.
+ scoped_ptr<cc::SingleReleaseCallback> pending_mailbox_release_callback_;
+
+ // The damage region to schedule paint for when Commit() is called.
+ // TODO(reveman): Use cc::Region here after adding a version of
+ // ui::Layer::SchedulePaint that takes a cc::Region.
+ gfx::Rect pending_damage_;
+
+ // These lists contains the callbacks to notify the client when it is a good
+ // time to start producing a new frame. These callbacks move to
+ // |frame_callbacks_| when Commit() is called. Later they are moved to
+ // |active_frame_callbacks_| when the effect of the Commit() is reflected in
+ // the compositor's active layer tree. The callbacks fire once we're notified
+ // that the compositor started drawing that active layer tree.
+ std::list<FrameCallback> pending_frame_callbacks_;
+ std::list<FrameCallback> frame_callbacks_;
+ std::list<FrameCallback> active_frame_callbacks_;
+
+ // The opaque region to take effect when Commit() is called.
+ cc::Region pending_opaque_region_;
+
+ // The compsitor being observer or null if not observing a compositor.
+ ui::Compositor* compositor_;
+
+ // This can be set to have some functions delegated. E.g. ShellSurface class
+ // can set this to handle Commit() and apply any double buffered state it
+ // maintains.
+ SurfaceDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(Surface);
+};
+
+} // namespace exo
+
+#endif // COMPONENTS_EXO_SURFACE_H_

Powered by Google App Engine
This is Rietveld 408576698