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

Side by Side Diff: tools/skiaserve/skiaserve.cpp

Issue 1734913002: Move the favicon to debugger.skia.org. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: rebase Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrCaps.h" 8 #include "GrCaps.h"
9 #include "GrContextFactory.h" 9 #include "GrContextFactory.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 12 matching lines...) Expand all
23 #include <sys/socket.h> 23 #include <sys/socket.h>
24 #include <microhttpd.h> 24 #include <microhttpd.h>
25 #include "png.h" 25 #include "png.h"
26 26
27 // To get image decoders linked in we have to do the below magic 27 // To get image decoders linked in we have to do the below magic
28 #include "SkForceLinking.h" 28 #include "SkForceLinking.h"
29 #include "SkImageDecoder.h" 29 #include "SkImageDecoder.h"
30 __SK_FORCE_IMAGE_DECODER_LINKING; 30 __SK_FORCE_IMAGE_DECODER_LINKING;
31 31
32 DEFINE_string(source, "https://debugger.skia.org", "Where to load the web UI fro m."); 32 DEFINE_string(source, "https://debugger.skia.org", "Where to load the web UI fro m.");
33 DEFINE_string(faviconDir, "tools/skiaserve", "The directory of the favicon");
34 DEFINE_int32(port, 8888, "The port to listen on."); 33 DEFINE_int32(port, 8888, "The port to listen on.");
35 34
36 // TODO probably want to make this configurable 35 // TODO probably want to make this configurable
37 static const int kImageWidth = 1920; 36 static const int kImageWidth = 1920;
38 static const int kImageHeight = 1080; 37 static const int kImageHeight = 1080;
39 38
40 // TODO move to template file
41 SkString generateTemplate(SkString source) { 39 SkString generateTemplate(SkString source) {
42 SkString debuggerTemplate; 40 SkString debuggerTemplate;
43 debuggerTemplate.appendf( 41 debuggerTemplate.appendf(
44 "<!DOCTYPE html>\n" 42 "<!DOCTYPE html>\n"
45 "<html>\n" 43 "<html>\n"
46 "<head>\n" 44 "<head>\n"
47 " <title>SkDebugger</title>\n" 45 " <title>SkDebugger</title>\n"
48 " <meta charset=\"utf-8\" />\n" 46 " <meta charset=\"utf-8\" />\n"
49 " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=egde,chrome=1\">\ n" 47 " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=egde,chrome=1\">\ n"
50 " <meta name=\"viewport\" content=\"width=device-width, initial-scale =1.0\">\n" 48 " <meta name=\"viewport\" content=\"width=device-width, initial-scale =1.0\">\n"
51 " <script src=\"%s/res/js/core.js\" type=\"text/javascript\" charset= \"utf-8\"></script>\n" 49 " <script src=\"%s/res/js/core.js\" type=\"text/javascript\" charset= \"utf-8\"></script>\n"
52 " <link href=\"%s/res/vul/elements.html\" rel=\"import\" />\n" 50 " <link href=\"%s/res/vul/elements.html\" rel=\"import\" />\n"
51 " <link rel='shortcut icon' href='https://debugger.skia.org/res/img/f avicon.ico' type='image/x-icon'/ >"
53 "</head>\n" 52 "</head>\n"
54 "<body class=\"fullbleed layout vertical\">\n" 53 "<body class=\"fullbleed layout vertical\">\n"
55 " <debugger-app-sk>This is the app." 54 " <debugger-app-sk>This is the app."
56 " </debugger-app-sk>\n" 55 " </debugger-app-sk>\n"
57 "</body>\n" 56 "</body>\n"
58 "</html>", source.c_str(), source.c_str()); 57 "</html>", source.c_str(), source.c_str());
59 return debuggerTemplate; 58 return debuggerTemplate;
60 59
61 } 60 }
62 61
63 struct UploadContext { 62 struct UploadContext {
64 SkDynamicMemoryWStream fStream; 63 SkDynamicMemoryWStream fStream;
65 MHD_PostProcessor* fPostProcessor; 64 MHD_PostProcessor* fPostProcessor;
66 MHD_Connection* connection; 65 MHD_Connection* connection;
67 }; 66 };
68 67
69 struct Request { 68 struct Request {
70 Request(SkString rootUrl) 69 Request(SkString rootUrl)
71 : fUploadContext(nullptr) 70 : fUploadContext(nullptr)
72 , fUrlDataManager(rootUrl) 71 , fUrlDataManager(rootUrl)
73 , fGPUEnabled(false) {} 72 , fGPUEnabled(false) {}
74 73
75 UploadContext* fUploadContext; 74 UploadContext* fUploadContext;
76 SkAutoTUnref<SkPicture> fPicture; 75 SkAutoTUnref<SkPicture> fPicture;
77 SkAutoTUnref<SkDebugCanvas> fDebugCanvas; 76 SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
78 SkAutoTDelete<GrContextFactory> fContextFactory; 77 SkAutoTDelete<GrContextFactory> fContextFactory;
79 SkAutoTUnref<SkSurface> fSurface; 78 SkAutoTUnref<SkSurface> fSurface;
80 UrlDataManager fUrlDataManager; 79 UrlDataManager fUrlDataManager;
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 SkAutoTUnref<UrlDataManager::UrlData> urlData( 672 SkAutoTUnref<UrlDataManager::UrlData> urlData(
674 SkRef(request->fUrlDataManager.getDataFromUrl(SkString(url)))); 673 SkRef(request->fUrlDataManager.getDataFromUrl(SkString(url))));
675 674
676 if (urlData) { 675 if (urlData) {
677 return SendData(connection, urlData->fData.get(), urlData->fContentT ype.c_str()); 676 return SendData(connection, urlData->fData.get(), urlData->fContentT ype.c_str());
678 } 677 }
679 return MHD_NO; 678 return MHD_NO;
680 } 679 }
681 }; 680 };
682 681
683 class FaviconHandler : public UrlHandler {
684 public:
685 bool canHandle(const char* method, const char* url) override {
686 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
687 0 == strcmp(url, "/favicon.ico");
688 }
689
690 int handle(Request* request, MHD_Connection* connection,
691 const char* url, const char* method,
692 const char* upload_data, size_t* upload_data_size) override {
693 SkString dir(FLAGS_faviconDir[0]);
694 dir.append("/favicon.ico");
695 FILE* ico = fopen(dir.c_str(), "r");
696
697 SkAutoTUnref<SkData> data(SkData::NewFromFILE(ico));
698 int ret = SendData(connection, data, "image/vnd.microsoft.icon");
699 fclose(ico);
700 return ret;
701 }
702 };
703
704
705 class RootHandler : public UrlHandler { 682 class RootHandler : public UrlHandler {
706 public: 683 public:
707 bool canHandle(const char* method, const char* url) override { 684 bool canHandle(const char* method, const char* url) override {
708 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) && 685 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
709 0 == strcmp(url, "/"); 686 0 == strcmp(url, "/");
710 } 687 }
711 688
712 int handle(Request* request, MHD_Connection* connection, 689 int handle(Request* request, MHD_Connection* connection,
713 const char* url, const char* method, 690 const char* url, const char* method,
714 const char* upload_data, size_t* upload_data_size) override { 691 const char* upload_data, size_t* upload_data_size) override {
715 return SendTemplate(connection); 692 return SendTemplate(connection);
716 } 693 }
717 }; 694 };
718 695
719 class UrlManager { 696 class UrlManager {
720 public: 697 public:
721 UrlManager() { 698 UrlManager() {
722 // Register handlers 699 // Register handlers
723 fHandlers.push_back(new RootHandler); 700 fHandlers.push_back(new RootHandler);
724 fHandlers.push_back(new PostHandler); 701 fHandlers.push_back(new PostHandler);
725 fHandlers.push_back(new ImgHandler); 702 fHandlers.push_back(new ImgHandler);
726 fHandlers.push_back(new ClipAlphaHandler); 703 fHandlers.push_back(new ClipAlphaHandler);
727 fHandlers.push_back(new EnableGPUHandler); 704 fHandlers.push_back(new EnableGPUHandler);
728 fHandlers.push_back(new CmdHandler); 705 fHandlers.push_back(new CmdHandler);
729 fHandlers.push_back(new InfoHandler); 706 fHandlers.push_back(new InfoHandler);
730 fHandlers.push_back(new DownloadHandler); 707 fHandlers.push_back(new DownloadHandler);
731 fHandlers.push_back(new DataHandler); 708 fHandlers.push_back(new DataHandler);
732 fHandlers.push_back(new FaviconHandler);
733 fHandlers.push_back(new BreakHandler); 709 fHandlers.push_back(new BreakHandler);
734 } 710 }
735 711
736 ~UrlManager() { 712 ~UrlManager() {
737 for (int i = 0; i < fHandlers.count(); i++) { delete fHandlers[i]; } 713 for (int i = 0; i < fHandlers.count(); i++) { delete fHandlers[i]; }
738 } 714 }
739 715
740 // This is clearly not efficient for a large number of urls and handlers 716 // This is clearly not efficient for a large number of urls and handlers
741 int invoke(Request* request, MHD_Connection* connection, const char* url, co nst char* method, 717 int invoke(Request* request, MHD_Connection* connection, const char* url, co nst char* method,
742 const char* upload_data, size_t* upload_data_size) const { 718 const char* upload_data, size_t* upload_data_size) const {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 MHD_stop_daemon(daemon); 767 MHD_stop_daemon(daemon);
792 return 0; 768 return 0;
793 } 769 }
794 770
795 #if !defined SK_BUILD_FOR_IOS 771 #if !defined SK_BUILD_FOR_IOS
796 int main(int argc, char** argv) { 772 int main(int argc, char** argv) {
797 SkCommandLineFlags::Parse(argc, argv); 773 SkCommandLineFlags::Parse(argc, argv);
798 return skiaserve_main(); 774 return skiaserve_main();
799 } 775 }
800 #endif 776 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698