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

Unified Diff: examples/ganesh_app/ganesh_view.cc

Issue 1100803002: Make ganesh_app's GaneshView actually observe its View. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | services/kiosk_wm/kiosk_wm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/ganesh_app/ganesh_view.cc
diff --git a/examples/ganesh_app/ganesh_view.cc b/examples/ganesh_app/ganesh_view.cc
index a5afa1ab777f6d1466fcdb2a464a411c6d5314f4..bcd9f207ab4f9a2579125e1102e4c2d3d19cbb0a 100644
--- a/examples/ganesh_app/ganesh_view.cc
+++ b/examples/ganesh_app/ganesh_view.cc
@@ -4,10 +4,13 @@
#include "examples/ganesh_app/ganesh_view.h"
+#include "base/logging.h"
#include "mojo/skia/ganesh_surface.h"
#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkColor.h"
namespace examples {
+
namespace {
mojo::Size ToSize(const mojo::Rect& rect) {
@@ -16,13 +19,15 @@ mojo::Size ToSize(const mojo::Rect& rect) {
size.height = rect.height;
return size;
}
-}
+
+} // namespace
GaneshView::GaneshView(mojo::Shell* shell, mojo::View* view)
: view_(view),
gl_context_(mojo::GLContext::Create(shell)),
gr_context_(gl_context_),
texture_uploader_(this, shell, gl_context_) {
+ view_->AddObserver(this);
Draw(ToSize(view_->bounds()));
}
@@ -36,6 +41,8 @@ void GaneshView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
}
void GaneshView::OnViewDestroyed(mojo::View* view) {
+ DCHECK(view == view_);
+ view_->RemoveObserver(this);
delete this;
}
@@ -51,11 +58,18 @@ void GaneshView::Draw(const mojo::Size& size) {
&gr_context_, make_scoped_ptr(new mojo::GLTexture(gl_context_, size)));
SkCanvas* canvas = surface.canvas();
+ canvas->clear(SK_ColorCYAN);
SkPaint paint;
+ paint.setColor(SK_ColorGREEN);
+ SkRect rect = SkRect::MakeWH(size.width, size.height);
+ rect.inset(10, 10);
+ canvas->drawRect(rect, paint);
+
paint.setColor(SK_ColorRED);
paint.setFlags(SkPaint::kAntiAlias_Flag);
canvas->drawCircle(50, 100, 100, paint);
+
canvas->flush();
texture_uploader_.Upload(surface.TakeTexture());
« no previous file with comments | « no previous file | services/kiosk_wm/kiosk_wm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698